$socketInstance = new SocketContainer();
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s,packageInstance->socketType=%s', $socketResource, $socketProtocol, $packageInstance->getSocketType()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol));
// Set protocol
$socketInstance->setSocketProtocol($socketProtocol);
* @param $bindPort Optional port to bind to
* @return $result Result from binding socket
* @throws InvalidSocketException If socket is invalid
+ * @throws NullPointerException If listener instance is not given
*/
public function bindSocketToFile () {
- // Trace message
+ // Should be valid socket
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: CALLED!', strtoupper($this->getSocketProtocol())));
+ if (!$this->isValidSocket()) {
+ // Throw exception
+ throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
+ } elseif (is_null($this->getSocketFile())) {
+ // Throw exception
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ }
+
+ // Try to bind it to
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Binding socket to file %s ...', strtoupper($this->getSocketProtocol()), $this->getSocketFile()));
+ $result = socket_bind($this->getSocketResource(), $this->getSocketFile());
+
+ // Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+ return $result;
}
/**
// Get bind address and port
$address = $this->getListenerInstance()->getListenAddress();
- $port = $this->getListenerInstance()->getListenAddress();
+ $port = $this->getListenerInstance()->getListenPort();
// Try to bind it to
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Binding socket to %s:%d ...', strtoupper($this->getSocketProtocol()), $address, $port));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Binding socket to address %s:%d ...', strtoupper($this->getSocketProtocol()), $address, $port));
$result = socket_bind($this->getSocketResource(), $address, $port);
// Return result