don't close UDP socket if it receives an empty datagram (patch 1885472)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51623 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1198,11 +1198,16 @@ int GSocket::Read(char *buffer, int size)
|
|||||||
else
|
else
|
||||||
ret = Recv_Dgram(buffer, size);
|
ret = Recv_Dgram(buffer, size);
|
||||||
|
|
||||||
/* If recv returned zero, then the connection has been gracefully closed.
|
/*
|
||||||
* Otherwise, recv has returned an error (-1), in which case we have lost the
|
* If recv returned zero for a TCP socket (if m_stream == NULL, it's an UDP
|
||||||
* socket only if errno does _not_ indicate that there may be more data to read.
|
* socket and empty datagrams are possible), then the connection has been
|
||||||
|
* gracefully closed.
|
||||||
|
*
|
||||||
|
* Otherwise, recv has returned an error (-1), in which case we have lost
|
||||||
|
* the socket only if errno does _not_ indicate that there may be more data
|
||||||
|
* to read.
|
||||||
*/
|
*/
|
||||||
if (ret == 0)
|
if ((ret == 0) && m_stream)
|
||||||
{
|
{
|
||||||
/* Make sure wxSOCKET_LOST event gets sent and shut down the socket */
|
/* Make sure wxSOCKET_LOST event gets sent and shut down the socket */
|
||||||
if (m_use_events)
|
if (m_use_events)
|
||||||
@@ -1776,12 +1781,20 @@ void GSocket::Detected_Read()
|
|||||||
CALL_CALLBACK(this, GSOCK_CONNECTION);
|
CALL_CALLBACK(this, GSOCK_CONNECTION);
|
||||||
}
|
}
|
||||||
else if (num == 0)
|
else if (num == 0)
|
||||||
|
{
|
||||||
|
if (m_stream)
|
||||||
{
|
{
|
||||||
/* graceful shutdown */
|
/* graceful shutdown */
|
||||||
CALL_CALLBACK(this, GSOCK_LOST);
|
CALL_CALLBACK(this, GSOCK_LOST);
|
||||||
Shutdown();
|
Shutdown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
/* Empty datagram received */
|
||||||
|
CALL_CALLBACK(this, GSOCK_INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
/* Do not throw a lost event in cases where the socket isn't really lost */
|
/* Do not throw a lost event in cases where the socket isn't really lost */
|
||||||
if ((errno == EWOULDBLOCK) || (errno == EAGAIN) || (errno == EINTR))
|
if ((errno == EWOULDBLOCK) || (errno == EAGAIN) || (errno == EINTR))
|
||||||
|
|||||||
Reference in New Issue
Block a user