]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Stomp blocking writes fix
authorBrion Vibber <brion@pobox.com>
Thu, 3 Jun 2010 23:09:47 +0000 (16:09 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 3 Jun 2010 23:09:47 +0000 (16:09 -0700)
lib/liberalstomp.php

index 3d38953fd2cac9b3770673a06876bd9b3de7c5bd..70c22c17e6a949ef7d72b749ce20c30dea0965a5 100644 (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);
+        }
+    }
+ }