summaryrefslogtreecommitdiff
path: root/lib/liberalstomp.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-06-03 16:09:47 -0700
committerBrion Vibber <brion@pobox.com>2010-06-03 16:09:47 -0700
commit791b98046d2c81aecfa468c06d4b7fd1f06ea8fa (patch)
tree3d6105ea16d09075a3942e53617bb4fc12190fc4 /lib/liberalstomp.php
parent17ab15a3d02c335f2d9d333ac3773c037e796cf5 (diff)
Stomp blocking writes fix
Diffstat (limited to 'lib/liberalstomp.php')
-rw-r--r--lib/liberalstomp.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/liberalstomp.php b/lib/liberalstomp.php
index 3d38953fd..70c22c17e 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);
+ }
+ }
+ }