From 51524221948da8824d11d8682c516d802a7ce4e7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 20 Jun 2014 13:31:23 +0400 Subject: [PATCH] Check if socket is still alive --- main/streams/xp_socket.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 9e1521b537..b4799d48a8 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -57,7 +57,7 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count int didwrite; struct timeval *ptimeout; - if (sock->socket == -1) { + if (!sock || sock->socket == -1) { return 0; } @@ -116,7 +116,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data int retval; struct timeval *ptimeout; - if (sock->socket == -1) { + if (!sock || sock->socket == -1) { return; } @@ -146,7 +146,7 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; int nr_bytes = 0; - if (sock->socket == -1) { + if (!sock || sock->socket == -1) { return 0; } @@ -179,6 +179,10 @@ static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC) int n; #endif + if (!sock) { + return 0; + } + if (close_handle) { #ifdef PHP_WIN32 @@ -271,6 +275,10 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; php_stream_xport_param *xparam; + if (!sock) { + return PHP_STREAM_OPTION_RETURN_NOTIMPL; + } + switch(option) { case PHP_STREAM_OPTION_CHECK_LIVENESS: { @@ -413,6 +421,10 @@ static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) { php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; + if (!sock) { + return FAILURE; + } + switch(castas) { case PHP_STREAM_AS_STDIO: if (ret) { -- 2.40.0