API docs and cleanup

This commit is contained in:
Chris Boden 2012-07-11 15:43:54 -04:00
parent 5494e0132b
commit fd9e03bd99
4 changed files with 32 additions and 4 deletions

View File

@ -9,7 +9,8 @@ use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor; use React\Socket\Server as Reactor;
/** /**
* Creates an open-ended socket to listen on a port for incomming connections. Events are delegated through this to attached applications * Creates an open-ended socket to listen on a port for incomming connections.
* Events are delegated through this to attached applications
*/ */
class IoServer { class IoServer {
/** /**
@ -48,6 +49,12 @@ class IoServer {
$this->handlers['error'] = array($this, 'handleError'); $this->handlers['error'] = array($this, 'handleError');
} }
/**
* @param Ratchet\MessageComponentInterface The application that I/O will call when events are received
* @param int The port to server sockets on
* @param string The address to receive sockets on (0.0.0.0 means receive connections from any)
* @return Ratchet\Server\IoServer
*/
public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') { public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') {
$loop = new StreamSelectLoop; $loop = new StreamSelectLoop;
$socket = new Reactor($loop); $socket = new Reactor($loop);
@ -56,10 +63,16 @@ class IoServer {
return new static($component, $socket, $loop); return new static($component, $socket, $loop);
} }
/**
* Run the application by entering the event loop
*/
public function run() { public function run() {
$this->loop->run(); $this->loop->run();
} }
/**
* Triggered when a new connection is received from React
*/
public function handleConnect($conn) { public function handleConnect($conn) {
$conn->decor = new IoConnection($conn, $this); $conn->decor = new IoConnection($conn, $this);
@ -73,6 +86,11 @@ class IoServer {
$conn->on('error', $this->handlers['error']); $conn->on('error', $this->handlers['error']);
} }
/**
* Data has been received from React
* @param string
* @param React\Socket\Connection
*/
public function handleData($data, $conn) { public function handleData($data, $conn) {
try { try {
$this->app->onMessage($conn->decor, $data); $this->app->onMessage($conn->decor, $data);
@ -81,6 +99,10 @@ class IoServer {
} }
} }
/**
* A connection has been closed by React
* @param React\Socket\Connection
*/
public function handleEnd($conn) { public function handleEnd($conn) {
try { try {
$this->app->onClose($conn->decor); $this->app->onClose($conn->decor);
@ -89,6 +111,11 @@ class IoServer {
} }
} }
/**
* An error has occurred, let the listening application know
* @param Exception
* @param React\Socket\Connection
*/
public function handleError(\Exception $e, $conn) { public function handleError(\Exception $e, $conn) {
$this->app->onError($conn->decor, $e); $this->app->onError($conn->decor, $e);
} }

View File

@ -21,6 +21,10 @@ class RFC6455 implements VersionInterface {
*/ */
protected $_verifier; protected $_verifier;
/**
* A lookup of the valid close codes that can be sent in a frame
* @var array
*/
private $closeCodes = array(); private $closeCodes = array();
public function __construct() { public function __construct() {

View File

@ -54,8 +54,6 @@ class WsServer implements MessageComponentInterface {
* @param Ratchet\MessageComponentInterface Your application to run with WebSockets * @param Ratchet\MessageComponentInterface Your application to run with WebSockets
*/ */
public function __construct(MessageComponentInterface $component) { public function __construct(MessageComponentInterface $component) {
//mb_internal_encoding('UTF-8');
$this->reqParser = new HttpRequestParser; $this->reqParser = new HttpRequestParser;
$this->versioner = new VersionManager; $this->versioner = new VersionManager;

View File

@ -1,4 +1,3 @@
{ {
"options": {"failByDrop": false} "options": {"failByDrop": false}
, "outdir": "../reports/ab" , "outdir": "../reports/ab"