From: Brion Vibber Date: Thu, 3 Jun 2010 23:09:47 +0000 (-0700) Subject: Stomp blocking writes fix X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=791b98046d2c81aecfa468c06d4b7fd1f06ea8fa;p=quix0rs-gnu-social.git Stomp blocking writes fix --- diff --git a/lib/liberalstomp.php b/lib/liberalstomp.php index 3d38953fd2..70c22c17e6 100644 --- a/lib/liberalstomp.php +++ b/lib/liberalstomp.php @@ -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); + } + } + }