throw new InvalidSocketException(array($this, gettype($socket), $errno, $errstr), BaseListener::EXCEPTION_INVALID_SOCKET);
} // END - if
+ // Now, we want non-blocking mode
+ $this->debugOutput('LISTENER: Setting non-blocking mode.');
+ if (!stream_set_blocking($socket, false)) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, gettype($socket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
// Remember the socket in our class
$this->setSocketResource($socket);
* "Listens" for incoming network packages
*
* @return void
- * @todo 0% done
+ * @todo ~50% done
*/
public function doListen() {
- $this->partialStub('Need to implement this method.');
+ // Read a package and determine the client
+ $pkt = trim(stream_socket_recvfrom($this->getSocketResource(), 1500, 0, $peer));
+
+ // Zero sized packages/peer names are usual in non-blocking mode
+ if ((empty($pkt)) || (trim($peer) == '')) {
+ // Skip here
+ return;
+ } // END - if
+
+ // Debug only
+ $this->debugOutput('LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer);
}
}