diff options
author | Wez Furlong <wez@php.net> | 2004-08-10 13:44:43 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2004-08-10 13:44:43 +0000 |
commit | b21a7357fc82863d2649ba5d082c9742c8b4beff (patch) | |
tree | aa581b69698fd1caf301b8c775b51691ad442afc | |
parent | db855e2c74a889b18789cba3a2cb7fdfccbaa62d (diff) | |
download | php-git-b21a7357fc82863d2649ba5d082c9742c8b4beff.tar.gz |
Fix for #29256 from Dmitry, very slightly modified
-rw-r--r-- | main/streams/xp_socket.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index f14c96445d..a16cbe0125 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -52,13 +52,49 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count return 0; } +retry: didwrite = send(sock->socket, buf, count, 0); if (didwrite <= 0) { - char *estr = php_socket_strerror(php_socket_errno(), NULL, 0); + long err = php_socket_errno(); + char *estr; + if (sock->is_blocked && err == EWOULDBLOCK) { + fd_set fdw, tfdw; + int retval; + struct timeval timeout, *ptimeout; + + FD_ZERO(&fdw); + FD_SET(sock->socket, &fdw); + sock->timeout_event = 0; + + if (sock->timeout.tv_sec == -1) + ptimeout = NULL; + else + ptimeout = &timeout; + + do { + tfdw = fdw; + timeout = sock->timeout; + + retval = select(sock->socket + 1, NULL, &tfdw, NULL, ptimeout); + + if (retval == 0) { + sock->timeout_event = 1; + break; + } + + if (retval > 0) { + /* writable now; retry */ + goto retry; + } + + err = php_socket_errno(); + } while (err == EINTR); + } + estr = php_socket_strerror(err, NULL, 0); php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of %ld bytes failed with errno=%d %s", - (long)count, php_socket_errno(), estr); + (long)count, err, estr); efree(estr); } |