Skip to content

Commit

Permalink
Heartbeat frames will decrease the timeout used when calling wait_cha…
Browse files Browse the repository at this point in the history
…nnel - heartbeat frames do not reset the timeout
  • Loading branch information
ruicampos committed Jul 22, 2015
1 parent 4403cd9 commit 1822b6d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions PhpAmqpLib/Connection/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,23 @@ protected function wait_frame($timeout = 0)
*/
protected function wait_channel($channel_id, $timeout = 0)
{
// Keeping the original timeout unchanged.
$_timeout = $timeout;
while (true) {
list($frame_type, $frame_channel, $payload) = $this->wait_frame($timeout);
$now = time();
list($frame_type, $frame_channel, $payload) = $this->wait_frame($_timeout);

if ($frame_channel === 0 && $frame_type === 8) {
// skip heartbeat frames
// skip heartbeat frames and reduce the timeout by the time passed
if( $_timeout > 0 )
{
$_timeout -= time() - $now;
if( $_timeout <= 0 )
{
// If timeout has reached, throw the exception without calling wait_frame
throw new AMQPTimeoutException( "Timeout waiting on channel");
}
}
continue;

} else {
Expand Down

0 comments on commit 1822b6d

Please sign in to comment.