fixed bug in closing down a socket.

This commit is contained in:
crs 2002-05-30 16:11:59 +00:00
parent 8cb0302665
commit 2cc63e31aa
2 changed files with 27 additions and 4 deletions

View File

@ -140,13 +140,27 @@ void CTCPSocket::ioThread(void*)
{ {
try { try {
ioService(); ioService();
ioCleanup();
}
catch (...) {
ioCleanup();
throw;
}
}
void CTCPSocket::ioCleanup()
{
try {
m_input->close(); m_input->close();
}
catch (...) {
// ignore
}
try {
m_output->close(); m_output->close();
} }
catch (...) { catch (...) {
m_input->close(); // ignore
m_output->close();
throw;
} }
} }
@ -162,6 +176,9 @@ void CTCPSocket::ioService()
// choose events to poll for // choose events to poll for
CLock lock(m_mutex); CLock lock(m_mutex);
pfds[0].events = 0; pfds[0].events = 0;
if (m_connected == 0) {
return;
}
if ((m_connected & kRead) != 0) { if ((m_connected & kRead) != 0) {
// still open for reading // still open for reading
pfds[0].events |= CNetwork::kPOLLIN; pfds[0].events |= CNetwork::kPOLLIN;
@ -174,6 +191,11 @@ void CTCPSocket::ioService()
// check for status // check for status
CThread::testCancel(); CThread::testCancel();
if (pfds[0].events == 0) {
CThread::sleep(0.05);
CThread::testCancel();
continue;
}
const int status = CNetwork::poll(pfds, 1, 50); const int status = CNetwork::poll(pfds, 1, 50);
CThread::testCancel(); CThread::testCancel();
@ -197,7 +219,7 @@ void CTCPSocket::ioService()
else if (n == 0) { else if (n == 0) {
// stream hungup // stream hungup
m_input->hangup(); m_input->hangup();
return; m_connected &= ~kRead;
} }
} }

View File

@ -32,6 +32,7 @@ public:
private: private:
void init(); void init();
void ioThread(void*); void ioThread(void*);
void ioCleanup();
void ioService(); void ioService();
void closeInput(void*); void closeInput(void*);
void closeOutput(void*); void closeOutput(void*);