cvs: pear /Net_Server Server.php /Net_Server/Server Driver.php Handler.php /Net_Server/Server/Driver Sequential.php
| From: | Stephan Schmidt | Date: | Sun, 04 Jan 2004 15:43:51 +0000 |
| Subject: | cvs: pear /Net_Server Server.php /Net_Server/Server Driver.php Handler.php /Net_Server/Server/Driver Sequential.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-15345@lists.php.net to get a copy of this message | ||
schst Sun Jan 4 10:43:51 2004 EDT
Modified files:
/pear/Net_Server Server.php
/pear/Net_Server/Server Driver.php Handler.php
/pear/Net_Server/Server/Driver Sequential.php
Log:
added some PHPDoc comments
Index: pear/Net_Server/Server.php diff -u pear/Net_Server/Server.php:1.8 pear/Net_Server/Server.php:1.9 --- pear/Net_Server/Server.php:1.8 Fri Jan 2 11:40:48 2004 +++ pear/Net_Server/Server.php Sun Jan 4 10:43:49 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Server.php,v 1.8 2004/01/02 16:40:48 schst Exp $ +// $Id: Server.php,v 1.9 2004/01/04 15:43:49 schst Exp $ /** * PHP socket server base class @@ -81,17 +81,22 @@ class Net_Server { /** - * create a new server + * Create a new server * * Currently two types of servers are supported: * - 'sequential', creates a server where one process handles all request from all clients sequentially * - 'fork', creates a server where a new process is forked for each client that connects to the server. This only works on *NIX * + * This method will either return a server object or a PEAR error if the server + * type does not exist. + * * @access public * @static * @param string $type type of the server * @param string $host hostname * @param integer $port port + * @return object Net_Server_Driver server object of the desired type + * @throws object PEAR_Error */ function &create($type, $host, $port) { Index: pear/Net_Server/Server/Driver.php diff -u pear/Net_Server/Server/Driver.php:1.3 pear/Net_Server/Server/Driver.php:1.4 --- pear/Net_Server/Server/Driver.php:1.3 Fri Jan 2 11:40:49 2004 +++ pear/Net_Server/Server/Driver.php Sun Jan 4 10:43:50 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Driver.php,v 1.3 2004/01/02 16:40:49 schst Exp $ +// $Id: Driver.php,v 1.4 2004/01/04 15:43:50 schst Exp $ /** * Base class for all drivers @@ -29,6 +29,9 @@ /** * Base class for all drivers * + * This class provides methods, can be used by all + * server implementations. + * * @category Networking * @package Net_Server * @author Stephan Schmidt <schst@php.net> @@ -121,13 +124,14 @@ /** * constructor _MUST_ not be called directly * - * instead please use the Net_Server::create() method + * Please use the Net_Server::create() method instead * that can be called statically and will return a server - * of the specified type + * of the specified type. * * @access private * @param string $domain domain to bind to * @param integer $port port to listen to + * @see Net_Server::create() */ function Net_Server_Driver($domain = "localhost", $port = 10000) { @@ -139,6 +143,8 @@ /** * destructor + * + * Will shutdown the server if the script is abborted. * * @access private */ @@ -148,10 +154,15 @@ } /** - * set debug mode + * Set debug mode * + * Debug information can either be written + * to a logfile or standard out (= the console). + * + * To disable debugging, pass false as first parameter. + * * @access public - * @param mixed $debug [text|htmlfalse] + * @param mixed $debug [text|html|false] * @param string $dest destination of debug message (stdout to output or filename if log should be written) */ function setDebugMode($debug, $dest = "stdout") @@ -166,7 +177,6 @@ $this->_debugDest = $dest; } - /** * read from a socket * @@ -210,9 +220,14 @@ /** * send a debug message + * + * Debug messages will be either sent to standard out + * or written to a logfile, depending on debug settings. * - * @access private + * @access public * @param string $msg message to debug + * @see setDebugMode() + * @todo remove underscore from method name as the method now is public. */ function _sendDebugMessage($msg) { if (!$this->_debug) { @@ -241,10 +256,18 @@ } /** - * register a callback object, that is used to handle all events + * register a callback object + * + * The callback object is the actual server, + * that contains the logic to process the events + * triggered by the driver class. + * + * The best way to create a callback object is to + * extend the Net_Server_Handler class. * * @access public * @param object $object callback object + * @see Net_Server_Handler */ function setCallbackObject(&$object) { Index: pear/Net_Server/Server/Handler.php diff -u pear/Net_Server/Server/Handler.php:1.4 pear/Net_Server/Server/Handler.php:1.5 --- pear/Net_Server/Server/Handler.php:1.4 Fri Jan 2 11:40:49 2004 +++ pear/Net_Server/Server/Handler.php Sun Jan 4 10:43:50 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Handler.php,v 1.4 2004/01/02 16:40:49 schst Exp $ +// $Id: Handler.php,v 1.5 2004/01/04 15:43:50 schst Exp $ /** * Base class for all handlers @@ -37,7 +37,8 @@ /** * reference to the server object, used to send data to the client - * @var object + * @var object + * @access private */ var $_server; @@ -47,7 +48,8 @@ * This is done automatically when the handler is passed over to the server * * @access public - * @param object Net_Server_* object + * @param object Net_Server_Driver a reference to the driver object, needed to send data + * to the clients */ function setServerReference( &$server ) { @@ -58,6 +60,9 @@ * onStart handler * * This handler is called, when the server starts. + * + * Implement this method to load configuration files. + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork @@ -72,6 +77,10 @@ * onShutdown handler * * This handler is called, when the server is stopped. + * + * Implement gabage collection in this method, if your server + * created some temporary files. + * * Available in: * - Net_Server_Sequential * @@ -84,7 +93,11 @@ /** * onConnect handler * - * This handler is called, when a new client connects + * This handler is called, when a new client connects. It is + * called even before the client sent data to the server. + * + * You could use this method to send a welcome message to the client. + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork @@ -99,7 +112,11 @@ /** * onConnectionRefused handler * - * This handler is called, when a new client tries to connect but is not allowed to + * This handler is called, when a new client tries to connect but is not allowed to. + * + * This could happen, if max clients is used. This method currently only may be + * implemented in Net_Server_Sequential. Will be available in other drivers soon. + * * Available in: * - Net_Server_Sequential * @@ -113,7 +130,10 @@ /** * onClose handler * - * This handler is called, when a client disconnects from the server + * This handler is called, when a client disconnects from the server. + * + * You could implement some garbage collection in this method. + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork @@ -129,6 +149,7 @@ * onReceiveData handler * * This handler is called, when a client sends data to the server + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork Index: pear/Net_Server/Server/Driver/Sequential.php diff -u pear/Net_Server/Server/Driver/Sequential.php:1.3 pear/Net_Server/Server/Driver/Sequential.php:1.4 --- pear/Net_Server/Server/Driver/Sequential.php:1.3 Fri Jan 2 11:40:50 2004 +++ pear/Net_Server/Server/Driver/Sequential.php Sun Jan 4 10:43:51 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Sequential.php,v 1.3 2004/01/02 16:40:50 schst Exp $ +// $Id: Sequential.php,v 1.4 2004/01/04 15:43:51 schst Exp $ /** * Sequential server class. @@ -181,7 +181,7 @@ /** * accept a new connection * - * @access public + * @access private * @param resource &$socket socket that received the new connection * @return int $clientID internal ID of the client */
Index: pear/Net_Server/Server.php diff -u pear/Net_Server/Server.php:1.8 pear/Net_Server/Server.php:1.9 --- pear/Net_Server/Server.php:1.8 Fri Jan 2 11:40:48 2004 +++ pear/Net_Server/Server.php Sun Jan 4 10:43:49 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Server.php,v 1.8 2004/01/02 16:40:48 schst Exp $ +// $Id: Server.php,v 1.9 2004/01/04 15:43:49 schst Exp $ /** * PHP socket server base class @@ -81,17 +81,22 @@ class Net_Server { /** - * create a new server + * Create a new server * * Currently two types of servers are supported: * - 'sequential', creates a server where one process handles all request from all clients sequentially * - 'fork', creates a server where a new process is forked for each client that connects to the server. This only works on *NIX * + * This method will either return a server object or a PEAR error if the server + * type does not exist. + * * @access public * @static * @param string $type type of the server * @param string $host hostname * @param integer $port port + * @return object Net_Server_Driver server object of the desired type + * @throws object PEAR_Error */ function &create($type, $host, $port) { Index: pear/Net_Server/Server/Driver.php diff -u pear/Net_Server/Server/Driver.php:1.3 pear/Net_Server/Server/Driver.php:1.4 --- pear/Net_Server/Server/Driver.php:1.3 Fri Jan 2 11:40:49 2004 +++ pear/Net_Server/Server/Driver.php Sun Jan 4 10:43:50 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Driver.php,v 1.3 2004/01/02 16:40:49 schst Exp $ +// $Id: Driver.php,v 1.4 2004/01/04 15:43:50 schst Exp $ /** * Base class for all drivers @@ -29,6 +29,9 @@ /** * Base class for all drivers * + * This class provides methods, can be used by all + * server implementations. + * * @category Networking * @package Net_Server * @author Stephan Schmidt <schst@php.net> @@ -121,13 +124,14 @@ /** * constructor _MUST_ not be called directly * - * instead please use the Net_Server::create() method + * Please use the Net_Server::create() method instead * that can be called statically and will return a server - * of the specified type + * of the specified type. * * @access private * @param string $domain domain to bind to * @param integer $port port to listen to + * @see Net_Server::create() */ function Net_Server_Driver($domain = "localhost", $port = 10000) { @@ -139,6 +143,8 @@ /** * destructor + * + * Will shutdown the server if the script is abborted. * * @access private */ @@ -148,10 +154,15 @@ } /** - * set debug mode + * Set debug mode * + * Debug information can either be written + * to a logfile or standard out (= the console). + * + * To disable debugging, pass false as first parameter. + * * @access public - * @param mixed $debug [text|htmlfalse] + * @param mixed $debug [text|html|false] * @param string $dest destination of debug message (stdout to output or filename if log should be written) */ function setDebugMode($debug, $dest = "stdout") @@ -166,7 +177,6 @@ $this->_debugDest = $dest; } - /** * read from a socket * @@ -210,9 +220,14 @@ /** * send a debug message + * + * Debug messages will be either sent to standard out + * or written to a logfile, depending on debug settings. * - * @access private + * @access public * @param string $msg message to debug + * @see setDebugMode() + * @todo remove underscore from method name as the method now is public. */ function _sendDebugMessage($msg) { if (!$this->_debug) { @@ -241,10 +256,18 @@ } /** - * register a callback object, that is used to handle all events + * register a callback object + * + * The callback object is the actual server, + * that contains the logic to process the events + * triggered by the driver class. + * + * The best way to create a callback object is to + * extend the Net_Server_Handler class. * * @access public * @param object $object callback object + * @see Net_Server_Handler */ function setCallbackObject(&$object) { Index: pear/Net_Server/Server/Handler.php diff -u pear/Net_Server/Server/Handler.php:1.4 pear/Net_Server/Server/Handler.php:1.5 --- pear/Net_Server/Server/Handler.php:1.4 Fri Jan 2 11:40:49 2004 +++ pear/Net_Server/Server/Handler.php Sun Jan 4 10:43:50 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Handler.php,v 1.4 2004/01/02 16:40:49 schst Exp $ +// $Id: Handler.php,v 1.5 2004/01/04 15:43:50 schst Exp $ /** * Base class for all handlers @@ -37,7 +37,8 @@ /** * reference to the server object, used to send data to the client - * @var object + * @var object + * @access private */ var $_server; @@ -47,7 +48,8 @@ * This is done automatically when the handler is passed over to the server * * @access public - * @param object Net_Server_* object + * @param object Net_Server_Driver a reference to the driver object, needed to send data + * to the clients */ function setServerReference( &$server ) { @@ -58,6 +60,9 @@ * onStart handler * * This handler is called, when the server starts. + * + * Implement this method to load configuration files. + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork @@ -72,6 +77,10 @@ * onShutdown handler * * This handler is called, when the server is stopped. + * + * Implement gabage collection in this method, if your server + * created some temporary files. + * * Available in: * - Net_Server_Sequential * @@ -84,7 +93,11 @@ /** * onConnect handler * - * This handler is called, when a new client connects + * This handler is called, when a new client connects. It is + * called even before the client sent data to the server. + * + * You could use this method to send a welcome message to the client. + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork @@ -99,7 +112,11 @@ /** * onConnectionRefused handler * - * This handler is called, when a new client tries to connect but is not allowed to + * This handler is called, when a new client tries to connect but is not allowed to. + * + * This could happen, if max clients is used. This method currently only may be + * implemented in Net_Server_Sequential. Will be available in other drivers soon. + * * Available in: * - Net_Server_Sequential * @@ -113,7 +130,10 @@ /** * onClose handler * - * This handler is called, when a client disconnects from the server + * This handler is called, when a client disconnects from the server. + * + * You could implement some garbage collection in this method. + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork @@ -129,6 +149,7 @@ * onReceiveData handler * * This handler is called, when a client sends data to the server + * * Available in: * - Net_Server_Sequential * - Net_Server_Fork Index: pear/Net_Server/Server/Driver/Sequential.php diff -u pear/Net_Server/Server/Driver/Sequential.php:1.3 pear/Net_Server/Server/Driver/Sequential.php:1.4 --- pear/Net_Server/Server/Driver/Sequential.php:1.3 Fri Jan 2 11:40:50 2004 +++ pear/Net_Server/Server/Driver/Sequential.php Sun Jan 4 10:43:51 2004 @@ -16,7 +16,7 @@ // | Authors: Stephan Schmidt <schst@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Sequential.php,v 1.3 2004/01/02 16:40:50 schst Exp $ +// $Id: Sequential.php,v 1.4 2004/01/04 15:43:51 schst Exp $ /** * Sequential server class. @@ -181,7 +181,7 @@ /** * accept a new connection * - * @access public + * @access private * @param resource &$socket socket that received the new connection * @return int $clientID internal ID of the client */