mirror of
https://github.com/lsalzman/enet
synced 2024-11-21 06:25:59 -07:00
handle EINTR in enet_socket_wait
This commit is contained in:
parent
5d76b92c54
commit
7dc0189ffb
4 changed files with 40 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
* added enet_linked_version() for checking the linked version
|
||||
* added enet_socket_get_address() for querying the local address of a socket
|
||||
* silenced some debugging prints unless ENET_DEBUG is defined during compilation
|
||||
* handle EINTR in enet_socket_wait() so that enet_host_service() doesn't propagate errors from signals
|
||||
|
||||
ENet 1.3.7 (March 6, 2013):
|
||||
|
||||
|
|
|
@ -46,9 +46,10 @@ typedef enum _ENetSocketType
|
|||
|
||||
typedef enum _ENetSocketWait
|
||||
{
|
||||
ENET_SOCKET_WAIT_NONE = 0,
|
||||
ENET_SOCKET_WAIT_SEND = (1 << 0),
|
||||
ENET_SOCKET_WAIT_RECEIVE = (1 << 1)
|
||||
ENET_SOCKET_WAIT_NONE = 0,
|
||||
ENET_SOCKET_WAIT_SEND = (1 << 0),
|
||||
ENET_SOCKET_WAIT_RECEIVE = (1 << 1),
|
||||
ENET_SOCKET_WAIT_INTERRUPT = (1 << 2)
|
||||
} ENetSocketWait;
|
||||
|
||||
typedef enum _ENetSocketOption
|
||||
|
|
26
protocol.c
26
protocol.c
|
@ -1895,18 +1895,22 @@ enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)
|
|||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
host -> serviceTime = enet_time_get ();
|
||||
|
||||
if (ENET_TIME_GREATER_EQUAL (host -> serviceTime, timeout))
|
||||
return 0;
|
||||
|
||||
waitCondition = ENET_SOCKET_WAIT_RECEIVE | ENET_SOCKET_WAIT_INTERRUPT;
|
||||
|
||||
if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
|
||||
return -1;
|
||||
}
|
||||
while (waitCondition & ENET_SOCKET_WAIT_INTERRUPT);
|
||||
|
||||
host -> serviceTime = enet_time_get ();
|
||||
|
||||
if (ENET_TIME_GREATER_EQUAL (host -> serviceTime, timeout))
|
||||
return 0;
|
||||
|
||||
waitCondition = ENET_SOCKET_WAIT_RECEIVE;
|
||||
|
||||
if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)
|
||||
return -1;
|
||||
|
||||
host -> serviceTime = enet_time_get ();
|
||||
} while (waitCondition == ENET_SOCKET_WAIT_RECEIVE);
|
||||
} while (waitCondition & ENET_SOCKET_WAIT_RECEIVE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
22
unix.c
22
unix.c
|
@ -435,7 +435,16 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
|
|||
pollCount = poll (& pollSocket, 1, timeout);
|
||||
|
||||
if (pollCount < 0)
|
||||
return -1;
|
||||
{
|
||||
if (errno == EINTR && * condition & ENET_SOCKET_WAIT_INTERRUPT)
|
||||
{
|
||||
* condition = ENET_SOCKET_WAIT_INTERRUPT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
* condition = ENET_SOCKET_WAIT_NONE;
|
||||
|
||||
|
@ -469,7 +478,16 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
|
|||
selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
|
||||
|
||||
if (selectCount < 0)
|
||||
return -1;
|
||||
{
|
||||
if (errno == EINTR && * condition & ENET_SOCKET_WAIT_INTERRUPT)
|
||||
{
|
||||
* condition = ENET_SOCKET_WAIT_INTERRUPT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
* condition = ENET_SOCKET_WAIT_NONE;
|
||||
|
||||
|
|
Loading…
Reference in a new issue