buffer_incoming = new Misc_Buffer($linebreak); $this->buffer_outgoing = new Misc_Buffer($linebreak); $this->socketHandler = new Socket_SocketHandler($socket); $this->id = $id; $this->group = $group; $this->protocol = $protocol; $this->is_server = FALSE; } /** * Calls parent destructor. * @return void */ function __destruct() { unset($this->socketHandler); } /** * @return string */ public function getProtocol() { return $this->protocol; } /** * @return string Connection Group */ public function getGroup() { return $this->group; } /** * @return int Connection ID */ public function getID() { return $this->id; } /** * Returns whether this connection is a listening socket or a general client connection socket. * @return boolean */ public function isServer() { return $this->is_server; } /** * Reads from SocketHandler, writes into buffer_incoming. * Returns a boolean that will indicate whether the socket is still okay. * @throws Exception_SocketException * @return boolean */ public function readToBuffer() { $data = $this->socketHandler->read(); if($data === "") return FALSE; $this->buffer_incoming->addData($data); return TRUE; } /** * Writes the buffer_outgoing to the SocketHandler. * Returns a boolean that will indicate whether the socket is still okay. * @throws Exception_SocketException * @return boolean */ public function writeFromBuffer() { while($this->buffer_outgoing->hasLines()) { $result = $this->socketHandler->write($this->buffer_outgoing->getNextLine()); if($result === FALSE) return FALSE; } return TRUE; } /** * Calls error() on Socket_SocketHandler. * @throws Socket_SocketExceptions * @return void */ public function handleSocketError() { $this->socketHandler->error(); } /** * Determines whether this ConnectionHandler has data to read. * @return boolean */ public function canRead() { return $this->buffer_incoming->hasLines(); } /** * Determines whether this ConnectionHandler has data to write. * @return boolean */ public function canWrite() { return $this->buffer_outgoing->hasLines(); } /** * Reads new data into buffer_incoming. * Returns a full line from buffer_incoming. * @return string */ public function read() { return $this->buffer_incoming->getNextLine(); } /** * Writes data into buffer_outgoing. * Sends data from buffer_outgoing to the SocketHandler. * @param $data * @return void */ public function write($data) { $this->buffer_outgoing->addData($data); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return ressource */ public function accept() { return $this->socketHandler->accept(); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return string */ public function getRemoteName() { return $this->socketHandler->getRemoteName(); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return string */ public function getLocalName() { return $this->socketHandler->getLocalName(); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return void */ public function close() { return $this->socketHandler->close(); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return void */ public function connect($address, $port) { return $this->socketHandler->connect($address, $port); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return void */ public function bind($address, $port) { return $this->socketHandler->bind($address, $port); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return void */ public function listen() { $this->is_server = TRUE; return $this->socketHandler->listen(); } /** * @see Socket_SocketHandler * @return boolean */ public function isConnected() { return $this->socketHandler->isConnected(); } /** * @see Socket_SocketHandler * @return boolean */ public function isListening() { return $this->socketHandler->isListening(); } /** * Calls SocketHandler * @see Socket_SocketHandler * @throws Exception_SocketException * @return ressource */ public function getSocket() { return $this->socketHandler->getSocket(); } /** * @return Socket_SocketHandler */ public function getSocketHandler() { return $this->socketHandler; } /** * Calls SocketHandler * @see Socket_SocketHandler * @return void */ public function hasBeenAccepted() { return $this->socketHandler->hasBeenAccepted(); } } ?>