Re: select for UNIX sockets?

Petr Vandrovec
2003-06-04T12:06:36Z

On 4 Jun 03 at 6:55, Jesse Pollard wrote:
> On Monday 02 June 2003 19:08, Krzysztof Halasa wrote:
> > Hi,
> >
> > Should something like this work correctly?
> >
> > while(1) {
> > FD_ZERO(&set);
> > FD_SET(fd, &set);
> > select(FD_SETSIZE, NULL, &set, NULL, NULL); <<<<<<< for writing
> >
> > if (FD_ISSET(fd, &set))
> > sendto(fd, &datagram, 1, 0, ...);
> > }
> >
> > fd is a normal local datagram socket. It looks select() returns with
> > "fd ready for write" and sendto() then blocks as the queue is full.
> >
> > I don't know if it's expected behaviour or just a not yet known bug.
> > Of course, I have a more complete test program if needed.
> >
> > 2.4.21rc6, haven't tried any other version.
> >
> > strace shows:
> >
> > select(1024, NULL, [3], NULL, NULL) = 1 (out [3])
> > sendto(3, "\0", 1, 0, {sa_family=AF_UNIX, path="/tmp/tempUn"}, 13 <<<
> > blocks
>
> Could. There may be room for the buffer, but unless it is set to nonblock,
> you may have a stream open to another host that may not accept the data (busy,
> network congestion...) With the required acks, the return may (should?) be
> delayed until the ack arrives.

Besides that select() on unconnected socket is nonsense... If you'll
change code to do connect(), select(), send(), then it should work,
unless I missed something.
Petr Vandrovec
vandrove@vc.cvut.cz