]> git.mxchange.org Git - hub.git/commitdiff
More rewrites:
authorRoland Häder <roland@mxchange.org>
Sat, 20 May 2017 23:10:38 +0000 (01:10 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:05 +0000 (18:50 +0200)
- imported missing classes/interfaces
- socket error 95 (operation not supported) is now handled and new exception thrown
- EXCEPTION_INVALID_SOCKET is no longer located in BaseListener
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
25 files changed:
application/hub/classes/client/http/class_HttpClient.p
application/hub/classes/client/http/class_HttpClient.ph
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/handler/raw_data/network/class_BaseRawDataHandler.php
application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/listener/tcp/class_TcpListener.php
application/hub/classes/listener/udp/class_UdpListener.php
application/hub/classes/package/assembler/class_PackageAssembler.php
application/hub/classes/package/class_NetworkPackage.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/classes/resolver/state/peer/class_PeerStateResolver.php
application/hub/classes/states/peer/class_
application/hub/classes/states/peer/connected/class_ConnectedPeerState.php
application/hub/classes/states/peer/errors/class_ConnectionRefusedPeerState.php
application/hub/classes/states/peer/errors/class_ConnectionTimedOutPeerState.php
application/hub/classes/states/peer/errors/class_NoRouteToHostPeerState.php
application/hub/classes/states/peer/errors/class_OperationAlreadyProgressPeerState.php
application/hub/classes/states/peer/errors/class_ProblemPeerState.php
application/hub/classes/states/peer/errors/class_TransportEndpointGonePeerState.php
application/hub/interfaces/container/socket/class_StorableSocket.php
core

index 98e50d0152612f4a2996fb085b8a6526d44fc2e7..bfc535d33888376adfaa32f8a9be45227c7ae566 100644 (file)
@@ -19,5 +19,5 @@
                // Check if there was an error else
                if ($errorNo > 0) {
                        // Then throw again
-                       throw new InvalidSocketException(array($helperInstance, $socketResource, $errorNo, $errorStr), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($helperInstance, $socketResource, $errorNo, $errorStr), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
index 49990704c30493d66c6fd08a53687fc271f0c9e6..cdd80f71919cf1f7a1bdbfbb999320c2fa445103 100644 (file)
@@ -38,7 +38,7 @@
                // Check if there was an error else
                if ($errorNo > 0) {
                        // Then throw again
-                       throw new InvalidSocketException(array($helperInstance, $socketResource, $errorNo, $errorStr), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($helperInstance, $socketResource, $errorNo, $errorStr), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Prepare the GET request
index a49a2c8094156e3646ccb25ff9aa7bbc2a69178f..db6f3d0d357062a5ed8d9a98d2ec3ecc3a999878 100644 (file)
@@ -3,16 +3,23 @@
 namespace Hub\Container\Socket;
 
 // Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Helper\Connection\BaseConnectionHelper;
 use Hub\Information\ShareableInfo;
 use Hub\Listener\BaseListener;
 use Hub\Network\Package\NetworkPackage;
 
 // Import framework stuff
 use CoreFramework\Container\BaseContainer;
+use CoreFramework\Factory\ObjectFactory;
 use CoreFramework\Listener\Listenable;
 use CoreFramework\Registry\Registerable;
 use CoreFramework\Socket\InvalidSocketException;
 use CoreFramework\Socket\NoSocketErrorDetectedException;
+use CoreFramework\Socket\SocketBindingException;
+use CoreFramework\Socket\SocketConnectionException;
+use CoreFramework\Socket\SocketOperationException;
+use CoreFramework\Socket\UnsupportedSocketErrorHandlerException;
 use CoreFramework\Visitor\Visitable;
 use CoreFramework\Visitor\Visitor;
 
@@ -55,11 +62,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * @param       $socketResource         A valid socket resource
         * @param       $infoInstance           An instance of a  ShareableInfo class
         * @param       $packageData            Raw package data
-        * @return      $containerInstance      An instance of this Container class
+        * @return      $socketInstance An instance of this Container class
         */
        public static final function createSocketContainer ($socketResource, ShareableInfo $infoInstance = NULL, array $packageData = array()) {
                // Get a new instance
-               $containerInstance = new SocketContainer();
+               $socketInstance = new SocketContainer();
 
                // Remove unneeded entries
                unset($packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
@@ -83,24 +90,24 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
 
                                // Set it here for later usage
-                               $containerInstance->setListenerInstance($listenerInstance);
+                               $socketInstance->setListenerInstance($listenerInstance);
                        } elseif ($helperInstance instanceof ConnectionHelper) {
                                // Debug message
                                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-CONTAINER: Setting helperInstance=' . $helperInstance->__toString() . ' ...');
 
                                // Set it here for later usage
-                               $containerInstance->setHelperInstance($helperInstance);
+                               $socketInstance->setHelperInstance($helperInstance);
                        }
                } // END - if
 
                // Set the resource ...
-               $containerInstance->setSocketResource($socketResource);
+               $socketInstance->setSocketResource($socketResource);
 
                // ... and package data
-               $containerInstance->setPackageData($packageData);
+               $socketInstance->setPackageData($packageData);
 
                // Return the prepared instance
-               return $containerInstance;
+               return $socketInstance;
        }
 
        /**
@@ -233,6 +240,73 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
        }
 
+       /**
+        * Some "getter" for peer address/port from stored socket
+        *
+        * @param       $peerAddress    Peer address being determined
+        * @param       $peerPort               Peer port being determined
+        * @return      $result                 Result from asking for peer address
+        * @throws      InvalidSocketException  If socket is invalid
+        */
+       public function getSocketPeerName (&$peerAddress, &$peerPort) {
+               // Should be valid socket
+               if (!$this->isValidSocket()) {
+                       // Throw exception
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+
+               // Init result
+               $result = FALSE;
+
+               /*
+                * Which type of socket is set? Please note that UDP sockets doesn't
+                * support socket_getpeername():
+                * http://de2.php.net/manual/en/function.socket-getpeername.php#35656
+                */
+               if ($this->getSocketType() == 'udp') {
+                       // UDP is WIP:
+                       $this->partialStub('UDP sockets are unfinished.');
+               } else {
+                       // Use socket_getpeername()
+                       $result = socket_getpeername($this->getSocketResource(), $peerAddress, $peerPort);
+               }
+
+               // Return result
+               return $result;
+       }
+
+       /**
+        * Some "getter" for socket type of stored socket
+        *
+        * @return      $socketType             Socket type
+        * @throws      InvalidSocketException  If socket is invalid
+        */
+       public function getSocketType () {
+               // Should be valid socket
+               if (!$this->isValidSocket()) {
+                       // Throw exception
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+
+               // Get socket protocol first
+               $socketProtocol = $this->getSocketProtocol();
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: 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));
+
+               // Is it valid?
+               if ($socketType === FALSE) {
+                       // Something went wrong
+                       $this->handleSocketError(__METHOD__, __LINE__, array('null', '0'));
+               } // END - if
+       }
+
        /**
         * Validates stored stocket
         *
@@ -260,7 +334,7 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                // Should be valid socket
                if (!$this->isValidSocket()) {
                        // Throw exception
-                       throw new InvalidSocketException(array($this, $this->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Get it from stored socket resource
@@ -273,6 +347,29 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                return $errorCode;
        }
 
+       /**
+        * Getter for last socket error message
+        *
+        * @return      $lastSocketErrorMessage Last socket error message
+        * @throws      InvalidSocketException  If socket is invalid
+        */
+       public function getLastSocketErrorMessage () {
+               // Should be valid socket
+               if (!$this->isValidSocket()) {
+                       // Throw exception
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+
+               // Get it from stored socket resource
+               $socketResource = $this->getSocketResource();
+
+               // Get error code and message
+               $message = socket_strerror(socket_last_error($socketResource));
+
+               // Return it
+               return $message;
+       }
+
        /**
         * Tries to bind the socket.
         *
@@ -285,7 +382,7 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                // Should be valid socket
                if (!$this->isValidSocket()) {
                        // Throw exception
-                       throw new InvalidSocketException(array($this, $this->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Try to bind it to
@@ -299,13 +396,13 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Tries to listen on the socket
         *
         * @return      $result         Result from listening on socket
-        * @throws      InvalidSocketException  If socket is valid
+        * @throws      InvalidSocketException  If stored socket is invalid
         */
        public function listenOnSocket () {
                // Should be valid socket
                if (!$this->isValidSocket()) {
                        // Throw exception
-                       throw new InvalidSocketException(array($this, $this->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Try to listen on socket
@@ -319,13 +416,13 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Tries to set non-blocking I/O on stored socket
         *
         * @return      $result         Result of changing to non-blocking I/O
-        * @throws      InvalidSocketException  If socket is valid
+        * @throws      InvalidSocketException  If stored socket is invalid
         */
        public function enableSocketNonBlocking () {
                // Should be valid socket
                if (!$this->isValidSocket()) {
                        // Throw exception
-                       throw new InvalidSocketException(array($this, $this->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Try to set non-blocking I/O
@@ -356,7 +453,7 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                // This method handles only socket resources
                if (!$this->isValidSocket()) {
                        // No resource, abort here
-                       throw new InvalidSocketException(array($this, $this->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number
@@ -377,10 +474,299 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
                $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
 
                // Call-back the error handler method
-               call_user_func_array(array($this, $handlerName), array($this, $socketData));
+               call_user_func_array(array($this, $handlerName), array($socketData));
 
                // Finally clear the error because it has been handled
                $this->clearLastSocketError();
        }
 
+       /**
+        * Translates socket error codes into our own internal names which can be
+        * used for call-backs.
+        *
+        * @param       $errorCode      The error code from socket_last_error() to be translated
+        * @return      $errorName      The translated name (all lower-case, with underlines)
+        */
+       public function translateSocketErrorCodeToName ($errorCode) {
+               // Nothing bad happened by default
+               $errorName = StorableSocket::SOCKET_CONNECTED;
+
+               // Is the code a number, then we have to change it
+               switch ($errorCode) {
+                       case 0: // Silently ignored, the socket is connected
+                               break;
+
+                       case 11:  // "Resource temporary unavailable"
+                               $errorName = StorableSocket::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
+                               break;
+
+                       case 13:  // "Permission denied"
+                               $errorName = StorableSocket::SOCKET_ERROR_PERMISSION_DENIED;
+                               break;
+
+                       case 32:  // "Broken pipe"
+                               $errorName = StorableSocket::SOCKET_ERROR_BROKEN_PIPE;
+                               break;
+
+                       case 95:  // "Operation not supported"
+                               $errorName = StorableSocket::SOCKET_ERROR_OPERATION_NOT_SUPPORTED;
+                               break;
+
+                       case 104: // "Connection reset by peer"
+                               $errorName = StorableSocket::SOCKET_ERROR_CONNECTION_RESET_BY_PEER;
+                               break;
+
+                       case 107: // "Transport end-point not connected"
+                       case 134: // On some (?) systems for 'transport end-point not connected'
+                               // @TODO On some systems it is 134, on some 107?
+                               $errorName = StorableSocket::SOCKET_ERROR_TRANSPORT_ENDPOINT;
+                               break;
+
+                       case 110: // "Connection timed out"
+                               $errorName = StorableSocket::SOCKET_ERROR_CONNECTION_TIMED_OUT;
+                               break;
+
+                       case 111: // "Connection refused"
+                               $errorName = StorableSocket::SOCKET_ERROR_CONNECTION_REFUSED;
+                               break;
+
+                       case 113: // "No route to host"
+                               $errorName = StorableSocket::SOCKET_ERROR_NO_ROUTE_TO_HOST;
+                               break;
+
+                       case 114: // "Operation already in progress"
+                               $errorName = StorableSocket::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS;
+                               break;
+
+                       case 115: // "Operation now in progress"
+                               $errorName = StorableSocket::SOCKET_ERROR_OPERATION_IN_PROGRESS;
+                               break;
+
+                       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)));
+
+                               // Change it only in this class
+                               $errorName = StorableSocket::SOCKET_ERROR_UNKNOWN;
+                               break;
+               } // END - switch
+
+               // Return translated name
+               return $errorName;
+       }
+
+       /**
+        * Constructs a callable method name from given socket error code. If the
+        * method is not found, a generic one is used.
+        *
+        * @param       $errorCode              Error code from socket_last_error()
+        * @return      $handlerName    Call-back method name for the error handler
+        * @throws      UnsupportedSocketErrorHandlerException If the error handler is not implemented
+        */
+       protected function getSocketErrorHandlerFromCode ($errorCode) {
+               // Create a name from translated error code
+               $handlerName = 'handleSocketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode));
+
+               // Is the call-back method there?
+               if (!method_exists($this, $handlerName)) {
+                       // Please implement this
+                       throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), BaseConnectionHelper::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
+               } // END - if
+
+               // Return it
+               return $handlerName;
+       }
+
+       /************************************************************************
+        *                Socket error handler call-back methods                *
+        ************************************************************************/
+
+       /**
+        * Handles socket error 'permission denied', but does not clear it for
+        * later debugging purposes.
+        *
+        * @param       $socketData                     A valid socket data array (0 = IP/file name, 1 = port)
+        * @return      void
+        * @throws      SocketBindingException  The socket could not be bind to
+        */
+       protected function handleSocketErrorPermissionDenied (array $socketData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketBindingException(array($this, $socketData, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'connection timed out', but does not clear it for
+        * later debugging purposes.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketConnectionException       The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorConnectionTimedOut (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketConnectionException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'resource temporary unavailable', but does not
+        * clear it for later debugging purposes.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketConnectionException       The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorResourceUnavailable (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketConnectionException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'connection refused', but does not clear it for
+        * later debugging purposes.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketConnectionException       The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorConnectionRefused (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketConnectionException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'no route to host', but does not clear it for later
+        * debugging purposes.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketConnectionException       The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorNoRouteToHost (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketConnectionException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'operation already in progress' which happens in
+        * method connectToPeerByUnlData() on timed out connection
+        * attempts.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketConnectionException       The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorOperationAlreadyProgress (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Half-shutdown this socket (see there for difference to shutdownSocket())
+               $this->halfShutdownSocket();
+
+               // Throw it again
+               throw new SocketConnectionException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'connection reset by peer', but does not clear it for
+        * later debugging purposes.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketConnectionException       The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorConnectionResetByPeer (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketConnectionException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket error 'operation not supported', but does not clear it for
+        * later debugging purposes.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        * @throws      SocketOperationException        The connection attempts fails with a time-out
+        */
+       protected function handleSocketErrorOperationNotSupported (array $unlData) {
+               // Get socket error code for verification
+               $socketError = $this->getLastSocketError();
+
+               // Get error message
+               $errorMessage = $this->getLastSocketErrorMessage();
+
+               // Shutdown this socket
+               $this->shutdownSocket();
+
+               // Throw it again
+               throw new SocketOperationException(array($this, $this->getSocketResource(), $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
+       }
+
+       /**
+        * Handles socket "error" 'operation now in progress' which can be safely
+        * passed on with non-blocking connections.
+        *
+        * @param       $unlData                        A valid UNL data array
+        * @return      void
+        */
+       protected function handleSocketErrorOperationInProgress (array $unlData) {
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Operation is now in progress, this is usual for non-blocking connections and is no bug.');
+       }
+
 }
index 43be546201328c8bfa1c8fe3ae3d896cb12b6d36..594416bc4dc85b04e5400c8eb7c2c78e0c03e51d 100644 (file)
@@ -240,7 +240,7 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look
                        $lastError = socket_last_error($socketResource);
 
                        // Doesn't work!
-                       throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Debug message
index e20805b6ae857b3d59d923565dd27af0d35ecafa..d62d7a55ab7a84a17c220e9961679a62672aa161 100644 (file)
@@ -138,7 +138,7 @@ class SocketFactory extends ObjectFactory {
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
                        // Something bad happened
-                       throw new InvalidSocketException(array($listenerInstance, $socketInstance->getSocketResource()), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($listenerInstance, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Get socket error code for verification
index 2cdccd86557ac7bc0719894780c8aa0cfe9ba45b..2544d52899016756a9e594a8e7faadbef31e0b83 100644 (file)
@@ -32,24 +32,6 @@ use CoreFramework\Handler\BaseHandler;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseRawDataHandler extends BaseHandler {
-       // Error codes:
-       // - Socket raw data stream errors
-       const SOCKET_ERROR_UNKNOWN                    = 'unknown_error';              // Unknown error (should not happen)
-       const SOCKET_ERROR_TRANSPORT_ENDPOINT         = 'transport_endpoint';         // Transport endpoint has closed
-       const SOCKET_ERROR_INVALID_BASE64_MODULO      = 'base64_modulo';              // Length is not modulo 4
-       const SOCKET_ERROR_INVALID_BASE64_MESSAGE     = 'base64_message';             // Raw data is not Base64-encoded
-       const SOCKET_ERROR_UNHANDLED                  = 'unhandled_package';          // Unhandled raw data (not bad)
-       const SOCKET_ERROR_CONNECTION_REFUSED         = 'connection_refused';         // The name says it: connection refused
-       const SOCKET_ERROR_CONNECTION_TIMED_OUT       = 'connection_timed_out';       // The name says it: connection attempt has timed-out
-       const SOCKET_ERROR_OPERATION_IN_PROGRESS      = 'operation_in_progress';      // 'Operation now in progress'
-       const SOCKET_ERROR_OPERATION_ALREADY_PROGRESS = 'operation_already_progress'; // 'Operation already in progress'
-       const SOCKET_ERROR_RESOURCE_UNAVAILABLE       = 'resource_unavailable';       // 'Resource temporary unavailable'
-       const SOCKET_ERROR_NO_ROUTE_TO_HOST           = 'no_route_to_host';           // The name says it: no route to host
-       const SOCKET_ERROR_CONNECTION_RESET_BY_PEER   = 'connection_reset_by_peer';   // Connection reset by peer
-       const SOCKET_ERROR_BROKEN_PIPE                = 'broken_pipe';                // Broken pipe
-       const SOCKET_ERROR_PERMISSION_DENIED          = 'permission_denied';          // Permission denied
-       const SOCKET_CONNECTED                        = 'connected';                  // Nothing errorous happens, socket is connected
-
        // - Package errors
        const PACKAGE_ERROR_INVALID_DATA       = 'invalid_data';    // Invalid data in package found
        const PACKAGE_ERROR_INCOMPLETE_DATA    = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
index a12c47cfad05f94b8483a0a65dc7a74248fd30a4..b9799d4dc6e1b148365ed598039cb58596abb75e 100644 (file)
@@ -202,161 +202,4 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper {
                $this->initSocketInstance();
        }
 
-       // ************************************************************************
-       //                 Socket error handler call-back methods
-       // ************************************************************************
-
-       /**
-        * Handles socket error 'connection timed out', but does not clear it for
-        * later debugging purposes.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      SocketConnectionException       The connection attempts fails with a time-out
-        */
-       protected function socketErrorConnectionTimedOutHandler (StorableSocket $socketInstance, array $unlData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Shutdown this socket
-               $socketInstance->shutdownSocket();
-
-               // Throw it again
-               throw new SocketConnectionException(array($this, $socketInstance, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
-       }
-
-       /**
-        * Handles socket error 'resource temporary unavailable', but does not
-        * clear it for later debugging purposes.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      SocketConnectionException       The connection attempts fails with a time-out
-        */
-       protected function socketErrorResourceUnavailableHandler (StorableSocket $socketInstance, array $unlData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Shutdown this socket
-               $socketInstance->shutdownSocket();
-
-               // Throw it again
-               throw new SocketConnectionException(array($this, $socketInstance, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
-       }
-
-       /**
-        * Handles socket error 'connection refused', but does not clear it for
-        * later debugging purposes.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      SocketConnectionException       The connection attempts fails with a time-out
-        */
-       protected function socketErrorConnectionRefusedHandler (StorableSocket $socketInstance, array $unlData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Shutdown this socket
-               $socketInstance->shutdownSocket();
-
-               // Throw it again
-               throw new SocketConnectionException(array($this, $socketInstance, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
-       }
-
-       /**
-        * Handles socket error 'no route to host', but does not clear it for later
-        * debugging purposes.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      SocketConnectionException       The connection attempts fails with a time-out
-        */
-       protected function socketErrorNoRouteToHostHandler (StorableSocket $socketInstance, array $unlData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Shutdown this socket
-               $socketInstance->shutdownSocket();
-
-               // Throw it again
-               throw new SocketConnectionException(array($this, $socketInstance, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
-       }
-
-       /**
-        * Handles socket error 'operation already in progress' which happens in
-        * method connectToPeerByUnlData() on timed out connection
-        * attempts.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      SocketConnectionException       The connection attempts fails with a time-out
-        */
-       protected function socketErrorOperationAlreadyProgressHandler (StorableSocket $socketInstance, array $unlData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Half-shutdown this socket (see there for difference to shutdownSocket())
-               $socketInstance->halfShutdownSocket();
-
-               // Throw it again
-               throw new SocketConnectionException(array($this, $socketInstance, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
-       }
-
-       /**
-        * Handles socket error 'connection reset by peer', but does not clear it for
-        * later debugging purposes.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        * @throws      SocketConnectionException       The connection attempts fails with a time-out
-        */
-       protected function socketErrorConnectionResetByPeerHandler (StorableSocket $socketInstance, array $unlData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Shutdown this socket
-               $socketInstance->shutdownSocket();
-
-               // Throw it again
-               throw new SocketConnectionException(array($this, $socketInstance, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
-       }
-
-       /**
-        * Handles socket "error" 'operation now in progress' which can be safely
-        * passed on with non-blocking connections.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $unlData                        A valid UNL data array
-        * @return      void
-        */
-       protected function socketErrorOperationInProgressHandler (StorableSocket $socketInstance, array $unlData) {
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Operation is now in progress, this is usual for non-blocking connections and is no bug.');
-       }
 }
-
-// [EOF]
-?>
index 6859446f1d19bca53a212191d914bff6a97b7540..b6c086708b69154a560d5b287e00537d14974587 100644 (file)
@@ -71,7 +71,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                         * possible here because that method would throw an
                         * InvalidSocketException back.
                         */
-                       throw new SocketCreationException(array($helperInstance, gettype($socketResource)), SocketHandler::EXCEPTION_SOCKET_CREATION_FAILED);
+                       throw new SocketCreationException(array($helperInstance, gettype($socketResource)), StorableSocket::EXCEPTION_SOCKET_CREATION_FAILED);
                } // END - if
 
                // Get socket error code for verification
@@ -83,7 +83,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                        $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
 
                        // Then throw again
-                       throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), SocketHandler::EXCEPTION_SOCKET_CREATION_FAILED);
+                       throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), StorableSocket::EXCEPTION_SOCKET_CREATION_FAILED);
                } // END - if
 
                // Debug message
@@ -173,7 +173,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                        // 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, SocketHandler::EXCEPTION_INVALID_SOCKET);
+                               throw new SocketShutdownException($this, self::EXCEPTION_INVALID_SOCKET);
                        } // END - if
                } // END - if
 
index b1039c8d4d32d2f29f4d3e7d72f04e6c3f2345de..625f0806e9cccd3844121e95a9895aa5da8806fd 100644 (file)
@@ -6,7 +6,6 @@ namespace Hub\Listener;
 use Hub\Container\Socket\StorableSocket;
 use Hub\Factory\Information\Connection\ConnectionInfoFactory;
 use Hub\Generic\BaseHubSystem;
-use Hub\Handler\RawData\BaseRawDataHandler;
 use Hub\Helper\Connection\BaseConnectionHelper;
 use Hub\Network\Package\NetworkPackage;
 use Hub\Pool\Peer\PoolablePeer;
@@ -282,99 +281,6 @@ class BaseListener extends BaseHubSystem implements Visitable {
                throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
        }
 
-       /**
-        * Constructs a callable method name from given socket error code. If the
-        * method is not found, a generic one is used.
-        *
-        * @param       $errorCode              Error code from socket_last_error()
-        * @return      $handlerName    Call-back method name for the error handler
-        * @throws      UnsupportedSocketErrorHandlerException If the error handler is not implemented
-        */
-       protected function getSocketErrorHandlerFromCode ($errorCode) {
-               // Create a name from translated error code
-               $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
-
-               // Is the call-back method there?
-               if (!method_exists($this, $handlerName)) {
-                       // Please implement this
-                       throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), BaseConnectionHelper::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
-               } // END - if
-
-               // Return it
-               return $handlerName;
-       }
-
-       /**
-        * Translates socket error codes into our own internal names which can be
-        * used for call-backs.
-        *
-        * @param       $errorCode      The error code from socket_last_error() to be translated
-        * @return      $errorName      The translated name (all lower-case, with underlines)
-        */
-       public function translateSocketErrorCodeToName ($errorCode) {
-               // Nothing bad happened by default
-               $errorName = BaseRawDataHandler::SOCKET_CONNECTED;
-
-               // Is the code a number, then we have to change it
-               switch ($errorCode) {
-                       case 0: // Silently ignored, the socket is connected
-                               break;
-
-                       case 11:  // "Resource temporary unavailable"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
-                               break;
-
-                       case 13:  // "Permission denied"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_PERMISSION_DENIED;
-                               break;
-
-                       case 32:  // "Broken pipe"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_BROKEN_PIPE;
-                               break;
-
-                       case 104: // "Connection reset by peer"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_RESET_BY_PEER;
-                               break;
-
-                       case 107: // "Transport end-point not connected"
-                       case 134: // On some (?) systems for 'transport end-point not connected'
-                               // @TODO On some systems it is 134, on some 107?
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
-                               break;
-
-                       case 110: // "Connection timed out"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT;
-                               break;
-
-                       case 111: // "Connection refused"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED;
-                               break;
-
-                       case 113: // "No route to host"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST;
-                               break;
-
-                       case 114: // "Operation already in progress"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS;
-                               break;
-
-                       case 115: // "Operation now in progress"
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_IN_PROGRESS;
-                               break;
-
-                       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('BASE-HUB UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
-
-                               // Change it only in this class
-                               $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
-                               break;
-               }
-
-               // Return translated name
-               return $errorName;
-       }
-
        /**
         * "Listens" for incoming network packages
         *
@@ -515,31 +421,4 @@ class BaseListener extends BaseHubSystem implements Visitable {
                $this->getIteratorInstance()->next();
        }
 
-       // ************************************************************************
-       //                 Socket error handler call-back methods
-       // ************************************************************************
-
-       /**
-        * Handles socket error 'permission denied', but does not clear it for
-        * later debugging purposes.
-        *
-        * @param       $socketInstance         An instance of a StorableSocket class
-        * @param       $socketData                     A valid socket data array (0 = IP/file name, 1 = port)
-        * @return      void
-        * @throws      SocketBindingException  The socket could not be bind to
-        */
-       protected function socketErrorPermissionDeniedHandler (StorableSocket $socketInstance, array $socketData) {
-               // Get socket error code for verification
-               $socketError = $socketInstance->getLastSocketError();
-
-               // Get error message
-               $errorMessage = $socketInstance->getLastSocketErrorMessage();
-
-               // Shutdown this socket
-               $socketInstance->shutdownSocket();
-
-               // Throw it again
-               throw new SocketBindingException(array($this, $socketData, $socketInstance, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
-       }
-
 }
index 1a387388c18a3f9e43e21460d83b31f842d2014b..83b003087f38b16ecfdbb87098259b9c2e01a939 100644 (file)
@@ -74,7 +74,7 @@ class TcpListener extends BaseListener implements Listenable {
                // Is the socket resource valid?
                if (!is_resource($mainSocket)) {
                        // Something bad happened
-                       throw new InvalidSocketException(array($this, $mainSocket), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Get socket error code for verification
@@ -86,7 +86,7 @@ class TcpListener extends BaseListener implements Listenable {
                        $this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
                        /*
                        // Then throw again
-                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, socket_strerror($socketError)), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, socket_strerror($socketError)), self::EXCEPTION_INVALID_SOCKET);
                        */
                } // END - if
 
@@ -105,7 +105,7 @@ class TcpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
                        */
                } // END - if
 
@@ -129,7 +129,7 @@ class TcpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
                        */
                } // END - if
 
@@ -149,7 +149,7 @@ class TcpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
                        */
                } // END - if
 
@@ -169,7 +169,7 @@ class TcpListener extends BaseListener implements Listenable {
                        $this->shutdownSocket($mainSocket);
 
                        // And throw again
-                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), self::EXCEPTION_INVALID_SOCKET);
                        */
                } // END - if
 
index c06401292d7863e4923e0606c1111e834b5ed5e0..697f0c82d66adf8814a2e2ee6301165110732d1c 100644 (file)
@@ -72,7 +72,7 @@ class UdpListener extends BaseListener implements Listenable {
                // Is the socket a valid resource or do we have any error?
                if (!is_resource($mainSocket)) {
                        // Then throw an InvalidSocketException
-                       throw new InvalidSocketException(array($this, $mainSocket), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $mainSocket), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                /*
index 4c50578a940bf93070ac7a390491c1cb0e29a9d2..3ba2381945fc6503ae01c8952175a5343fdf7ae3 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Network\Package\Assembler;
 
 // Import hub-specific stuff
+use Hub\Container\Socket\StorableSocket;
 use Hub\Generic\BaseHubSystem;
 use Hub\Handler\RawData\BaseRawDataHandler;
 use Hub\Network\Package\NetworkPackage;
@@ -267,7 +268,7 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
                // Init fake array
                $packageContent = array(
                        BaseRawDataHandler::PACKAGE_RAW_DATA   => $this->getInputStreamInstance()->streamData($this->pendingData),
-                       BaseRawDataHandler::PACKAGE_ERROR_CODE => BaseRawDataHandler::SOCKET_ERROR_UNHANDLED
+                       BaseRawDataHandler::PACKAGE_ERROR_CODE => StorableSocket::SOCKET_ERROR_UNHANDLED
                );
 
                /*
index aa01e2139bb57db03c028df800f5895db2588460..1e35c4ada4906e99a9aa923aa3dc8bd0d4724802 100644 (file)
@@ -1128,8 +1128,8 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 * Also make sure the error code is SOCKET_ERROR_UNHANDLED because we
                 * only want to handle unhandled packages here.
                 */
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . BaseRawDataHandler::SOCKET_ERROR_UNHANDLED . ')');
-               assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] . '(' . StorableSocket::SOCKET_ERROR_UNHANDLED . ')');
+               assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == StorableSocket::SOCKET_ERROR_UNHANDLED);
 
                // Remove the last chunk SEPARATOR (because there is no need for it)
                if (substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
index a6bb89d23bcd1673b354791e8c836d3af506655b..d8272757f3c2dda9964902e77c40edb4c2ba29ad 100644 (file)
@@ -77,7 +77,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // Is it a valid resource?
                if (!$socketInstance->isValidSocket()) {
                        // Throw an exception
-                       throw new InvalidSocketException(array($this, $socketInstance->getSocketResource()), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                       throw new InvalidSocketException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Get error code
index 811224abd6df756409022b2113ba2d0f7885f341..315afcd9747fcd004bcbf26804bd6a1a73b6c13c 100644 (file)
@@ -84,7 +84,7 @@ class PeerStateResolver extends BaseStateResolver implements StateResolver {
                        // Still no socket resource?
                        if (!$socketInstance->isValidSocket())) {
                                // Then abort here with an exception (may happen after socket_shutdown())
-                               throw new InvalidSocketException(array($helperInstance, $socketInstance->getSocketResource()), SocketHandler::EXCEPTION_INVALID_SOCKET);
+                               throw new InvalidSocketException(array($helperInstance, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
                        } // END - if
                } // END - if
 
index 1dbda959e408cad232233b5be126f3da9ebe16f9..e9e2ac927aeeee8bf9faee4ffbad83dc70be2ae2 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class ???PeerState extends BasePeerState implements PeerStateable {
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_!!!);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_!!!);
        }
 
        /**
index 1fc6279f585903648bc96c8f9e0b3a497d7d8741..9b71fe1e32312aaf4639d9f9263c1e9e1fc25353 100644 (file)
@@ -2,6 +2,9 @@
 // Own namespace
 namespace Hub\State\Peer;
 
+// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
+
 // Import framework stuff
 use CoreFramework\State\Stateable;
 
@@ -38,7 +41,7 @@ class ConnectedPeerState extends BasePeerState implements PeerStateable {
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_CONNECTED);
+               $this->setStateName(StorableSocket::SOCKET_CONNECTED);
        }
 
        /**
index 7f24ae5588f49eb45bbe45cdb510698a362d6f84..f12869ae6bb2cb725c3dcf324a23bf87c981083d 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class ConnectionRefusedPeerState extends BasePeerState implements PeerStateable
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_CONNECTION_REFUSED);
        }
 
        /**
index c295b2b33c5f7db41df2d1f3d036558db2b3ec32..7313e93907502b9314cbd9ca0dacaded54475a0d 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class ConnectionTimedOutPeerState extends BasePeerState implements PeerStateable
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_CONNECTION_TIMED_OUT);
        }
 
        /**
index 29785850feaf0f71618283a92031823836febe21..edaa29f837f7420acaea278ebe058ae31a3c1c3b 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class NoRouteToHostPeerState extends BasePeerState implements PeerStateable {
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_NO_ROUTE_TO_HOST);
        }
 
        /**
index c7d7df8b8998eb626fa43536a90c57f5e3958f6c..99d39acc9843ae55b1386f12dd67bcd87d060369 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class OperationAlreadyProgressPeerState extends BasePeerState implements PeerSta
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS);
        }
 
        /**
index 256cd86e2a7efae18ea12f92f4b1f9f45f59b38c..ca6d00f2d5ed6d3b59e1179be1fac1fc2a8bb5b5 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class ProblemPeerState extends BasePeerState implements PeerStateable {
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_UNKNOWN);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_UNKNOWN);
        }
 
        /**
index 7308b68bafcded88e188d8dc237ee530be0f34ad..30aa74d6cdfa40e14de1d214becc73528ca07e38 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\State\Peer;
 
 // Import application-specific stuff
-use Hub\Handler\RawData\BaseRawDataHandler;
+use Hub\Container\Socket\StorableSocket;
 
 // Import framework stuff
 use CoreFramework\State\Stateable;
@@ -41,7 +41,7 @@ class TransportEndpointGonePeerState extends BasePeerState implements PeerStatea
                parent::__construct(__CLASS__);
 
                // Set state name
-               $this->setStateName(BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT);
+               $this->setStateName(StorableSocket::SOCKET_ERROR_TRANSPORT_ENDPOINT);
        }
 
        /**
index 3afb47d131912b993055f4c78cb4375c07e69d57..06c072cd68dabb1ab10b33b281bba5a0b60613f4 100644 (file)
@@ -28,6 +28,66 @@ use CoreFramework\Generic\FrameworkInterface;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface StorableSocket extends FrameworkInterface {
+       // Error codes:
+       // - Socket raw data stream errors
+       const SOCKET_ERROR_UNKNOWN                    = 'unknown_error';              // Unknown error (should not happen)
+       const SOCKET_ERROR_TRANSPORT_ENDPOINT         = 'transport_endpoint';         // Transport endpoint has closed
+       const SOCKET_ERROR_INVALID_BASE64_MODULO      = 'base64_modulo';              // Length is not modulo 4
+       const SOCKET_ERROR_INVALID_BASE64_MESSAGE     = 'base64_message';             // Raw data is not Base64-encoded
+       const SOCKET_ERROR_UNHANDLED                  = 'unhandled_package';          // Unhandled raw data (not bad)
+       const SOCKET_ERROR_CONNECTION_REFUSED         = 'connection_refused';         // The name says it: connection refused
+       const SOCKET_ERROR_CONNECTION_TIMED_OUT       = 'connection_timed_out';       // The name says it: connection attempt has timed-out
+       const SOCKET_ERROR_OPERATION_IN_PROGRESS      = 'operation_in_progress';      // 'Operation now in progress'
+       const SOCKET_ERROR_OPERATION_ALREADY_PROGRESS = 'operation_already_progress'; // 'Operation already in progress'
+       const SOCKET_ERROR_RESOURCE_UNAVAILABLE       = 'resource_unavailable';       // 'Resource temporary unavailable'
+       const SOCKET_ERROR_NO_ROUTE_TO_HOST           = 'no_route_to_host';           // The name says it: no route to host
+       const SOCKET_ERROR_CONNECTION_RESET_BY_PEER   = 'connection_reset_by_peer';   // Connection reset by peer
+       const SOCKET_ERROR_BROKEN_PIPE                = 'broken_pipe';                // Broken pipe
+       const SOCKET_ERROR_PERMISSION_DENIED          = 'permission_denied';          // Permission denied
+       const SOCKET_ERROR_OPERATION_NOT_SUPPORTED    = 'operation_not_supported';    // 'Operation not supported'
+       const SOCKET_CONNECTED                        = 'connected';                  // Nothing errorous happens, socket is connected
+
+       /**
+        * Tries to bind the socket.
+        *
+        * @param       $bindAddress    Where to bind the socket to (e.g. Uni* socket file)
+        * @return      $result         Result from binding socket
+        * @throws      InvalidSocketException  If stored socket is invalid
+        */
+       function bindSocketTo ($bindAddress);
+
+       /**
+        * Tries to listen on the socket
+        *
+        * @return      $result         Result from listening on socket
+        * @throws      InvalidSocketException  If stored socket is invalid
+        */
+       function listenOnSocket ();
+
+       /**
+        * Tries to set non-blocking I/O on stored socket
+        *
+        * @return      $result         Result of changing to non-blocking I/O
+        * @throws      InvalidSocketException  If stored socket is invalid
+        */
+       function enableSocketNonBlocking ();
+
+       /**
+        * Some "getter" for peer address/port from stored socket
+        *
+        * @param       $peerAddress    Peer address being determined
+        * @param       $peerPort               Peer port being determined
+        * @return      $result                 Result from asking for peer address
+        * @throws      InvalidSocketException  If stored socket is invalid
+        */
+       function getSocketPeerName (&$peerAddress, &$peerPort);
+
+       /**
+        * Some "getter" for socket type of stored socket
+        *
+        * @return      $socketType             Socket type
+        */
+       function getSocketType ();
 
        /**
         * Checks whether the given Universal Node Locator matches with the one from package data
@@ -79,34 +139,17 @@ interface StorableSocket extends FrameworkInterface {
         * Getter for last socket error
         *
         * @return      $lastSocketError        Last socket error
-        * @throws      InvalidSocketException  If socket is valid
+        * @throws      InvalidSocketException  If stored socket is invalid
         */
        function getLastSocketError ();
 
        /**
-        * Tries to bind the socket.
-        *
-        * @param       $bindAddress    Where to bind the socket to (e.g. Uni* socket file)
-        * @return      $result         Result from binding socket
-        * @throws      InvalidSocketException  If socket is valid
-        */
-       function bindSocketTo ($bindAddress);
-
-       /**
-        * Tries to listen on the socket
-        *
-        * @return      $result         Result from listening on socket
-        * @throws      InvalidSocketException  If socket is valid
-        */
-       function listenOnSocket ();
-
-       /**
-        * Tries to set non-blocking I/O on stored socket
+        * Getter for last socket error message
         *
-        * @return      $result         Result of changing to non-blocking I/O
-        * @throws      InvalidSocketException  If socket is valid
+        * @return      $lastSocketErrorMessage Last socket error message
+        * @throws      InvalidSocketException  If stored socket is invalid
         */
-       function enableSocketNonBlocking ();
+       function getLastSocketErrorMessage ();
 
        /**
         * Handles socket error for given socket resource and peer data. This method
@@ -124,4 +167,13 @@ interface StorableSocket extends FrameworkInterface {
         */
        function handleSocketError ($method, $line, array $socketData);
 
+       /**
+        * Translates socket error codes into our own internal names which can be
+        * used for call-backs.
+        *
+        * @param       $errorCode      The error code from socket_last_error() to be translated
+        * @return      $errorName      The translated name (all lower-case, with underlines)
+        */
+       function translateSocketErrorCodeToName ($errorCode);
+
 }
diff --git a/core b/core
index 8d7422139a55477388fcd6a30a1ce41d83780e5e..6751244349667c1165f05a319f3d66d3f6781b40 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 8d7422139a55477388fcd6a30a1ce41d83780e5e
+Subproject commit 6751244349667c1165f05a319f3d66d3f6781b40