fix handling of errors due to the other end of the socket being closed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57661 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -838,7 +838,9 @@ wxUint32 wxSocketBase::DoRead(void* buffer_, wxUint32 nbytes)
|
|||||||
if ( !WaitForRead() )
|
if ( !WaitForRead() )
|
||||||
break;
|
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 )
|
if ( ret == 0 )
|
||||||
{
|
{
|
||||||
// for connection-oriented (e.g. TCP) sockets we can only read
|
// for connection-oriented (e.g. TCP) sockets we can only read
|
||||||
@@ -850,10 +852,7 @@ wxUint32 wxSocketBase::DoRead(void* buffer_, wxUint32 nbytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ret == -1 )
|
if ( ret == -1 )
|
||||||
{
|
|
||||||
SetError(wxSOCKET_IOERR);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
total += ret;
|
total += ret;
|
||||||
|
|
||||||
@@ -1020,7 +1019,7 @@ wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
|
|||||||
if ( !WaitForWrite() )
|
if ( !WaitForWrite() )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const int ret = m_impl->Write(buffer, nbytes);
|
const int ret = m_connected ? m_impl->Write(buffer, nbytes) : -1;
|
||||||
if ( ret == 0 )
|
if ( ret == 0 )
|
||||||
{
|
{
|
||||||
m_closed = true;
|
m_closed = true;
|
||||||
@@ -1028,10 +1027,7 @@ wxUint32 wxSocketBase::DoWrite(const void *buffer_, wxUint32 nbytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ret == -1 )
|
if ( ret == -1 )
|
||||||
{
|
|
||||||
SetError(wxSOCKET_IOERR);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
total += ret;
|
total += ret;
|
||||||
if ( !(m_flags & wxSOCKET_WAITALL) )
|
if ( !(m_flags & wxSOCKET_WAITALL) )
|
||||||
@@ -1239,6 +1235,10 @@ wxSocketBase::DoWait(long seconds, long milliseconds, wxSocketEventFlags flags)
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG( m_impl, false, "can't wait on invalid socket" );
|
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.
|
// This can be set to true from Interrupt() to exit this function a.s.a.p.
|
||||||
m_interrupt = false;
|
m_interrupt = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user