application/hub/main/handler/network/.htaccess -text svneol=unset#text/plain
application/hub/main/handler/network/class_ svneol=native#text/plain
application/hub/main/handler/network/class_BaseNetworkPackageHandler.php svneol=native#text/plain
+application/hub/main/handler/network/class_BaseRawDataHandler.php svneol=native#text/plain
application/hub/main/handler/network/tcp/.htaccess -text svneol=unset#text/plain
application/hub/main/handler/network/tcp/class_ svneol=native#text/plain
application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php svneol=native#text/plain
+application/hub/main/handler/network/tcp/class_TcpRawDataHandler.php svneol=native#text/plain
application/hub/main/handler/network/udp/.htaccess -text svneol=unset#text/plain
application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php svneol=native#text/plain
+application/hub/main/handler/network/udp/class_UdpRawDataHandler.php svneol=native#text/plain
application/hub/main/handler/tasks/.htaccess -text svneol=unset#text/plain
application/hub/main/handler/tasks/class_TaskHandler.php svneol=native#text/plain
application/hub/main/helper/.htaccess -text svneol=unset#text/plain
// CFG: NETWORK-LISTEN-ITERATOR-CLASS
$cfg->setConfigEntry('network_listen_iterator_class', 'NetworkListenIterator');
-// CFG: NETWORK-PACKAGE-HANDLER-CLASS
-$cfg->setConfigEntry('tcp_network_package_handler_class', 'TcpNetworkPackageHandler');
+// CFG: TCP-RAW-DATA-HANDLER-CLASS
+$cfg->setConfigEntry('tcp_raw_data_handler_class', 'TcpRawDataHandler');
+
+// CFG: UDP-RAW-DATA-HANDLER-CLASS
+$cfg->setConfigEntry('udp_raw_data_handler_class', 'UdpRawDataHandler');
// CFG: SHUTDOWN-LISTENER-POOL-VISITOR-CLASS
$cfg->setConfigEntry('shutdown_listener_pool_visitor_class', 'ShutdownListenerPoolVisitor');
<?php
-/**
- * A general Handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class BaseNetworkPackageHandler extends BaseHandler {
- // Error codes:
- // - Socket raw data stream errors
- const SOCKET_ERROR_UNKNOWN = 'unknown_error'; // Unknown error (should not happen)
- const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint'; // Transport endpoint has closed
- const SOCKET_ERROR_EMPTY_DATA = 'empty_data'; // Other peer has sent nothing
- const SOCKET_ERROR_INVALID_BASE64_MODULO = 'base64_modulo'; // Length is not modulo 4
- const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message'; // Raw data is not Base64-encoded
- const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; // Unhandled raw data (not bad)
-
- // - Package errors
- const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
- const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
- const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
- const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
- const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
-
- // Package data
- const PACKAGE_DECODED_DATA = 'decoded_data';
- const PACKAGE_ERROR_CODE = 'error_code';
-
- /**
- * Error code from socket
- */
- private $errorCode = -1;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Set error code to 'unknown'
- $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
-
- // Get an input stream instance
- $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
-
- // Set it in this network-package handler
- $this->setInputStreamInstance($streamInstance);
-
- // Init stacker instance for processed raw data
- $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
-
- // Remember this in this package handler
- $this->setStackerInstance($stackerInstance);
-
- // Init stacker
- $this->initStacker();
- }
-
- /**
- * Initializes the stacker for raw data
- *
- * @return void
- */
- protected function initStacker () {
- $this->getStackerInstance()->initStacker('raw_data');
- }
-
- /**
- * Adds given decoded data to the raw data stacker
- *
- * @param $decodedData Decoded data from the socket resource
- * @return void
- */
- protected function addDecodedDataToStacker ($decodedData) {
- /*
- * Add the deocoded data and error code to the stacker so other classes
- * (e.g. NetworkPackage) can "pop" it from the stacker.
- */
- $this->getStackerInstance()->pushNamed('raw_data', array(
- self::PACKAGE_DECODED_DATA => $decodedData,
- self::PACKAGE_ERROR_CODE => $this->getErrorCode()
- ));
- }
-
- /**
- * Checks wether the 'recipient' field matches our own address:port
- * combination.
- *
- * @param $packageData Raw package data
- * @return $matches Wether it matches
- * @todo This method will be moved to a better place
- */
- protected function ifRecipientMatchesOwnAddress (array $packageData) {
- // Construct own address first
- $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
-
- // Does it match?
- // @TODO Numeric or alpha-numeric index?
- $matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
-
- // Return result
- return $matches;
- }
-
- /**
- * Setter for error code
- *
- * @param $errorCode The error code we shall set
- * @return void
- */
- protected final function setErrorCode ($errorCode) {
- $this->errorCode = $errorCode;
- }
-
- /**
- * Getter for error code
- *
- * @return $errorCode The error code
- */
- public final function getErrorCode () {
- return $this->errorCode;
- }
-}
-
-// [EOF]
+// @DEPRECATED
?>
--- /dev/null
+<?php
+/**
+ * A general Handler for raw data from sockets
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class BaseRawDataHandler extends BaseHandler {
+ // Error codes:
+ // - Socket raw data stream errors
+ const SOCKET_ERROR_UNKNOWN = 'unknown_error'; // Unknown error (should not happen)
+ const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint'; // Transport endpoint has closed
+ const SOCKET_ERROR_EMPTY_DATA = 'empty_data'; // Other peer has sent nothing
+ const SOCKET_ERROR_INVALID_BASE64_MODULO = 'base64_modulo'; // Length is not modulo 4
+ const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message'; // Raw data is not Base64-encoded
+ const SOCKET_ERROR_UNHANDLED = 'unhandled_package'; // Unhandled raw data (not bad)
+
+ // - Package errors
+ const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
+ const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
+ const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
+ const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
+ const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
+
+ // Package data
+ const PACKAGE_DECODED_DATA = 'decoded_data';
+ const PACKAGE_ERROR_CODE = 'error_code';
+
+ /**
+ * Error code from socket
+ */
+ private $errorCode = -1;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Set error code to 'unknown'
+ $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
+
+ // Get an input stream instance
+ $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
+
+ // Set it in this network-package handler
+ $this->setInputStreamInstance($streamInstance);
+
+ // Init stacker instance for processed raw data
+ $stackerInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
+
+ // Remember this in this package handler
+ $this->setStackerInstance($stackerInstance);
+
+ // Init stacker
+ $this->initStacker();
+ }
+
+ /**
+ * Initializes the stacker for raw data
+ *
+ * @return void
+ */
+ protected function initStacker () {
+ $this->getStackerInstance()->initStacker('raw_data');
+ }
+
+ /**
+ * Adds given decoded data to the raw data stacker
+ *
+ * @param $decodedData Decoded data from the socket resource
+ * @return void
+ */
+ protected function addDecodedDataToStacker ($decodedData) {
+ /*
+ * Add the deocoded data and error code to the stacker so other classes
+ * (e.g. NetworkPackage) can "pop" it from the stacker.
+ */
+ $this->getStackerInstance()->pushNamed('raw_data', array(
+ self::PACKAGE_DECODED_DATA => $decodedData,
+ self::PACKAGE_ERROR_CODE => $this->getErrorCode()
+ ));
+ }
+
+ /**
+ * Checks wether the 'recipient' field matches our own address:port
+ * combination.
+ *
+ * @param $packageData Raw package data
+ * @return $matches Wether it matches
+ * @todo This method will be moved to a better place
+ */
+ protected function ifRecipientMatchesOwnAddress (array $packageData) {
+ // Construct own address first
+ $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
+
+ // Does it match?
+ // @TODO Numeric or alpha-numeric index?
+ $matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
+
+ // Return result
+ return $matches;
+ }
+
+ /**
+ * Setter for error code
+ *
+ * @param $errorCode The error code we shall set
+ * @return void
+ */
+ protected final function setErrorCode ($errorCode) {
+ $this->errorCode = $errorCode;
+ }
+
+ /**
+ * Getter for error code
+ *
+ * @return $errorCode The error code
+ */
+ public final function getErrorCode () {
+ return $this->errorCode;
+ }
+}
+
+// [EOF]
+?>
<?php
-/**
- * A TCP network package handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('tcp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function createTcpNetworkPackageHandler () {
- // Get new instance
- $handlerInstance = new TcpNetworkPackageHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
- *
- * @param $resource A valid resource identifier
- * @return void
- */
- public function processRawDataFromResource ($resource) {
- // Check the resource
- if (!is_resource($resource)) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Reset error code to unhandled
- $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
-
- // Init variables
- $decodedData = false;
-
- // Debug message
- //* NOISY-DEBUG: */ $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
-
- /*
- * Read the raw data from socket. If you change PHP_BINARY_READ to
- * PHP_NORMAL_READ, this line will endless block. We only have
- * simultanous threads and no real threads.
- */
- $rawData = socket_read($resource, $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
-
- // Debug output of read data length
- //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: rawData[]=' . strlen($rawData));
-
- // Is it valid?
- if (($rawData === false) || (socket_last_error($resource) > 0)) {
- // Network error or connection lost
- $this->setErrorCode(socket_last_error($resource));
- } elseif (empty($rawData)) {
- // The peer did send nothing to us
- $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
- } else {
- /*
- * Low-level checks of the raw data went all fine, we can now
- * decode the raw data. This may still fail because of invalid
- * encoded data.
- */
- $decodedData = $this->getInputStreamInstance()->streamData($rawData);
- }
-
- // Add the (maybe above decoded) data to the stacker
- $this->addDecodedDataToStacker($decodedData);
- }
-}
-
-// [EOF]
+// @DEPRECATED
?>
--- /dev/null
+<?php
+/**
+ * A TCP raw data handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('tcp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public static final function createTcpRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new TcpRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ */
+ public function processRawDataFromResource ($resource) {
+ // Check the resource
+ if (!is_resource($resource)) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Reset error code to unhandled
+ $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
+
+ // Init variables
+ $decodedData = false;
+
+ // Debug message
+ //* NOISY-DEBUG: */ $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
+
+ /*
+ * Read the raw data from socket. If you change PHP_BINARY_READ to
+ * PHP_NORMAL_READ, this line will endless block. We only have
+ * simultanous threads and no real threads.
+ */
+ $rawData = socket_read($resource, $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
+
+ // Debug output of read data length
+ //* NOISY-DEBUG: */ $this->debugOutput('TCP-HANDLER: rawData[]=' . strlen($rawData));
+
+ // Is it valid?
+ if (($rawData === false) || (socket_last_error($resource) > 0)) {
+ // Network error or connection lost
+ $this->setErrorCode(socket_last_error($resource));
+ } elseif (empty($rawData)) {
+ // The peer did send nothing to us
+ $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
+ } else {
+ /*
+ * Low-level checks of the raw data went all fine, we can now
+ * decode the raw data. This may still fail because of invalid
+ * encoded data.
+ */
+ $decodedData = $this->getInputStreamInstance()->streamData($rawData);
+ }
+
+ // Add the (maybe above decoded) data to the stacker
+ $this->addDecodedDataToStacker($decodedData);
+ }
+}
+
+// [EOF]
+?>
<?php
-/**
- * A UDP network package handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('udp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function createUdpNetworkPackageHandler () {
- // Get new instance
- $handlerInstance = new UdpNetworkPackageHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
- *
- * @param $resource A valid resource identifier
- * @return void
- * @throws InvalidResourceException If the given resource is invalid
- * @todo 0%
- */
- public function processRawDataFromResource ($resource) {
- // Check the resource
- if (!is_resource($resource)) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Implement processing here
- $this->partialStub('Please implement this method. resource=' . $resource);
- }
-}
-
-// [EOF]
+// @DEPRECATED
?>
--- /dev/null
+<?php
+/**
+ * A UDP raw data handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('udp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public static final function createUdpRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new UdpRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processRawDataFromResource ($resource) {
+ // Check the resource
+ if (!is_resource($resource)) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Implement processing here
+ $this->partialStub('Please implement this method. resource=' . $resource);
+ }
+}
+
+// [EOF]
+?>
*/
public function accept (Visitor $visitorInstance) {
// Debug message
- //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START');
+ //* DEBUG: */ $this->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START');
// Visit this listener
$visitorInstance->visitListener($this);
} // END - if
// Debug message
- //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
+ //* DEBUG: */ $this->debugOutput(strtoupper($this->getProtocol()) . '-LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
}
/**
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set the protocol to TCP
+ $this->setProtocol('tcp');
}
/**
// Set the application instance
$listenerInstance->setNodeInstance($nodeInstance);
- // Set the protocol to TCP
- $listenerInstance->setProtocol('tcp');
-
// Return the prepared instance
return $listenerInstance;
}
// "Bind" the socket to the given address, on given port so this means
// that all connections on this port are now our resposibility to
// send/recv data, disconnect, etc..
- $this->debugOutput('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+ $this->debugOutput('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
// Get socket error code for verification
$socketError = socket_last_error($mainSocket);
} // END - if
// Start listen for connections
- $this->debugOutput('LISTENER: Listening for connections.');
+ $this->debugOutput('TCP-LISTENER: Listening for connections.');
if (!socket_listen($mainSocket)) {
// Get socket error code for verification
$socketError = socket_last_error($mainSocket);
} // END - if
// Now, we want non-blocking mode
- $this->debugOutput('LISTENER: Setting non-blocking mode.');
+ $this->debugOutput('TCP-LISTENER: Setting non-blocking mode.');
if (!socket_set_nonblock($mainSocket)) {
// Get socket error code for verification
$socketError = socket_last_error($mainSocket);
$this->setIteratorInstance($iteratorInstance);
// Initialize the network package handler
- $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_network_package_handler_class');
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('tcp_raw_data_handler_class');
// Set it in this class
$this->setHandlerInstance($handlerInstance);
// Output message
- $this->debugOutput('LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+ $this->debugOutput('TCP-LISTENER: TCP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
}
/**
if (in_array($this->getSocketResource(), $readers)) {
// Then accept it
$newSocket = socket_accept($this->getSocketResource());
- //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: newSocket=' . $newSocket);
+ //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: newSocket=' . $newSocket);
// We want non-blocking here, too
if (!socket_set_nonblock($newSocket)) {
// Handle it here, if not main socket
if ($currentSocket != $this->getSocketResource()) {
// ... or else it will raise warnings like 'Transport endpoint is not connected'
- //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: currentSocket=' . $currentSocket);
+ //* NOISY-DEBUG: */ $this->debugOutput('TCP-LISTENER: currentSocket=' . $currentSocket);
$this->getHandlerInstance()->processRawDataFromResource($currentSocket);
} // END - if
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set the protocol to UDP
+ $this->setProtocol('udp');
}
/**
// Set the application instance
$listenerInstance->setNodeInstance($nodeInstance);
- // Set the protocol to UDP
- $listenerInstance->setProtocol('udp');
-
// Return the prepared instance
return $listenerInstance;
}
} // END - if
// Set the option to reuse the port
- $this->debugOutput('LISTENER: Setting re-use address option.');
+ $this->debugOutput('UDP-LISTENER: Setting re-use address option.');
if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
// Get socket error code for verification
$socketError = socket_last_error($mainSocket);
// "Bind" the socket to the given address, on given port so this means
// that all connections on this port are now our resposibility to
// send/recv data, disconnect, etc..
- $this->debugOutput('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+ $this->debugOutput('UDP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
// Get socket error code for verification
$socketError = socket_last_error($mainSocket);
} // END - if
// Now, we want non-blocking mode
- $this->debugOutput('LISTENER: Setting non-blocking mode.');
+ $this->debugOutput('UDP-LISTENER: Setting non-blocking mode.');
if (!socket_set_nonblock($mainSocket)) {
// Get socket error code for verification
$socketError = socket_last_error($socket);
// Remember the socket in our class
$this->registerServerSocketResource($mainSocket);
+ // Initialize the network package handler
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('udp_raw_data_handler_class');
+
+ // Set it in this class
+ $this->setHandlerInstance($handlerInstance);
+
// Output message
- $this->debugOutput('LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+ $this->debugOutput('UDP-LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
}
/**
return;
} elseif ($lastError > 0) {
// Other error detected
- $this->debugOutput('LISTENER: Error detected: ' . socket_strerror($lastError));
+ $this->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError));
// Skip further processing
return;
} // END - if
// Debug only
- $this->debugOutput('LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
+ $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port);
}
/**
if (($errorCode == 134) || ($errorCode == 107)) {
// Transport endpoint not connected, should be handled else!
// @TODO On some systems it is 134, on some 107?
- $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
+ $errorCode = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
} elseif (is_int($errorCode)) {
// Unhandled error code detected, so first debug it because we may want to handle it like the others
$this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
// Change it only in this class
- $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
+ $errorCode = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
} // END - if
// Create a state instance based on $errorCode. This factory does the hard work for us
// Can it be validated?
if ((strlen($data) % 4) != 0) {
// Length modulo 4 must be zero, else it is an invalid Base64 message
- $this->getHandlerInstance()->setErrorCode(BaseNetworkPackageHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
+ $this->getHandlerInstance()->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
$data = false;
} elseif (!$this->isBase64Encoded($data)) {
// Is not a valid Base64-encoded message
- $this->getHandlerInstance()->setErrorCode(BaseNetworkPackageHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
+ $this->getHandlerInstance()->setErrorCode(BaseRawDataHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
$data = false;
} else {
// Decode the data with BASE64-encoding