socket_create() doesn't expose error if one occurs [CVS HEAD]

From: Date: Sat, 27 Apr 2002 12:22:56 +0000
Subject: socket_create() doesn't expose error if one occurs [CVS HEAD]
Groups: php.dev 
Request: Send a blank email to php-dev+get-83423@lists.php.net to get a copy of this message
Hi, socket_create() doesn't expose an error if one occurs when creating a new socket with socket(). The current code is: [...] php_sock->bsd_socket = socket(arg1, arg2, arg3); php_sock->type = arg1; if (IS_INVALID_SOCKET(php_sock)) { efree(php_sock); RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, php_sock, le_socket); } This logic silently hides the error if we encounter one during socket creating. Since the current socket error reporting facility only operates with a valid socket resource context we have a limitation here because obviously there's no valid socket resource context here (false is returned and we don't have the socket resource yet). Suggestion: Introduce a (per thread) global variable which always stores the error message of the last socket function which failed and teach socket_last_error() to return this value if no resource is passed to it, e.g.: if (false == (socket_create(...))) { echo "Failed, reason:", socket_strerror(socket_last_error()), "\n"; [...] } To be consistent with the other socket_*() functions I also suggest emitting an E_WARNING message if it fails (basically all other functions have been rewritten this way). I haven't included a patch because it's rather trivial. Any objections or better suggestions how to handle this? - Markus -- Please always Cc to me when replying to me on the lists. GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc "Mind if I MFH ?" "What QA did you do on it?" "the usual?" "ah... none :)"

« previous php.dev (#83423) next »