cvs: php4 /ext/sockets sockets.c

From: Date: Sun, 07 Jul 2002 07:01:18 +0000
Subject: cvs: php4 /ext/sockets sockets.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-12737@lists.php.net to get a copy of this message
jason Sun Jul 7 03:01:18 2002 EDT Modified files: /php4/ext/sockets sockets.c Log: Remove sleep workaround, and fix the actual win32 memory leak which was occurring in the error reporting system. The reason why sleepex appeared to be working was because it suppressed EWOULDBLOCK errors in the example (which was non-blocking) @Fix win32 memory leak in /ext/sockets that would occur on any error condition @Fix host resolution error messages on win32 Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.116 php4/ext/sockets/sockets.c:1.117 --- php4/ext/sockets/sockets.c:1.116 Tue Jun 25 02:24:45 2002 +++ php4/ext/sockets/sockets.c Sun Jul 7 03:01:17 2002 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sockets.c,v 1.116 2002/06/25 06:24:45 mfischer Exp $ */ +/* $Id: sockets.c,v 1.117 2002/07/07 07:01:17 jason Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -111,6 +111,9 @@ static unsigned char third_through_seventh_args_force_ref[] = {7, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE}; +/* Global buffer for php_strerror() */ +static char php_strerror_buf[10000]; + /* {{{ sockets_functions[] */ function_entry sockets_functions[] = { @@ -343,16 +346,25 @@ buf = hstrerror(error); #else { - static char buf[100]; - sprintf(buf, "Host lookup error %d", error); + sprintf(php_strerror_buf, "Host lookup error %d", error); + buf = php_strerror_buf; } #endif } else { buf = strerror(error); } -#else - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL); +#else + { + LPTSTR tmp = NULL; + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &tmp, 0, NULL); + + strlcpy(php_strerror_buf, (char *) tmp, 10000); + LocalFree(tmp); + + buf = php_strerror_buf; + } #endif return (buf ? (char *) buf : ""); @@ -368,7 +380,11 @@ } else { if (! (host_entry = gethostbyname(string))) { /* Note: < -10000 indicates a host lookup error */ +#ifdef PHP_WIN32 + PHP_SOCKET_ERROR(php_sock, "Host lookup failed", WSAGetLastError()); +#else PHP_SOCKET_ERROR(php_sock, "Host lookup failed", (-10000 - h_errno)); +#endif return 0; } if (host_entry->h_addrtype != AF_INET) { @@ -754,8 +770,6 @@ retval = (*read_function)(php_sock->bsd_socket, tmpbuf, length); #else retval = recv(php_sock->bsd_socket, tmpbuf, length, 0); - /* i don't know why, but it _does_ fix a memleak */ - SleepEx(1, TRUE); #endif if (retval == -1) {

« previous php.cvs (#12737) next »