]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/listener/udp/class_UdpListener.php
Updated 'core'.
[hub.git] / application / hub / main / listener / udp / class_UdpListener.php
index 5a26b7f3d44b0680f524e13ca848e4e95ac55646..a9c9d51dea265b32d3b857f5a8f83397692e9611 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * An UDP connection listener
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.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
@@ -32,7 +32,7 @@ class UdpListener extends BaseListener implements Listenable {
                parent::__construct(__CLASS__);
 
                // Set the protocol to UDP
-               $this->setProtocol('udp');
+               $this->setProtocolName('udp');
        }
 
        /**
@@ -69,11 +69,15 @@ class UdpListener extends BaseListener implements Listenable {
                        throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
-               // Set the option to reuse the port
-               $this->debugOutput('UDP-LISTENER: Setting re-use address option.');
-               if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
+               /*
+                * "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..
+                */
+               self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
+               if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
                        // Handle the socket error with a faked recipientData array
-                       $this->handleSocketError($mainSocket, array('0.0.0.0', '0'));
+                       $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
                        /*
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
@@ -89,16 +93,14 @@ class UdpListener extends BaseListener implements Listenable {
                        */
                } // END - if
 
-               // "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('UDP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
-               if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
+               // Now, we want non-blocking mode
+               self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting non-blocking mode.');
+               if (!socket_set_nonblock($mainSocket)) {
                        // Handle the socket error with a faked recipientData array
-                       $this->handleSocketError($mainSocket, array('0.0.0.0', '0'));
+                       $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
                        /*
                        // Get socket error code for verification
-                       $socketError = socket_last_error($mainSocket);
+                       $socketError = socket_last_error($socket);
 
                        // Get error message
                        $errorMessage = socket_strerror($socketError);
@@ -111,14 +113,14 @@ class UdpListener extends BaseListener implements Listenable {
                        */
                } // END - if
 
-               // Now, we want non-blocking mode
-               $this->debugOutput('UDP-LISTENER: Setting non-blocking mode.');
-               if (!socket_set_nonblock($mainSocket)) {
+               // Set the option to reuse the port
+               self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Setting re-use address option.');
+               if (!socket_set_option($mainSocket, SOL_SOCKET, SO_REUSEADDR, 1)) {
                        // Handle the socket error with a faked recipientData array
-                       $this->handleSocketError($mainSocket, array('0.0.0.0', '0'));
+                       $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
                        /*
                        // Get socket error code for verification
-                       $socketError = socket_last_error($socket);
+                       $socketError = socket_last_error($mainSocket);
 
                        // Get error message
                        $errorMessage = socket_strerror($socketError);
@@ -141,7 +143,7 @@ class UdpListener extends BaseListener implements Listenable {
                $this->setHandlerInstance($handlerInstance);
 
                // Output message
-               $this->debugOutput('UDP-LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
+               self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
        }
 
        /**
@@ -171,7 +173,7 @@ class UdpListener extends BaseListener implements Listenable {
                        return;
                } elseif ($lastError > 0) {
                        // Other error detected
-                       $this->debugOutput('UDP-LISTENER: Error detected: ' . socket_strerror($lastError));
+                       self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Error detected: ' . socket_strerror($lastError));
 
                        // Skip further processing
                        return;
@@ -181,7 +183,7 @@ class UdpListener extends BaseListener implements Listenable {
                } // END - if
 
                // Debug only
-               $this->debugOutput('UDP-LISTENER: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port);
+               self::createDebugInstance(__CLASS__)->debugOutput('UDP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: Handling UDP package with size ' . strlen($rawData) . ' from peer ' . $peer . ':' . $port);
        }
 
        /**