$helperInstance = $infoInstance->getHelperInstance();
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: listenerInstance[]=' . gettype($listenerInstance));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance));
// Is there a listener instance set?
if ($listenerInstance instanceof Listenable) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
// Set it here for later usage
$socketInstance->setListenerInstance($listenerInstance);
} elseif ($helperInstance instanceof ConnectionHelper) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: Setting helperInstance=' . $helperInstance->__toString() . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting helperInstance=' . $helperInstance->__toString() . ' ...');
// Set it here for later usage
$socketInstance->setHelperInstance($helperInstance);
$packageData = $this->getPackageData();
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: unl=' . $unl . ',packageData=' . print_r($packageData, true));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: unl=' . $unl . ',packageData=' . print_r($packageData, true));
// So, does both match?
$matches = ((isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) && ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] === $unl));
*/
public function ifSocketResourceMatches ($socketResource) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: socketResource[' . gettype($socketResource) . ']=' .$socketResource . ',storedResource[' . gettype($this->getSocketResource()) . ']=' . $this->getSocketResource());
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: socketResource[' . gettype($socketResource) . ']=' .$socketResource . ',storedResource[' . gettype($this->getSocketResource()) . ']=' . $this->getSocketResource());
// So, does both match?
$matches = ((is_resource($socketResource)) && ($socketResource === $this->getSocketResource()));
*/
public function isServerSocketResource () {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET: Testing if server socket - CALLED!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Testing if server socket - CALLED!');
// Init peer address/port
$peerAddress = '0.0.0.0';
} // END - if
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: peerAddress=%s,peerPort=%d', $peerAddress, $peerPort));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf(strtoupper($this->getSocketProtocol()) . '-SOCKET: peerAddress=%s,peerPort=%d', $peerAddress, $peerPort));
// Check peer name, it must be empty
$isServerSocket = (($isServerSocket) && (empty($peerAddress)));
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: isServerSocket=%d - EXIT!', intval($isServerSocket)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf(strtoupper($this->getSocketProtocol()) . '-SOCKET: isServerSocket=%d - EXIT!', intval($isServerSocket)));
// Return result
return $isServerSocket;
*/
public function shutdownSocket () {
// Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET: Shutting down socket resource ' . $this->getSocketResource() . ' with state ' . $this->getPrintableState() . ' ...');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource() . ' with state ' . $this->getPrintableState() . ' ...');
// Get a visitor instance
$visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
// Debug output
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
// Call the visitor
$this->accept($visitorInstance);
*/
public function halfShutdownSocket () {
// Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET: Half-shutting down socket resource ' . $this->getSocketResource() . ' with state ' . $this->getPrintableState() . ' ...');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Half-shutting down socket resource ' . $this->getSocketResource() . ' with state ' . $this->getPrintableState() . ' ...');
// Get a visitor instance
$visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
// Debug output
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
// Call the visitor
$this->accept($visitorInstance);
*/
public function accept (Visitor $visitorInstance) {
// Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
// Visit this listener
- $visitorInstance->visitListener($this);
+ $visitorInstance->visitSocket($this);
// Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
}
/**
$socketProtocol = $this->getSocketProtocol();
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketProtocol[%s]=%s', gettype($socketProtocol), $socketProtocol));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf(strtoupper($this->getSocketProtocol()) . '-SOCKET: socketProtocol[%s]=%s', gettype($socketProtocol), $socketProtocol));
// Get socket option
$socketType = socket_get_option($this->getSocketResource(), getprotobyname($socketProtocol), SO_TYPE);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketType[%s]=%s', gettype($socketType), $socketType));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf(strtoupper($this->getSocketProtocol()) . '-SOCKET: socketType[%s]=%s', gettype($socketType), $socketType));
// Is it valid?
if ($socketType === FALSE) {
return $result;
}
+ /**
+ * Do the shutdown sequence for this connection helper
+ *
+ * @return void
+ * @throws SocketShutdownException If the current socket could not be shut down
+ * @todo We may want to implement a filter for ease notification of other objects like our pool
+ * @todo rewrite this!
+ */
+ public function doShutdown () {
+ // Debug message
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Shutting down socket ' . $this->getSocketResource());
+ $this->partialStub('Please rewrite this method.');
+ return;
+
+ // Clear any previous errors
+ socket_clear_error($this->getSocketResource());
+
+ // Call the shutdown function on the currently set socket
+ if (!socket_shutdown($this->getSocketResource())) {
+ // Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
+ if (socket_last_error($this->getSocketResource()) != 107) {
+ // Something bad happened while we shutdown a socket
+ throw new SocketShutdownException($this, self::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+ } // END - if
+
+ // Try to make blocking IO for socket_close()
+ socket_set_block($this->getSocketResource());
+
+ // Drop all data (don't sent any on socket closure)
+ socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0));
+
+ // Finally close socket to free some resources
+ socket_close($this->getSocketResource());
+
+ // Mark this connection as shutted down
+ $this->markConnectionShuttedDown();
+ }
+
/**
* Handles socket error for given socket resource and peer data. This method
* validates socket resource stored in given container if it is a valid
default: // Everything else <> 0
// Unhandled error code detected, so first debug it because we may want to handle it like the others
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: Unsupported errorCode=%d,message=%s', $errorCode, socket_strerror($errorCode)));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf(strtoupper($this->getSocketProtocol()) . '-SOCKET: Unsupported errorCode=%d,message=%s', $errorCode, socket_strerror($errorCode)));
// Change it only in this class
$errorName = StorableSocket::SOCKET_ERROR_UNKNOWN;
* @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
- * @todo Find an interface for hub helper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* @return void
* @throws SocketShutdownException If the current socket could not be shut down
- * @todo We may want to implement a filter for ease notification of other objects like our pool
+ * @todo rewrite this!
*/
public function doShutdown () {
// Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Shutting down socket resource ' . $this->getSocketResource());
-
- // Clear any previous errors
- socket_clear_error($this->getSocketResource());
-
- // Call the shutdown function on the currently set socket
- if (!socket_shutdown($this->getSocketResource())) {
- // Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
- if (socket_last_error($this->getSocketResource()) != 107) {
- // Something bad happened while we shutdown a socket
- throw new SocketShutdownException($this, self::EXCEPTION_INVALID_SOCKET);
- } // END - if
- } // END - if
-
- // Try to make blocking IO for socket_close()
- socket_set_block($this->getSocketResource());
-
- // Drop all data (don't sent any on socket closure)
- socket_set_option($this->getSocketResource(), SOL_SOCKET, SO_LINGER, array('l_onoff' => 1, 'l_linger' => 0));
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Shutting down connection ... - CALLED!');
- // Finally close socket to free some resources
- socket_close($this->getSocketResource());
-
- // Mark this connection as shutted down
- $this->markConnectionShuttedDown();
+ $this->partialStub('Please implement this method.');
}
-}
-// [EOF]
-?>
+}