Permalink
Browse files

Docs

  • Loading branch information...
kakserpom committed Mar 20, 2013
1 parent c54b731 commit 401072b515f59daff0babe206733e2adec36aa7d
@@ -29,7 +29,7 @@ class IRCClientConnection extends NetworkClientConnection {
*/
public function onReady() {
if ($this->pool->identd) {
- $this->pool->identd->registerPair($this->locPort, $this->port, 'UNIX : '.$this->user);
+ $this->pool->identd->registerPair($this->locPort, $this->port, ['UNIX', $this->user]);
}
list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
$this->command('USER', $this->user, 0, '*', $this->realname);
View
@@ -52,7 +52,11 @@ public function RPCall($method, $args) {
*/
public function registerPair($local, $foreign, $user) {
- $this->appInstance->broadcastCall('registerPair', [$local, $foreign, $user]);
+ $this->appInstance->broadcastCall('registerPair', [
+ $local,
+ $foreign,
+ is_array($user) ? implode(' : ', $user) : $user
+ ]);
}
/* Unregister pair
View
@@ -34,19 +34,19 @@ protected function getConfigDefaults() {
/**
* Default servers
- * @var boolean
+ * @var string|array
*/
'servers' => '127.0.0.1',
/**
* Default server
- * @var boolean
+ * @var string
*/
'server' => '127.0.0.1',
/**
* Maximum connections per server
- * @var boolean
+ * @var integer
*/
'maxconnperserv' => 32
];
@@ -8,23 +8,61 @@
* @author Zorin Vasily <kak.serpom.po.yaitsam@gmail.com>
*/
class NetworkClientConnection extends Connection {
+ /**
+ * Busy?
+ * @var boolean
+ */
protected $busy = false;
+
+ /**
+ * Timeout
+ * @var integer
+ */
protected $timeout = 60;
+
+ /**
+ * No Send-and-Forget?
+ * @var boolean
+ */
protected $noSAF = true;
- protected $onResponse; // stack of onResponse callbacks
- protected $alive = true;
+ /**
+ * Stack of onResponse callbacks
+ * @var StackCallbacks
+ */
+ protected $onResponse;
+
+ /**
+ * Alive?
+ * @var boolean
+ */
+ protected $alive = true; // @TODO: ???
+
+ /**
+ * Constructor
+ * @param mixed File descriptor
+ * @param [ConnectionPool
+ * @return objectg
+ */
public function __construct($fd, $pool = null) {
parent::__construct($fd, $pool);
$this->onResponse = new StackCallbacks;
}
+ /**
+ * Busy?
+ * @return boolean
+ */
public function isBusy() {
return $this->busy;
}
- public function onResponse($m) {
- $this->onResponse->push($m);
+ /**
+ * Push callback to onReponse stack
+ * @return void
+ */
+ public function onResponse($cb) {
+ $this->onResponse->push($cb);
}
/**
* Called when the connection is handshaked (at low-level), and peer is ready to recv. data
@@ -40,8 +78,14 @@ public function onReady() {
}
}
- public function setFree($bool = true) {
- $this->busy = !$bool;
+
+ /**
+ * Set connection free/busy
+ * @param boolean Free?
+ * @return void
+ */
+ public function setFree($free = true) {
+ $this->busy = !$free;
if ($this->url === null) {
return;
}
@@ -57,10 +101,18 @@ public function setFree($bool = true) {
}
}
+ /**
+ * Set connection free
+ * @return void
+ */
public function release() {
$this->setFree(true);
}
+ /**
+ * Set connection free/busy according to onResponse emptiness and ->finished
+ * @return void
+ */
public function checkFree() {
$this->setFree(!$this->finished && $this->onResponse && $this->onResponse->isEmpty());
}
@@ -1,20 +1,47 @@
<?php
class PriorityQueueCallbacks extends SplPriorityQueue {
+ /**
+ * Insert callback
+ * @param callable Callback
+ * @param integer Priority
+ * @return void
+ */
public function insert($cb, $pri = 0) {
parent::insert(CallbackWrapper::wrap($cb), $pri);
}
+
+ /**
+ * Enqueue callback
+ * @param callable Callback
+ * @return void
+ */
public function enqueue($cb, $pri = 0) {
return parent::insert(CallbackWrapper::wrap($cb), $pri);
}
+
+ /**
+ * Dequeue
+ * @return callabble
+ */
public function dequeue() {
return $this->extract();
}
+
+ /**
+ * Compare two priorities
+ * @return integer
+ */
public function compare($pri1, $pri2) {
if ($pri1 === $pri2) {
return 0;
}
return $pri1 < $pri2 ? -1 : 1;
}
+
+ /**
+ * Executes one callback from the top of queue with arbitrary arguments
+ * @return integer
+ */
public function executeOne() {
if ($this->isEmpty()) {
return false;
@@ -25,6 +52,11 @@ public function executeOne() {
}
return true;
}
+
+ /**
+ * Executes all callbacks from the top of queue to bottom with arbitrary arguments
+ * @return integer
+ */
public function executeAll() {
if ($this->isEmpty()) {
return 0;
View
@@ -8,22 +8,48 @@
*/
class RedisClient extends NetworkClient {
- protected $subscribeCb = []; // subscriptions callbacks
+
+ /**
+ * Subcriptions
+ * @var hash
+ */
+ protected $subscribeCb = [];
+
/**
* Setting default config options
* Overriden from NetworkClient::getConfigDefaults
* @return array|false
*/
protected function getConfigDefaults() {
return [
- // @todo add description strings
+ /**
+ * Default servers
+ * @var string|array
+ */
'servers' => 'tcp://127.0.0.1',
+
+ /**
+ * Default port
+ * @var integer
+ */
'port' => 6379,
+
+ /**
+ * Maximum connections per server
+ * @var integer
+ */
'maxconnperserv' => 32,
];
}
-
+ /**
+ * Magic __call.
+ * @method Command name
+ * @param .. Command-dependent set of arguments ..
+ * @param [callback Callback. Optional.
+ * @example $redis->lpush('mylist', microtime(true));
+ * @return void
+ */
public function __call($name, $args) {
$onResponse = null;
if (($e = end($args)) && (is_array($e) || is_object($e)) && is_callable($e)) {
@@ -43,7 +69,7 @@ public function __call($name, $args) {
if (($name === 'SUBSCRIBE') || ($name === 'PSUBSCRIBE')) {
for ($i = 1; $i < $s; ++$i) {
$arg = $args[$i];
- // TODO: check if $onResponse already in subscribeCb[$arg]?
+ // @TODO: check if $onResponse already in subscribeCb[$arg]?
$this->subscribeCb[$arg][] = CallbackWrapper::wrap($onResponse);
}
}
@@ -9,14 +9,48 @@
class RedisClientConnection extends NetworkClientConnection {
- public $result = null; // current result (array)
- public $resultLength = 0;
- public $error; // error message
- public $key; // current incoming key
- protected $EOL = "\r\n"; // EOL for readln() and writeln()
- const STATE_BINARY = 1;
+ /**
+ * Current result
+ * @var array|null
+ */
+ public $result = null;
+
+ /**
+ * Current error message
+ * @var string
+ */
+ public $error;
+
+ /**
+ * Current incoming key
+ * @var string
+ */
+ protected $key;
+
+ /**
+ * Current result length
+ * @var integer
+ */
+ protected $resultLength = 0;
+
+ /**
+ * EOL
+ * @var string "\r\n"
+ */
+ protected $EOL = "\r\n";
+
+ /**
+ * No Send-and-Forget?
+ * @var boolean
+ */
protected $noSAF = true;
+ /**
+ * In the middle of binary response part
+ * @const integer
+ */
+ const STATE_BINARY = 1;
+
/**
* Check if arrived data is message from subscription
*/

0 comments on commit 401072b

Please sign in to comment.