]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/class_HubPeer.php
Code syncronized with shipsimu code base
[hub.git] / application / hub / main / class_HubPeer.php
index a457b1e1a8ff625cd573820e83796dff9306cc80..c257bf2f7c2144660c51c39f44317064fbc5d8e6 100644 (file)
@@ -124,23 +124,17 @@ class HubPeer extends BaseFrameworkSystem {
        //----------------------------------------------------------
        //                              Exceptions
        //----------------------------------------------------------
-       const EXCEPTION_PEER_SOCKET_INVALID     = 0x200;
-       const EXCEPTION_PEER_IP_CHANGED         = 0x201;
+       const EXCEPTION_PEER_SOCKET_INVALID             = 0x200;
+       const EXCEPTION_PEER_IP_CHANGED                 = 0x201;
        const EXCEPTION_PEER_SOCKET_BROKEN              = 0x202;
        //----------------------------------------------------------
 
        /**
         * The private constructor
         */
-       private function __construct () {
+       protected function __construct () {
                // Call parent constructor
-               parent::constructor(__CLASS__);
-
-               // Set description
-               $this->setPartDescr("Hub-Peer");
-
-               // Set unique ID
-               $this->createUniqueID();
+               parent::__construct(__CLASS__);
 
                // Tidy up a little
                $this->removeSystemArray();
@@ -192,7 +186,7 @@ class HubPeer extends BaseFrameworkSystem {
        /**
         * Setter for peer socket
         *
-        * @param               $peerSocket             The peer's socket
+        * @param       $peerSocket             The peer's socket
         * @return      void
         */
        public final function setPeerSocket ($peerSocket) {
@@ -203,6 +197,15 @@ class HubPeer extends BaseFrameworkSystem {
                }
        }
 
+       /**
+        * Getter for peer socket
+        *
+        * @return      $peerSocket             The peer's socket
+        */
+       public final function getPeerSocket () {
+               return $this->peerSocket;
+       }
+
        /**
         * Setter for connection timestamp only once
         *
@@ -340,7 +343,7 @@ class HubPeer extends BaseFrameworkSystem {
        /**
         * Disconnects the peer with a special reason (status)
         *
-        * @param               $reason         The special reason
+        * @param       $reason         The special reason
         * @return      void
         */
        public final function disconnectWithReason ($reason) {
@@ -361,7 +364,7 @@ class HubPeer extends BaseFrameworkSystem {
        /**
         * Sends a specified message to the peer's socket
         *
-        * @param               $message                The special message
+        * @param       $message                The special message
         * @return      void
         * @throws      BrokenPipeException             If a pipe to a socket peer is lost
         */
@@ -378,6 +381,17 @@ class HubPeer extends BaseFrameworkSystem {
                        $this->getValidatedIP()
                ));
 
+               // Is the socket still valid?
+               if (!is_resource($this->peerSocket)) {
+                       // The socket is no longer valid!
+                       throw new BrokenPipeException (
+                               array(
+                                       'this'  => $this,
+                                       'code'  => socket_last_error()
+                               ), self::EXCEPTION_PEER_SOCKET_BROKEN
+                       );
+               }
+
                // Send it to the peer
                if (socket_write($this->peerSocket, $message."\n") !== false) {
                        // Set the timestamp and message