]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/listener/udp/class_UdpListener.php
Refactured handling of socket errors, old code is commeted out and will be removed...
[hub.git] / application / hub / main / listener / udp / class_UdpListener.php
index bae286155e2324c98386b98aa75b22bac2d6c983..5fac3aa4f882ecf4581902b98c7771d6c1433dda 100644 (file)
@@ -72,6 +72,9 @@ class UdpListener extends BaseListener implements Listenable {
                // 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)) {
+                       // Handle the socket error with a faked recipientData array
+                       $this->handleSocketError($mainSocket, array('0.0.0.0', '0'));
+                       /*
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
 
@@ -82,7 +85,8 @@ class UdpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, gettype($mainSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       */
                } // END - if
 
                // "Bind" the socket to the given address, on given port so this means
@@ -90,6 +94,9 @@ class UdpListener extends BaseListener implements Listenable {
                // send/recv data, disconnect, etc..
                $this->debugOutput('UDP-LISTENER: 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'));
+                       /*
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
 
@@ -100,12 +107,16 @@ class UdpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, gettype($mainSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       */
                } // END - if
 
                // Now, we want non-blocking mode
                $this->debugOutput('UDP-LISTENER: 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'));
+                       /*
                        // Get socket error code for verification
                        $socketError = socket_last_error($socket);
 
@@ -116,7 +127,8 @@ class UdpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, gettype($mainSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       */
                } // END - if
 
                // Remember the socket in our class