From 0f233292063400ea7fdbcd5e5d5cd6e54f8cd71c Mon Sep 17 00:00:00 2001 From: Javivi Date: Mon, 20 Feb 2017 17:46:01 +0100 Subject: [PATCH] Document magic numbers No more magic --- plugins/include/sockets.inc | 40 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/plugins/include/sockets.inc b/plugins/include/sockets.inc index 30412ef3..a117b785 100755 --- a/plugins/include/sockets.inc +++ b/plugins/include/sockets.inc @@ -41,23 +41,6 @@ #define SOCK_ERROR_SERVER_UNKNOWN 2 /* Server unknown */ #define SOCK_ERROR_WHILE_CONNECTING 3 /* Error while connecting */ -/* - * Nonblocking sockets error handler - * - * @param error Error code returned by socket_open() - * - * @note A newly created nonblocking socket may be still finishing his connection when - * socket_open() returns the socket descriptor. This stock should be used to - * check if socket_open() succeded on creating a new socket, and socket_is_writable() - * should be used later on the socket descriptor when data is about to be sent to check if - * the connection ended up being established. - * - * - * @return true if the socket is succesfully created and connected or currently connecting - * false if the socket failed to be created - */ -stock bool:SOCK_ERROR_EINPROGRESS(error) return (error == 0 || error == 10035 || error == 10036 || error == 115) - /** * Connects to the given node and service via TCP/UDP. * @@ -98,6 +81,29 @@ stock bool:SOCK_ERROR_EINPROGRESS(error) return (error == 0 || error == 10035 || */ native socket_open(const _hostname[], _port, _protocol = SOCKET_TCP, &_error, _flags = 0); +/* + * Nonblocking sockets error handler + * + * @param error Error code returned by socket_open() + * + * @note A newly created nonblocking socket may be still finishing his connection when + * socket_open() returns the socket descriptor. This stock should be used to + * check if socket_open() succeded on creating a new socket, and socket_is_writable() + * should be used later on the socket descriptor when data is about to be sent to check if + * the connection ended up being established. + * + * + * @return true if the socket is succesfully created and connected or currently connecting + * false if the socket failed to be created + */ +stock bool:SOCK_ERROR_EINPROGRESS(error) +{ + return (error == 0 + || error == 10035 // WINDOWS, WSAEWOULDBLOCK + || error == 10036 // WINDOWS, WSAEINPROGRESS + || error == 115) // POSIX, EINPROGRESS +} + /** * Closes a socket *