//----------------------------------------------------------
// 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();
/**
* Setter for peer socket
*
- * @param $peerSocket The peer's socket
+ * @param $peerSocket The peer's socket
* @return void
*/
public final function setPeerSocket ($peerSocket) {
}
}
+ /**
+ * Getter for peer socket
+ *
+ * @return $peerSocket The peer's socket
+ */
+ public final function getPeerSocket () {
+ return $this->peerSocket;
+ }
+
/**
* Setter for connection timestamp only once
*
/**
* 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) {
/**
* 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
*/
$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