Bugzilla – Bug 311
Tcp socket close returns -1 but does not set errno.
Last modified: 2008-10-27 15:01:55 EDT
tcp-socket-impl.cc: line 294: if (m_state == CLOSED) { return -1; } It is illegal to return -1 without setting errno. But I have to confess that I don't really understand the purpose of this check: is it expected to guard against a double close ? If so, I suspect that the return errno here is EBADF.
I should have pointed out that, if the purpose is to guard against a double-close, then, the socket should not be initialized to CLOSED state in the TcpSocketImpl constructor because this would trigger an EBADF upon closing a socket which was just opened.
It seems the purpose of this check was to prevent a double close, BUT it apparently is superfluous in any case, because the state machine has the following entry in it: aT[CLOSED][APP_CLOSE] = SA (CLOSED, NO_ACT); Since we call ProcessEvent(APP_CLOSE) in this code, in the case of already being in the CLOSED state, nothing would happen in terms of state change or action in response to closing the socket. As such, deleting the check would cause a double close to silently succeed, and return 0. Really, this is what should have been done, because the processing of the m_state variable shouldn't explicitly be done in this code since it is handled by the ProcessEvent/Action methods. diff -r 6105fe16df43 src/internet-stack/tcp-socket-impl.cc --- a/src/internet-stack/tcp-socket-impl.cc Tue Sep 16 11:55:52 2008 -0700 +++ b/src/internet-stack/tcp-socket-impl.cc Wed Sep 17 15:33:07 2008 -0400 @@ -296,10 +296,6 @@ TcpSocketImpl::Close (void) { NS_LOG_FUNCTION_NOARGS (); - if (m_state == CLOSED) - { - return -1; - } if (m_pendingData && m_pendingData->Size() != 0) { // App close with pending data must wait until all data transmitted m_closeOnEmpty = true;
changeset 3818 080614a8e247