]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/listener/tcp/class_TcpListener.php
Introduced getListIterator() to all lists implementing Listable
[hub.git] / application / hub / main / listener / tcp / class_TcpListener.php
index a040861db22e499feda5232598d55dc67441ea45..005831ffc2f9c5e4676e3805fa910d765aba8cf6 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @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
  *
@@ -92,9 +92,11 @@ class TcpListener extends BaseListener implements Listenable {
                        throw new InvalidSocketException(array($this, gettype($mainSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
-               // Now, we want non-blocking mode
-               $this->debugOutput('LISTENER: Setting non-blocking mode.');
-               if (!socket_set_nonblock($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());
+               if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
 
@@ -108,11 +110,9 @@ class TcpListener extends BaseListener implements Listenable {
                        throw new InvalidSocketException(array($this, gettype($mainSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // 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('LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort());
-               if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) {
+               // Start listen for connections
+               $this->debugOutput('LISTENER: Listening for connections.');
+               if (!socket_listen($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
 
@@ -126,9 +126,9 @@ class TcpListener extends BaseListener implements Listenable {
                        throw new InvalidSocketException(array($this, gettype($mainSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
-               // Start listen for connections
-               $this->debugOutput('LISTENER: Listening for connections.');
-               if (!socket_listen($mainSocket)) {
+               // Now, we want non-blocking mode
+               $this->debugOutput('LISTENER: Setting non-blocking mode.');
+               if (!socket_set_nonblock($mainSocket)) {
                        // Get socket error code for verification
                        $socketError = socket_last_error($mainSocket);
 
@@ -202,6 +202,7 @@ class TcpListener extends BaseListener implements Listenable {
                if (in_array($this->getSocketResource(), $readers)) {
                        // Then accept it
                        $newSocket = socket_accept($this->getSocketResource());
+                       //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: newSocket=' . $newSocket);
 
                        // We want non-blocking here, too
                        if (!socket_set_nonblock($newSocket)) {
@@ -234,7 +235,8 @@ class TcpListener extends BaseListener implements Listenable {
                // Handle it here, if not main socket
                if ($currentSocket != $this->getSocketResource()) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
-                       $this->getPackageInstance()->processResourcePackage($currentSocket);
+                       //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: currentSocket=' . $currentSocket);
+                       $this->getPackageInstance()->processResourceRawData($currentSocket);
                } // END - if
 
                // Advance to next entry. This should be the last line
@@ -247,8 +249,8 @@ class TcpListener extends BaseListener implements Listenable {
         * @param       $packageData    Raw package data
         * @return      $accepts                Wether this listener does accept
         */
-       function ifListenerAcceptsPackageData (array $packageData) {
-               $this->partialStub('This call should not happen. Please report.');
+       public function ifListenerAcceptsPackageData (array $packageData) {
+               $this->partialStub('This call should not happen. Please report it.');
        }
 }