Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/toy-machine/stomp-php int…
Browse files Browse the repository at this point in the history
…o toy-machine-master

Conflicts:
	src/main/FuseSource/Stomp/Stomp.php
  • Loading branch information
monofone committed Nov 23, 2012
2 parents 7dde75c + 262d9d7 commit 92390ed
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/main/FuseSource/Stomp/Stomp.php
Expand Up @@ -30,7 +30,7 @@
*
* @package Stomp
* @author Hiram Chirino <hiram@hiramchirino.com>
* @author Dejan Bosanac <dejan@nighttale.net>
* @author Dejan Bosanac <dejan@nighttale.net>
* @author Michael Caplan <mcaplan@labnet.net>
* @version $Revision: 43 $
*/
Expand All @@ -49,14 +49,14 @@ class Stomp
* @var int
*/
public $prefetchSize = 1;

/**
* Client id used for durable subscriptions
*
* @var string
*/
public $clientId = null;

protected $_brokerUri = null;
protected $_socket = null;
protected $_hosts = array();
Expand All @@ -72,7 +72,7 @@ class Stomp
protected $_read_timeout_milliseconds = 0;
protected $_connect_timeout_seconds = 60;
protected $_waitbuf = array();

/**
* Constructor
*
Expand Down Expand Up @@ -137,16 +137,16 @@ protected function _makeConnection ()
if (count($this->_hosts) == 0) {
throw new StompException("No broker defined");
}

// force disconnect, if previous established connection exists
$this->disconnect();

$i = $this->_currentHost;
$att = 0;
$connected = false;
$connect_errno = null;
$connect_errstr = null;

while (! $connected && $att ++ < $this->_attempts) {
if (isset($this->_params['randomize']) && $this->_params['randomize'] == 'true') {
$i = rand(0, count($this->_hosts) - 1);
Expand Down Expand Up @@ -212,7 +212,7 @@ public function connect ($username = '', $password = '')
}
}
}

/**
* Check if client session has ben established
*
Expand All @@ -232,7 +232,7 @@ public function getSessionId()
return $this->_sessionId;
}
/**
* Send a message to a destination in the messaging system
* Send a message to a destination in the messaging system
*
* @param string $destination Destination queue
* @param string|Frame $msg Message
Expand Down Expand Up @@ -445,7 +445,7 @@ public function ack ($message, $transactionId = null)
$headers = $message->headers;
if (isset($transactionId)) {
$headers['transaction'] = $transactionId;
}
}
$frame = new Frame('ACK', $headers);
$this->_writeFrame($frame);
return true;
Expand Down Expand Up @@ -502,19 +502,19 @@ protected function _writeFrame (Frame $stompFrame)
$this->_writeFrame($stompFrame);
}
}

/**
* Set timeout to wait for content to read
*
* @param int $seconds_to_wait Seconds to wait for a frame
* @param int $milliseconds Milliseconds to wait for a frame
*/
public function setReadTimeout($seconds, $milliseconds = 0)
public function setReadTimeout($seconds, $milliseconds = 0)
{
$this->_read_timeout_seconds = $seconds;
$this->_read_timeout_milliseconds = $milliseconds;
}

/**
* Read response frame from server
*
Expand All @@ -529,14 +529,14 @@ public function readFrame ()
if (!$this->hasFrameToRead()) {
return false;
}

$rb = 1024;
$data = '';
$end = false;

do {
$read = fread($this->_socket, $rb);
if ($read === false) {
if ($read === false || $read === "") {
$this->_reconnect();
return $this->readFrame();
}
Expand All @@ -547,7 +547,7 @@ public function readFrame ()
}
$len = strlen($data);
} while ($len < 2 || $end == false);

list ($header, $body) = explode("\n\n", $data, 2);
$header = explode("\n", $header);
$headers = array();
Expand All @@ -568,7 +568,7 @@ public function readFrame ()
}
return $frame;
}

/**
* Check if there is a frame to read
*
Expand All @@ -579,9 +579,9 @@ public function hasFrameToRead()
$read = array($this->_socket);
$write = null;
$except = null;

$has_frame_to_read = @stream_select($read, $write, $except, $this->_read_timeout_seconds, $this->_read_timeout_milliseconds);

if ($has_frame_to_read !== false)
$has_frame_to_read = count($read);

Expand All @@ -591,18 +591,18 @@ public function hasFrameToRead()
} else if ($has_frame_to_read > 0) {
return true;
} else {
return false;
return false;
}
}

/**
* Reconnects and renews subscriptions (if there were any)
* Call this method when you detect connection problems
* Call this method when you detect connection problems
*/
protected function _reconnect ()
{
$subscriptions = $this->_subscriptions;

$this->connect($this->_username, $this->_password);
foreach ($subscriptions as $dest => $properties) {
$this->subscribe($dest, $properties);
Expand All @@ -616,4 +616,4 @@ public function __destruct()
{
$this->disconnect();
}
}
}

0 comments on commit 92390ed

Please sign in to comment.