public function read() { AirD::Log(AirD::LOGTYPE_INTERNAL, "socketServer's read", true); $client = new $this->client_class(parent::accept()); $this->on_accept($client); return $client; }
public function __destruct() { AirD::Log(AirD::LOGTYPE_INTERNAL, "SocketBase's destructor (FD " . (int) $this->socket . ")", true); if (is_resource($this->socket)) { $this->close(); } }
function __autoload($sClass) { AirD::Log(AirD::LOGTYPE_INTERNAL, "Loading " . $sClass); include "./src/" . $sClass . ".php"; if (!class_exists($sClass)) { AirD::Log(AirD::LOGTYPE_INTERNAL, "Loaded " . $sClass . " as a file, but class still doesn't exist. Aiee."); } }
public function read($length = 4096) { try { $this->read_buffer .= parent::read($length); $this->on_read(); } catch (socketException $e) { AirD::Log(AirD::LOGTYPE_INTERNAL, "Exception caught while reading from socket " . (int) $this->socket . ": " . $e->getMessage()); $old_socket = (int) $this->socket; $this->close(); $this->socket = $old_socket; $this->disconnected = true; $this->on_disconnect(); } }
public function __construct($socket) { AirD::Log(AirD::LOGTYPE_INTERNAL, "socketServerClient's constructor", true); $this->socket = $socket; if (!is_resource($this->socket)) { throw new socketException("Invalid socket or resource"); } elseif (!socket_getsockname($this->socket, $this->local_addr, $this->local_port)) { throw new socketException("Could not retrieve local address & port: " . socket_strerror(socket_last_error($this->socket))); } elseif (!socket_getpeername($this->socket, $this->remote_address, $this->remote_port)) { throw new socketException("Could not retrieve remote address & port: " . socket_strerror(socket_last_error($this->socket))); } $this->on_connect(); $this->set_non_block(true); SocketEngine::AddFd($this); }
public function shouldDestroy() { if (!$this->oHTTPClient && time() - $this->iHTTPDisconnected > 10) { AirD::Log(AirD::LOGTYPE_IRC, "Disconnected IRC session or abandoned IRC session (TS: " . $this->iHTTPDisconnected . ")"); $this->Destroy(); return true; } return parent::shouldDestroy(); }
/** Removes a given listmode mask from the channel. * @param cModeChar The mode character to unset ('b') * @param sValue The mask to remove (e.g. 'w00t!is@the.greatest). */ public function UnsetListMode($cModeChar, $sValue) { AirD::Log(AirD::LOGTYPE_IRC, "UnsetListMode: " . $cModeChar . ": " . $sValue, true); unset($this->aModes[$cModeChar][$sValue]); }
public function on_timer() { $idle_time = time() - $this->last_action; $total_time = time() - $this->accepted; if ($this->streaming_client && $this->irc_client) { $this->irc_client->send_script('chat.onSetNumberOfUsers(' . count(AirD::$aIRCClients) . ');'); } if (($total_time > $this->max_total_time || $idle_time > $this->max_idle_time) && !$this->streaming_client) { AirD::Log(AirD::LOGTYPE_HTTP, "TIMING OUT CLIENT"); $this->on_disconnect(); $this->Destroy(); } }
public function read() { AirD::Log(AirD::LOGTYPE_INTERNAL, "HTTPServer's read", true); parent::read(); AirD::Log(AirD::LOGTYPE_INTERNAL, "After HTTPServer's read", true); }
public static function process() { // if socketClient is in write set, and $socket->connecting === true, set connecting to false and call on_connect $read_set = SocketEngine::create_read_set(); $write_set = SocketEngine::create_write_set(); $exception_set = SocketEngine::create_exception_set(); $event_time = time(); while (($events = socket_select($read_set, $write_set, $exception_set, null)) !== false) { AirD::Log(AirD::LOGTYPE_INTERNAL, "Top of main loop.", true); if ($events > 0) { AirD::Log(AirD::LOGTYPE_INTERNAL, "Processing " . $events . " socket events", true); foreach ($read_set as $socket) { AirD::Log(AirD::LOGTYPE_INTERNAL, "Processing a read event for " . (int) $socket, true); SocketEngine::$clients[(int) $socket]->read(); } foreach ($write_set as $socket) { $socket = SocketEngine::get_class($socket); if (is_subclass_of($socket, 'socketClient')) { if ($socket->connecting === true) { $socket->on_connect(); $socket->connecting = false; } $socket->do_write(true); } } foreach ($exception_set as $socket) { $socket = SocketEngine::get_class($socket); if (is_subclass_of($socket, 'socketClient')) { $socket->on_disconnect(); if (isset(SocketEngine::$clients[(int) $socket->socket])) { unset(SocketEngine::$clients[(int) $socket->socket]); } } } } if (time() - $event_time > 1) { // only do this if more then a second passed, else we'd keep looping this for every bit recieved foreach (SocketEngine::$clients as $socket) { $socket->on_timer(); } $event_time = time(); } SocketEngine::clean_sockets(); $read_set = SocketEngine::create_read_set(); $write_set = SocketEngine::create_write_set(); $exception_set = SocketEngine::create_exception_set(); } }