write hangs on socket shut down for writing

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Apr 21 09:16:00 GMT 2004


On Apr 20 18:17, Yitzchak Scott-Thoennes wrote:
> 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.

Did you try it with a recent Cygwin version?  I used your above test
application and I'm getting a EPIPE (resp. a SIGPIPE) as expected.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Co-Project Leader          mailto:cygwin@cygwin.com
Red Hat, Inc.

--
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/



More information about the Cygwin mailing list