Stomp blocking writes fix

This commit is contained in:
Brion Vibber 2010-06-03 16:09:47 -07:00
parent 17ab15a3d0
commit 791b98046d
1 changed files with 26 additions and 1 deletions

View File

@ -147,5 +147,30 @@ class LiberalStomp extends Stomp
}
return $frame;
}
}
/**
* Write frame to server
*
* @param StompFrame $stompFrame
*/
protected function _writeFrame (StompFrame $stompFrame)
{
if (!is_resource($this->_socket)) {
require_once 'Stomp/Exception.php';
throw new StompException('Socket connection hasn\'t been established');
}
$data = $stompFrame->__toString();
// Make sure the socket's in a writable state; if not, wait a bit.
stream_set_blocking($this->_socket, 1);
$r = fwrite($this->_socket, $data, strlen($data));
stream_set_blocking($this->_socket, 0);
if ($r === false || $r == 0) {
$this->_reconnect();
$this->_writeFrame($stompFrame);
}
}
}