if ( !WaitForRead() )
break;
- const int ret = m_impl->Read(buffer, nbytes);
+ // m_connected will be set to false if we lost connection while
+ // waiting, there is no need to call Read() if this happened
+ const int ret = m_connected ? m_impl->Read(buffer, nbytes) : -1;
if ( ret == 0 )
{
// for connection-oriented (e.g. TCP) sockets we can only read
}
if ( ret == -1 )
- {
- SetError(wxSOCKET_IOERR);
break;
- }
total += ret;
if ( !WaitForWrite() )
break;
- const int ret = m_impl->Write(buffer, nbytes);
+ const int ret = m_connected ? m_impl->Write(buffer, nbytes) : -1;
if ( ret == 0 )
{
m_closed = true;
}
if ( ret == -1 )
- {
- SetError(wxSOCKET_IOERR);
break;
- }
total += ret;
if ( !(m_flags & wxSOCKET_WAITALL) )
{
wxCHECK_MSG( m_impl, false, "can't wait on invalid socket" );
+ // we're never going to become ready if we're not connected (any more)
+ if ( !m_connected && !m_establishing )
+ return (flags & wxSOCKET_LOST_FLAG) != 0;
+
// This can be set to true from Interrupt() to exit this function a.s.a.p.
m_interrupt = false;