Messages in this thread | | | Date | Sun, 12 Dec 1999 16:46:16 -0500 (EST) | From | "Richard B. Johnson" <> | Subject | Re: accept() doesn't block as it should in 2.3.x kernels |
| |
On Sat, 11 Dec 1999, David Dyck wrote:
> > The following demo code should block on the call to accept > but it doesn't in 2.3.x, (where x is 24,27,28,30,31, and 32pre2) > > 2.2.5, 2.2.13, and 2.2.14pre9 block as expected in accept() > > I'm getting > ENOTCONN "Transport endpoint is not connected" > > The man page for accept(2) leads me to believe that it should block > > If no pending connections are present on the queue, and the > socket is not marked as non- blocking, accept blocks the > caller until a connection is present. > > I discovered this when attempting to build perl for 2.3.32pre2 > (I'm using libc5.4.44 if that matters) > and it failed in when testing lib/io_unix > > I will appreciate your comments > > Thanks again, > David Dyck
It may be that previous versions let you get away with muddy code. There are several problems with the test code.
> > #include <stdio.h> > #include <unistd.h> > #include <sys/types.h> > #include <sys/socket.h> > #include <sys/un.h> > > #define PATH "/tmp/sock-test" > int main() > { > int s; > pid_t pid; > struct sockaddr_un sa = { AF_UNIX, PATH }; > char *buf[1024]; > > unlink(PATH); /* just in case */ > > s = socket(AF_UNIX, SOCK_STREAM, 0); > if (s == -1) { perror("socket"); exit(1); } > > if (bind(s, (struct sockaddr *)&sa, > strlen(sa.sun_path) + sizeof (sa.sun_family)) == -1) > { perror("bind"); exit(1); } > > if (listen(s, 5) == -1) { perror("listen"); exit(1); } > > { > int s2; > int sa2_len; > struct sockaddr_un sa2; >
Here, the length of sa2, passed to accept via sa2_len is undefined.
The length should be initialized to the length of the structure so accept() knows how much space is available. Accept() is probably getting a 0, returning a bogus error-code.
> if ((s2=accept(s, (struct sockaddr *)&sa2, &sa2_len)) == -1) > {perror("accept didn't block"); exit(1); } > } >
Cheers, Dick Johnson
Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips). Warning : The end of the world as we know it requires a new calendar. Seconds : 1667624 (until Y2K)
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |