Permalink
Browse files

Docs

  • Loading branch information...
1 parent c371c80 commit 2fb0d73c60dc4cb92b5a559f170e0c5cc56a99bd @kakserpom committed Mar 19, 2013
Showing with 387 additions and 20 deletions.
  1. +120 −1 lib/BoundSocket.php
  2. +24 −2 lib/BoundTCPSocket.php
  3. +55 −8 lib/BoundUDPSocket.php
  4. +112 −3 lib/ConnectionPool.php
  5. +59 −5 lib/DNSClient.php
  6. +17 −1 lib/Daemon_Bootstrap.php
View
@@ -9,27 +9,125 @@
*/
abstract class BoundSocket {
+ /**
+ * Enabled?
+ * @var boolean
+ */
protected $enabled = false;
+
+ /**
+ * File descriptor
+ * @var mixed
+ */
protected $fd;
+
+ /**
+ * Event
+ * @var EventListener/Event
+ */
protected $ev;
+
+ /**
+ * PID of process which bound this socket
+ * @var int
+ */
protected $pid;
+
+ /**
+ * Pool
+ * @var ConnectionPool
+ */
protected $pool;
+
+ /**
+ * Listener mode?
+ * @var boolean
+ */
protected $listenerMode = false;
+
+ /**
+ * Context
+ * @var mixed
+ */
public $ctx; // @TODO: make it protected
+
+ /**
+ * URI
+ * @var string
+ */
protected $uri;
+
+ /**
+ * Context name
+ * @var string
+ */
protected $ctxname;
+
+ /**
+ * Reuse?
+ * @var boolean
+ */
protected $reuse = true;
+
+ /**
+ * SSL?
+ * @var boolean
+ */
protected $ssl = false;
+
+ /**
+ * Errorneous?
+ * @var boolean
+ */
protected $errorneous = false;
+ /**
+ * Private key file
+ * @var string
+ */
protected $pkfile;
+
+ /**
+ * Certificate file
+ * @var string
+ */
protected $certfile;
+
+ /**
+ * Passphrase
+ * @var string
+ */
protected $passphrase;
+
+ /**
+ * Verify peer?
+ * @var boolean
+ */
protected $verifypeer = false;
+
+ /**
+ * Allow self-signed?
+ * @var boolean
+ */
protected $allowselfsigned = true;
+ /**
+ * Source
+ * @var string
+ */
protected $source;
+
+ /**
+ * Revision
+ * @var integer
+ */
protected $revision;
+
+ /**
+ * Constructor
+ * @param string URI
+ * @return object
+ */
public function __construct($uri) {
$this->uri = is_array($uri) ? $uri : Daemon_Config::parseCfgUri($uri);
if (!$this->uri) {
@@ -41,6 +139,10 @@ public function __construct($uri) {
}
}
+ /**
+ * Import parameters
+ * @return void
+ */
protected function importParams() {
foreach ($this->uri['params'] as $key => $val) {
@@ -76,6 +178,11 @@ protected function importParams() {
}
}
+
+ /**
+ * Initialize SSL context
+ * @return void
+ */
protected function initSSLContext() {
if (!EventUtil::sslRandPoll()) {
Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed');
@@ -91,6 +198,11 @@ protected function initSSLContext() {
]);
}
+ /**
+ * Attach to ConnectionPool
+ * @param ConnectionPool
+ * @return void
+ */
public function attachTo($pool) {
$this->pool = $pool;
$this->pool->attachBound($this);
@@ -195,7 +307,10 @@ public function close() {
}
}
-
+ /**
+ * Finishes BoundSocket
+ * @return void
+ */
public function finish() {
$this->disable();
$this->close();
@@ -219,6 +334,10 @@ public function onAcceptEv($stream = null, $events = 0, $arg = null) {
$this->accept();
}
+ /**
+ * Tries to accept new connection
+ * @return Connection|null
+ */
public function accept() {
if (Daemon::$config->logevents->value) {
Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' invoked.');
View
@@ -8,12 +8,35 @@
* @author Zorin Vasily <kak.serpom.po.yaitsam@gmail.com>
*/
class BoundTCPSocket extends BoundSocket {
+ /**
+ * Hostname
+ * @var string
+ */
protected $host;
+
+ /**
+ * Port
+ * @var integer
+ */
protected $port;
+
+ /**
+ * Listener mode?
+ * @var boolean
+ */
protected $listenerMode = true;
- protected $defaultPort;
+ /**
+ * Default port
+ * @var integer
+ */
+ protected $defaultPort;
+ /**
+ * Sets default port
+ * @param integer Port
+ * @return void
+ */
public function setDefaultPort($port) {
$this->defaultPort = $port;
}
@@ -67,7 +90,6 @@ public function bindSocket() {
return true;
}
-
/**
* Called when new connections is waiting for accept
* @param resource Descriptor
View
@@ -8,18 +8,65 @@
* @author Zorin Vasily <kak.serpom.po.yaitsam@gmail.com>
*/
class BoundUDPSocket extends BoundSocket {
- public $defaultPort = 0;
- public $reuse = true;
- public $host;
- public $port;
- public $portsMap = [];
+ /**
+ * Hostname
+ * @var string
+ */
+ protected $host;
+
+ /**
+ * Port
+ * @var integer
+ */
+ protected $port;
+
+ /**
+ * Listener mode?
+ * @var boolean
+ */
+ protected $listenerMode = true;
+ /**
+ * Default port
+ * @var integer
+ */
+ protected $defaultPort;
+
+ /**
+ * Reuse?
+ * @var boolean
+ */
+ protected $reuse = true;
+
+ /**
+ * Ports map
+ * @var hash [portNumber => Connection]
+ */
+ protected $portsMap = [];
+
+ /**
+ * Sets default port
+ * @param integer Port
+ * @return void
+ */
+ public function setDefaultPort($port) {
+ $this->defaultPort = $port;
+ }
+
+ /**
+ * Unassigns addr
+ * @param string Address
+ * @return void
+ */
public function unassignAddr($addr) {
unset($this->portsMap[$addr]);
}
- public function setDefaultPort($n) {
- $this->defaultPort = (int) $n;
- }
+
+ /**
+ * Sets reuse
+ * @param integer Port
+ * @return void
+ */
public function setReuse($reuse = true) {
$this->reuse = $reuse;
}
Oops, something went wrong.

0 comments on commit 2fb0d73

Please sign in to comment.