Subject: write hangs on socket shut down for writing
From: Yitzchak Scott-Thoennes <[email-masked]>
To: [email-masked]
Date: Tue, 20 Apr 2004 18:17:31 -0700

This seems to be the cause of perl's ext/Socket/t/socketpair.t test 14
failing (which I've seen since at least 1.3.22).

$ cat pairsock.c
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>

int main (int argc, char **argv) {
   int sockets[2] = {-1, -1};
   int result;
   ssize_t wrote;

   result = socketpair (AF_UNIX, SOCK_STREAM, PF_UNSPEC, sockets);
   printf ("socketpair result: %d, left %d, right %d.\n", result, sockets[0], sockets[1]);

   result = shutdown (sockets[0], SHUT_WR);
   printf ("shutdown result: %d.\n", result);

   printf ("writing 4 bytes to left socket.\n");
   wrote = write (sockets[0], "nogo", 4);
   printf ("write result: %ld.\n", (long)wrote);
   return 0;
}

$ gcc -Wall pairsock.c; ./a.exe
socketpair result: 0, left 3, right 4.
shutdown result: 0.
writing 4 bytes to left socket.

...and hangs there.

SUSv3 says:
The write() function shall fail if:
...
[EPIPE] 
A write was attempted on a socket that is shut down for writing, or is
no longer connected. In the latter case, if the socket is of type
SOCK_STREAM, the SIGPIPE signal is generated to the calling process.
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/