|Sun Solaris 2.x||
|x86 Linux 2.0||
|with linuxthreads 0.5||
|Digital Unix 3.2||
read(sock), processing the data, then going back into the read.
read(sock), or is elsewhere in the loop. If the former then read will return 0, indicating that the socket is closed. If the latter then eventually thread A will call
read(sock)and then this will return 0. Thread A should
close(sock), do any other tidying up, and exit.
shutdown(listenSock,2). Wherever thread A is in the loop, eventually it will return
ECONNABORTEDfrom the accept call. It should
close(listenSock), tidy up as necessary and exit.
shutdown(listenSock,2)--- this returns
ENOTCONN. Instead the following strategy can be used:
getsockaddr(listenSock)to find out which port listenSock is on (or knows already), sets up a socket dummySock, does
this host, port)and finally does
accept(listenSock). This will return successfully with a new socket, say connSock. Thread A then checks to see if the "shutdown flag" is set. If not, then it's a normal connection. If it is set, then thread A closes listenSock and connSock, tidies up and exits.
write(sock)then it will return with
ENXIO. If thread A calls write after thread B calls shutdown this will return
write(sock)then it will return the number of bytes written before it became blocked. A subsequent call to write will then generate
EPIPEwill be returned if
SIGPIPEis ignored by the thread).
connect(sock)then it will return a successful connection. Subsequent reading or writing will show that the socket has been shut down (i.e. read returns 0, write generates
EPIPE). If thread A calls connect after thread B calls shutdown this will return
F_SETFL, O_NONBLOCK). Then it calls connect on the socket --- this will return
EINPROGRESS. Then it must call
select(), waiting for either sock to become writable or for the pipe to become readable. If select returns that just sock is writable then the connection has succeeded. It then needs to set the socket back to blocking mode using
fcntl(sock, F_SETFL, 0). If instead select returns that the pipe is readable, thread A closes the socket, tidies up and exits.
This document was translated from LATEX by HEVEA.