On Wed, 2010-08-25 at 15:34 -0700, David Miller wrote:
[...]
[...]
This example seems to have both server (serv, s2) and client (s1) in the
same process for simplicity. The server socket (s2) is closed and the
client cannot be expected to know that. Of course the client ought to
drop the connection after the first EPIPE, but it's reasonable to expect
that this is a sticky condition just as it would be for a pipe.
Here's a similar test case in C:
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
struct sockaddr sa;
struct timeval tv;
int serv, s1, s2;
socklen_t len;
fd_set fds;
signal(SIGPIPE, SIG_IGN);
serv = socket(AF_INET, SOCK_STREAM, 0);
assert(serv >= 0);
assert(!listen(serv, 1));
len = sizeof(sa);
assert(!getsockname(serv, &sa, &len));
s1 = socket(AF_INET, SOCK_STREAM, 0);
assert(s1 >= 0);
assert(!connect(s1, &sa, len));
len = sizeof(sa);
s2 = accept(serv, &sa, &len);
assert(s2 >= 0);
close(s2);
for (;;) {
printf("write: %d\n", write(s1, "a", 1));
FD_ZERO(&fds);
FD_SET(s1, &fds);
tv.tv_sec = 1;
tv.tv_usec = 0;
printf("select: %d\n", select(s1 + 1, NULL, &fds, NULL, &tv));
}
return 0;
}
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
--