Bug 1062754: Support peer shutdown and EOF in |SocketIOBase|, r=qdot, btian

Calling read on a socket that has been closed for reading by the
peer, read returns 0. The socket is still readable however, so
polling and reading will return constant results of 0 received
bytes.

With this patch, if a socket's peer shuts down reading or if
we reached the EOF, we stop watching the file descriptor for
readability. |SocketIOBase| will detect this case exactly once
and initiate the socket's shutdown.
This commit is contained in:
Thomas Zimmermann
2014-09-05 10:16:24 +02:00
parent d3ccf83224
commit a781551dd1
4 changed files with 44 additions and 39 deletions

View File

@@ -389,10 +389,13 @@ UnixSocketConsumerIO::OnSocketCanReceiveWithoutBlocking()
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED); // see bug 990984
nsresult rv = ReceiveData(GetFd(), this);
if (NS_FAILED(rv)) {
ssize_t res = ReceiveData(GetFd(), this);
if (res < 0) {
/* I/O error */
RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
return;
} else if (!res) {
/* EOF or peer shutdown */
RemoveWatchers(READ_WATCHER);
}
}