Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeouts not properly checking timeout status of stream connection when performing reading and writing. #56

Merged
merged 2 commits into from Jan 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion PhpAmqpLib/Connection/AMQPConnection.php
Expand Up @@ -84,7 +84,10 @@ public function __construct($host, $port,
throw new \Exception ("Error Connecting to server($errno): $errstr "); throw new \Exception ("Error Connecting to server($errno): $errstr ");
} }


stream_set_timeout($this->sock, $read_write_timeout); if(!stream_set_timeout($this->sock, $read_write_timeout)) {
throw new \Exception ("Timeout could not be set");
}

stream_set_blocking($this->sock, 1); stream_set_blocking($this->sock, 1);
$this->input = new AMQPReader(null, $this->sock); $this->input = new AMQPReader(null, $this->sock);


Expand Down Expand Up @@ -167,6 +170,13 @@ protected function write($data)
if ($written === 0) { if ($written === 0) {
throw new \Exception ("Broken pipe or closed connection"); throw new \Exception ("Broken pipe or closed connection");
} }

// get status of socket to determine whether or not it has timed out
$info = stream_get_meta_data($this->sock);
if($info['timed_out']) {
throw new \Exception("Error sending data. Socket connection timed out");
}

$len = $len - $written; $len = $len - $written;
if ($len > 0) { if ($len > 0) {
$data = substr($data,0-$len); $data = substr($data,0-$len);
Expand Down
7 changes: 7 additions & 0 deletions PhpAmqpLib/Wire/AMQPReader.php
Expand Up @@ -53,6 +53,13 @@ private function rawread($n)


while ($read < $n && !feof($this->sock->real_sock()) && while ($read < $n && !feof($this->sock->real_sock()) &&
(false !== ($buf = fread($this->sock->real_sock(), $n - $read)))) { (false !== ($buf = fread($this->sock->real_sock(), $n - $read)))) {

// get status of socket to determine whether or not it has timed out
$info = stream_get_meta_data($this->sock->real_sock());
if($info['timed_out']) {
throw new \Exception('Error reading data. Socket connection timed out');
}

$read += strlen($buf); $read += strlen($buf);
$res .= $buf; $res .= $buf;
} }
Expand Down