f



Scattered-write with sendto() un a SOCK_DGRAM Unix Domain Socket

Hi to everyone, I'd like to do a scattered write, like with writev()
on a Unix Domain Socket. The problem is, since the socket is of
SOCK_DGRAM type, and thus unconnected, writev will fail saying
"Transport endpoint is not connected".
I checked in the man pages and yes, write() and writev() will not work
on datagram-type sockets.

The question is: is there a way to perform a scattered write on a
datagram Unix Socket? I don't know why it shouldn't be, but I wouldn't
be surprised if Linux API were lacking also of this possibility.

I use kernel 2.6.10.

Thanks,
Regards,

Cristiano.
0
5/6/2008 11:30:26 AM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

4 Replies
703 Views

Similar Articles

[PageSpeed] 9

janesconference@gmail.com writes:
> Hi to everyone, I'd like to do a scattered write, like with writev()
> on a Unix Domain Socket. The problem is, since the socket is of
> SOCK_DGRAM type, and thus unconnected, writev will fail saying
> "Transport endpoint is not connected".
> I checked in the man pages and yes, write() and writev() will not work
> on datagram-type sockets.
>
> The question is: is there a way to perform a scattered write on a
> datagram Unix Socket?

Two ways, actually: It is possible to use connect with a datagram
socket, too, which then sets the default destination address for
send-operations not specifying one and the acceptable recipient
address for recv. Afterwards, send, write or writev could be used as
with any other connected socket. The second one would be to use
sendmsg instead of sendto.
0
rweikusat (2830)
5/6/2008 12:22:30 PM
janesconference@gmail.com writes:
> Hi to everyone, I'd like to do a scattered write, like with writev()
> on a Unix Domain Socket. The problem is, since the socket is of
> SOCK_DGRAM type, and thus unconnected, writev will fail saying
> "Transport endpoint is not connected".
> I checked in the man pages and yes, write() and writev() will not work
> on datagram-type sockets.

Does your system have sendmsg()?  It should.  The msghdr structure
contains a msg_iov member that points to an array of scatter buffers,
as well as a msg_name pointer for the destination address.

-- 
James Carlson, Solaris Networking              <james.d.carlson@sun.com>
Sun Microsystems / 35 Network Drive        71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677
0
5/6/2008 12:25:33 PM
On 6 Mag, 14:25, James Carlson <james.d.carl...@sun.com> wrote:
> janesconfere...@gmail.com writes:
> > Hi to everyone, I'd like to do a scattered write, like with writev()
> > on a Unix Domain Socket. The problem is, since the socket is of
> > SOCK_DGRAM type, and thus unconnected, writev will fail saying
> > "Transport endpoint is not connected".
> > I checked in the man pages and yes, write() and writev() will not work
> > on datagram-type sockets.
>
> Does your system have sendmsg()? =A0It should. =A0The msghdr structure
> contains a msg_iov member that points to an array of scatter buffers,
> as well as a msg_name pointer for the destination address.
>
> --
> James Carlson, Solaris Networking =A0 =A0 =A0 =A0 =A0 =A0 =A0<james.d.carl=
....@sun.com>
> Sun Microsystems / 35 Network Drive =A0 =A0 =A0 =A071.232W =A0 Vox +1 781 =
442 2084
> MS UBUR02-212 / Burlington MA 01803-2757 =A0 42.496N =A0 Fax +1 781 442 16=
77

Many thanks to both of you!
Best regards,

Cristiano.
0
5/6/2008 12:33:30 PM
janesconference@gmail.com wrote:
> Hi to everyone, I'd like to do a scattered write, like with writev()
> on a Unix Domain Socket. The problem is, since the socket is of
> SOCK_DGRAM type, and thus unconnected, writev will fail saying
> "Transport endpoint is not connected".

> I checked in the man pages and yes, write() and writev() will not work
> on datagram-type sockets.

Actually read(), write() will work on SOCK_DGRAM type sockets,
if you call connect(). You lose the ability to communicate
with more than one peer at the same time on the same socket,
but you can now use the simpler read() and write() calls.
Eventually writev() will also work after connect().

Rainer
0
5/6/2008 12:39:23 PM
Reply: