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)) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($mainSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($mainSocket);
+
+ // And throw again
+ 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())) {
// Get socket error code for verification
$socketError = socket_last_error($mainSocket);
} // END - if
// 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);
* "Listens" for incoming network packages
*
* @return void
- * @todo 0% done
*/
public function doListen () {
// Get all readers
// Then accept it
$newSocket = socket_accept($this->getSocketResource());
- // Debug message
- $this->debugOutput('LISTENER: Adding new client: ' . $newSocket);
+ // We want non-blocking here, too
+ if (!socket_set_nonblock($newSocket)) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($newSocket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($newSocket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, gettype($newSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
// Add it to the clients
$this->getPoolInstance()->addClient($newSocket);
// Get the current value
$current = $this->getIteratorInstance()->current();
- // Handle it here
- $this->getPackageInstance()->processResourcePackage($current);
+ // Handle it here, if not main socket
+ if ($current !== $this->getSocketResource()) {
+ // ... or else it will raise warnings like 'Transport endpoint is not connected'
+ $this->getPackageInstance()->processResourcePackage($current);
+ } // END - if
// Advance to next entry. This should be the last line
$this->getIteratorInstance()->next();