Fixed bugs in error handling in CTCPSocket; previously was not

handling read errors at all and error handling for writes was
never being used.  Now the socket disconnects if a read or write
fails on the socket for any reason except EINTR.  Also added
<netinet/in.h> to includes in CNetwork.h because it's needed on
some platforms.
This commit is contained in:
crs 2002-10-30 22:16:30 +00:00
parent 9102fb80b9
commit cf13980bb8
2 changed files with 16 additions and 4 deletions

View File

@ -43,6 +43,7 @@ typedef int ssize_t;
#endif
#if UNIX_LIKE
# include <netinet/in.h>
# include <netdb.h>
# include <errno.h>
#endif
@ -183,9 +184,11 @@ public:
#if WINDOWS_LIKE
kEADDRINUSE = WSAEADDRINUSE,
kECONNECTING = WSAEWOULDBLOCK,
kEINTR = WSAEINTR,
#elif UNIX_LIKE
kEADDRINUSE = EADDRINUSE,
kECONNECTING = EINPROGRESS,
kEINTR = EINTR,
#endif
kNone = 0
};

View File

@ -292,6 +292,12 @@ CTCPSocket::ioService()
m_input->hangup();
m_connected &= ~kRead;
}
else {
// socket failed
if (CNetwork::getsockerror() != CNetwork::kEINTR) {
return;
}
}
}
// write some data
@ -303,18 +309,21 @@ CTCPSocket::ioService()
// write data
const void* buffer = m_output->peek(n);
n = (UInt32)CNetwork::write(m_fd, buffer, n);
ssize_t n2 = (UInt32)CNetwork::write(m_fd, buffer, n);
// discard written data
if (n > 0) {
if (n2 > 0) {
m_output->pop(n);
}
else if (n == (UInt32)-1 && CNetwork::getsockerror() == EPIPE) {
else if (n2 < 0) {
// socket failed
if (CNetwork::getsockerror() != CNetwork::kEINTR) {
return;
}
}
}
}
}
}
void