diff --git a/ChangeLog b/ChangeLog index ddb34eb..e60700a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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): diff --git a/include/enet/enet.h b/include/enet/enet.h index e32d68f..7bd10da 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -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 diff --git a/protocol.c b/protocol.c index 807c368..0fbd012 100644 --- a/protocol.c +++ b/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; } diff --git a/unix.c b/unix.c index fe8a280..47ffcb9 100644 --- a/unix.c +++ b/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;