From 0b64e77d96fbf2f80b78b768613c84584c84920f Mon Sep 17 00:00:00 2001 From: Martin Kraemer Date: Wed, 7 Feb 2007 22:39:58 +0000 Subject: [PATCH] Thrift: PHP Socket instrumentation for connect/read/write issues Summary: Sockets now error with timeout messages if it's a timeout over general read failures. Reviewed By: Slee Test Plan: Tested with payment broker client with overloaded addresses and send/recv timeouts. Revert Plan: revertible Notes: git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664993 13f79535-47bb-0310-9956-ffa450edef68 --- lib/php/src/transport/TSocket.php | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/php/src/transport/TSocket.php b/lib/php/src/transport/TSocket.php index b2bea914..d02b70b4 100644 --- a/lib/php/src/transport/TSocket.php +++ b/lib/php/src/transport/TSocket.php @@ -145,7 +145,7 @@ class TSocket extends TTransport { // Connect failed? if ($this->handle_ === FALSE) { - $error = 'TSocket: Could not connect to '.$this->host_.':'.$this->port_; + $error = 'TSocket: Could not connect to '.$this->host_.':'.$this->port_.' ('.$errstr.' ['.$errno.'])'; if ($this->debug_) { call_user_func($this->debugHandler_, $error); } @@ -184,8 +184,14 @@ class TSocket extends TTransport { while (TRUE) { $buf = @fread($this->handle_, $len); if ($buf === FALSE || $buf === '') { - throw new Exception('TSocket: Could not read '.$len.' bytes from '. - $this->host_.':'.$this->port_); + $md = stream_get_meta_data($this->handle_); + if ($md['timed_out']) { + throw new Exception('TSocket: timed out reading '.$len.' bytes from '. + $this->host_.':'.$this->port_); + } else { + throw new Exception('TSocket: Could not read '.$len.' bytes from '. + $this->host_.':'.$this->port_); + } } else if (($sz = strlen($buf)) < $len) { $md = stream_get_meta_data($this->handle_); if ($md['timed_out']) { @@ -214,8 +220,14 @@ class TSocket extends TTransport { } $data = @fread($this->handle_, $len); if ($data === FALSE || $data === '') { - throw new Exception('TSocket: Could not read '.$len.' bytes from '. - $this->host_.':'.$this->port_); + $md = stream_get_meta_data($this->handle_); + if ($md['timed_out']) { + throw new Exception('TSocket: timed out reading '.$len.' bytes from '. + $this->host_.':'.$this->port_); + } else { + throw new Exception('TSocket: Could not read '.$len.' bytes from '. + $this->host_.':'.$this->port_); + } } return $data; } @@ -233,8 +245,14 @@ class TSocket extends TTransport { while (!empty($buf)) { $got = @fwrite($this->handle_, $buf); if ($got === 0 || $got === FALSE) { - throw new Exception('TSocket: Could not write '.strlen($buf).' bytes '. - $this->host_.':'.$this->port_); + $md = stream_get_meta_data($this->handle_); + if ($md['timed_out']) { + throw new Exception('TSocket: timed out writing '.$len.' bytes from '. + $this->host_.':'.$this->port_); + } else { + throw new Exception('TSocket: Could not write '.strlen($buf).' bytes '. + $this->host_.':'.$this->port_); + } } $buf = substr($buf, $got); } -- 2.17.1