Merge pull request #211 from jwestfall69/socket-fix

Properly deal with a socket that is readable and writable at the same time
This commit is contained in:
Adrian Lucrèce Céleste 2018-12-30 14:49:26 -05:00 committed by GitHub
commit 943b9a8a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 8 deletions

View File

@ -544,10 +544,11 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
return newJob(); return newJob();
} }
EJobResult result = kRetry; EJobResult writeResult = kRetry;
EJobResult readResult = kRetry;
if (write) { if (write) {
try { try {
result = doWrite(); writeResult = doWrite();
} }
catch (XArchNetworkShutdown&) { catch (XArchNetworkShutdown&) {
// remote read end of stream hungup. our output side // remote read end of stream hungup. our output side
@ -558,13 +559,13 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
sendEvent(m_events->forISocket().disconnected()); sendEvent(m_events->forISocket().disconnected());
m_connected = false; m_connected = false;
} }
result = kNew; writeResult = kNew;
} }
catch (XArchNetworkDisconnected&) { catch (XArchNetworkDisconnected&) {
// stream hungup // stream hungup
onDisconnected(); onDisconnected();
sendEvent(m_events->forISocket().disconnected()); sendEvent(m_events->forISocket().disconnected());
result = kNew; writeResult = kNew;
} }
catch (XArchNetwork& e) { catch (XArchNetwork& e) {
// other write error // other write error
@ -572,19 +573,19 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
onDisconnected(); onDisconnected();
sendEvent(m_events->forIStream().outputError()); sendEvent(m_events->forIStream().outputError());
sendEvent(m_events->forISocket().disconnected()); sendEvent(m_events->forISocket().disconnected());
result = kNew; writeResult = kNew;
} }
} }
if (read && m_readable) { if (read && m_readable) {
try { try {
result = doRead(); readResult = doRead();
} }
catch (XArchNetworkDisconnected&) { catch (XArchNetworkDisconnected&) {
// stream hungup // stream hungup
sendEvent(m_events->forISocket().disconnected()); sendEvent(m_events->forISocket().disconnected());
onDisconnected(); onDisconnected();
result = kNew; readResult = kNew;
} }
catch (XArchNetwork& e) { catch (XArchNetwork& e) {
// ignore other read error // ignore other read error
@ -592,5 +593,11 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
} }
} }
return result == kBreak ? NULL : result == kNew ? newJob() : job; if (writeResult == kBreak || readResult == kBreak) {
return NULL;
} else if (writeResult == kNew || readResult == kNew) {
return newJob();
} else {
return job;
}
} }