summaryrefslogtreecommitdiff
path: root/ext/standard/fsock.c
diff options
context:
space:
mode:
authorJason Greene <jason@php.net>2002-06-11 03:55:28 +0000
committerJason Greene <jason@php.net>2002-06-11 03:55:28 +0000
commitc6a36d585bd6a7508e8f8722d044454fe3cceea4 (patch)
treec413aa5798a597389367a16ae953f0a42acb64b9 /ext/standard/fsock.c
parente51bd48d229a0a8c37ddf14f4e5d17e2cf1549ba (diff)
downloadphp-git-c6a36d585bd6a7508e8f8722d044454fe3cceea4.tar.gz
@Impelemented timeout functionality, and fixed error handling of fsockopen() on win32
Also fixed error handling on unix (micropatch) Closes Bug #14740
Diffstat (limited to 'ext/standard/fsock.c')
-rw-r--r--ext/standard/fsock.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
index 9d90788298..7b57267e2d 100644
--- a/ext/standard/fsock.c
+++ b/ext/standard/fsock.c
@@ -121,6 +121,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
char *host;
int host_len;
int port = -1;
+ int err;
zval *zerrno = NULL, *zerrstr = NULL;
double timeout = 60;
unsigned long conv;
@@ -152,7 +153,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
zval_dtor(zerrno);
ZVAL_LONG(zerrno, 0);
}
- if (zerrstr) {
+ if (zerrstr) {
zval_dtor(zerrstr);
ZVAL_STRING(zerrno, "", 1);
}
@@ -192,6 +193,10 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
else
#endif
stream = php_stream_sock_open_host(host, (unsigned short)port, socktype, (int)timeout, persistent);
+#ifdef PHP_WIN32
+ /* Preserve error */
+ err = WSAGetLastError();
+#endif
if (stream == NULL) {
zend_error(E_WARNING, "%s(): unable to connect to %s:%d",
@@ -227,15 +232,32 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
efree(hashkey);
if (stream == NULL) {
- if (zerrno) {
+ if (zerrno) {
zval_dtor(zerrno);
+#ifndef PHP_WIN32
ZVAL_LONG(zerrno, errno);
+#else
+ ZVAL_LONG(zerrno, err);
+#endif
}
- if (zerrstr) {
+#ifndef PHP_WIN32
+ if (zerrstr) {
zval_dtor(zerrstr);
- ZVAL_STRING(zerrno, strerror(errno), 1);
+ ZVAL_STRING(zerrstr, strerror(errno), 1);
}
+#else
+ if (zerrstr) {
+ char *buf;
+ if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
+ Z_LVAL_P(zerrno), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL)) {
+ RETURN_FALSE;
+ }
+
+ ZVAL_STRING(zerrstr, buf, 1);
+ LocalFree(buf);
+ }
+#endif
RETURN_FALSE;
}