开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: C++ preventing EReader reading when socket is closed


 

?Not sure if this is the right topic but I got a problem with these newly added code in EClientSocket::eDisconnect.

void EClientSocket::eDisconnect(bool resetState) {

// Stop EReader thread to avoid 509 error caused by reading on a closed socket.

? if (m_pEReader)

? ? m_pEReader->stop();

...
When TWS is shutdown manually, the code will hang at m_pEReader->stop(). The call stack is:
?
> ? ?APITWS.dll!EClientSocket::eDisconnect(bool resetState) Line 241 ? ?C++
? ? ?APITWS.dll!EClientSocket::onClose() Line 370 ? ?C++
? ? ?APITWS.dll!EClientSocket::receive(char * buf, unsigned int sz) Line 274 ? ?C++
? ? ?APITWS.dll!EReader::onReceive() Line 199 ? ?C++
? ? ?APITWS.dll!EReader::processNonBlockingSelect() Line 181 ? ?C++
? ? ?APITWS.dll!EReader::readToQueue() Line 101 ? ?C++
? ? ?APITWS.dll!EReader::readToQueueThread(void * lpParam) Line 93 ? ?C++
?
Commenting out m_pEReader->stop() the code runs happily and will generate a 509 error as expected.
?

Join [email protected] to automatically receive all group messages.