Bug #16819 Updated: FormatMessage and WSAGetLastError

From: Date: Fri, 26 Apr 2002 05:31:49 +0000
Subject: Bug #16819 Updated: FormatMessage and WSAGetLastError
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-6059@lists.php.net to get a copy of this message
ID: 16819 Updated by: Nofin@Mail2K.ru -Summary: socket_connect returns boolean, but not integer Reported By: Nofin@Mail2K.ru Status: Open Bug Type: Sockets related Operating System: Windows' 9x PHP Version: 4.1.2 New Comment: For the best understanding of a problem I bring endurance from the "Winsock Programmer's FAQ": >> Note that some people will tell you that the Win32 FormatMessage() API can be coerced into returning error messages for Winsock error numbers. At best, this is undocumented behavior that only works with some implementations of Winsock. I personally have not been able to get it to work, despite significant time devoted to the problem. My advice is that you're much better off spending your time constructing meaningful error messages than chasing something that could never work very well even if it was documented behavior. << Also in this book there is an example how to receive the textual message on an error from a code of an error. If you want I can to you it(him) send. I think that it is necessary to produce some modifications in functions ("socket.c": "php_strerror", "socket_strerror") , in connection with described above. Previous Comments: ------------------------------------------------------------------------ [2002-04-25 18:34:03] alindeman@php.net I fixed the return value part of the bug ------------------------------------------------------------------------ [2002-04-25 06:20:05] Nofin@Mail2K.ru 2) Function "socket_connect" (/ext/sockets/socket.c) calls function php_error: .... php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn)); ... but last parameter is not a pointer to string, it's an integer number (equals to "errn"), because "php_strerror(errn)" can not return error message (function "FormatMessage" fails). ------------------------------------------------------------------------ [2002-04-25 06:16:01] Nofin@Mail2K.ru 1) in your documentation (http://www.php.net/manual/en/function.socket-connect.php) "socket_connect" function described as: int socket_connect ( resource socket, string address [, int port]) but in your binaries (extensions/php_sockets.dll) and in source codes (/ext/sockets/socket.c) this function returns 0(false) or 1(true): ... if (retval != 0) { PHP_SOCKET_ERROR(php_sock, "unable to connect", errno); RETURN_FALSE; } RETURN_TRUE; ... Also "Example 2. Socket example: Simple TCP/IP client" (http://www.php.net/manual/en/ref.sockets.php) is wrong: ... $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket < 0) { echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n"; } else { echo "OK.\n"; } ... Must be something like this: ... if ($socket == 0) { ... 2) Function "socket_connect" (/ext/sockets/socket.c) calls function php_error: .... php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn)); ... but last parameter is not a pointer to string, it's an integer number (equals to "errn"), because "php_strerror(errn)" can not return error message (function "FormatMessage" fails). ------------------------------------------------------------------------ [2002-04-25 06:15:23] mfischer@php.net Yes, known thx. It's a documentation issue. ------------------------------------------------------------------------ [2002-04-25 06:13:40] Nofin@Mail2K.ru 1) in your documentation (http://www.php.net/manual/en/function.socket-connect.php) "socket_connect" function described as: int socket_connect ( resource socket, string address [, int port]) but in your binaries (extensions/php_sockets.dll) and in source codes (/ext/sockets/socket.c) this function returns 0(false) or 1(true): ... if (retval != 0) { PHP_SOCKET_ERROR(php_sock, "unable to connect", errno); RETURN_FALSE; } RETURN_TRUE; ... Also "Example 2. Socket example: Simple TCP/IP client" (http://www.php.net/manual/en/ref.sockets.php) is wrong: ... $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket < 0) { echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n"; } else { echo "OK.\n"; } ... Must be something like this: >> ... if ($socket == 0) { ... 2) Function "socket_connect" (/ext/sockets/socket.c) calls function php_error: .... php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), msg, errn, php_strerror(errn)); ... but last parameter is not a pointer to string, it's an integer number (equals to "errn"), because "php_strerror(errn)" can not return error message (function "FormatMessage" fails). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16819&edit=1

« previous php.bugs (#6059) next »