From 982fd7223b89e94a644c5511821e0c2da14298cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 18 May 2012 22:07:10 +0000 Subject: [PATCH] Moved some socket initializations before socket_bind(), made setErrorCode() public --- .../network/class_BaseRawDataHandler.php | 2 +- .../main/listener/tcp/class_TcpListener.php | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 9a3cc31b8..1fc3cde76 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -165,7 +165,7 @@ class BaseRawDataHandler extends BaseHandler { * @param $errorCode The error code we shall set * @return void */ - protected final function setErrorCode ($errorCode) { + public final function setErrorCode ($errorCode) { $this->errorCode = $errorCode; } diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index 2f6a3224a..abab91478 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -100,11 +100,9 @@ class TcpListener 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('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort()); - if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) { + // Now, we want non-blocking mode + $this->debugOutput('TCP-LISTENER: Setting non-blocking mode.'); + if (!socket_set_nonblock($mainSocket)) { // Handle this socket error with a faked recipientData array $this->handleSocketError($mainSocket, array('0.0.0.0', '0')); /* @@ -122,9 +120,13 @@ class TcpListener extends BaseListener implements Listenable { */ } // END - if - // Start listen for connections - $this->debugOutput('TCP-LISTENER: Listening for connections.'); - if (!socket_listen($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('TCP-LISTENER: Binding to address ' . $this->getListenAddress() . ':' . $this->getListenPort()); + if (!socket_bind($mainSocket, $this->getListenAddress(), $this->getListenPort())) { // Handle this socket error with a faked recipientData array $this->handleSocketError($mainSocket, array('0.0.0.0', '0')); /* @@ -142,9 +144,9 @@ class TcpListener extends BaseListener implements Listenable { */ } // END - if - // Now, we want non-blocking mode - $this->debugOutput('TCP-LISTENER: Setting non-blocking mode.'); - if (!socket_set_nonblock($mainSocket)) { + // Start listen for connections + $this->debugOutput('TCP-LISTENER: Listening for connections.'); + if (!socket_listen($mainSocket)) { // Handle this socket error with a faked recipientData array $this->handleSocketError($mainSocket, array('0.0.0.0', '0')); /* -- 2.39.2