/** * Free from loop */ public function __destruct() { if (!empty($this->event)) { event_del($this->event); event_free($this->event); unset($this->event); } }
/** * Remove signal handler. * * @param $signal */ public function removeSignal($signal) { if (isset($this->_signalEvents[$signal])) { $event = $this->_signalEvents[$signal]; event_del($event); unset($this->_signalEvents[$signal]); } }
/** * 关闭socket * @param $socket * @param $event * @return unknown_type */ static function close($socket, $event = null) { if ($event) { event_del($event); event_free($event); } fclose($socket); }
public function removeStream($stream) { if (isset($this->events[(int) $stream])) { $event = $this->events[(int) $stream]; event_del($event); event_free($event); unset($this->events[(int) $stream]); } }
public function close() { $this->log("close()"); foreach (array_keys($this->clients) as $id) { $this->disconnectClient($id); } $this->clients = array(); stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR); event_del($this->socket_event); event_free($this->socket_event); $this->socket_event = null; }
private function service($connection, $flag, $base) { $connectionId = $this->getIdByConnection($connection); $buffer = event_buffer_new($connection, array($this, 'onRead'), array($this, 'onWrite'), array($this, 'onError'), $connectionId); event_buffer_base_set($buffer, $this->base); event_buffer_watermark_set($buffer, EV_READ, 0, 0xffffff); event_buffer_priority_set($buffer, 10); event_buffer_enable($buffer, EV_READ | EV_WRITE | EV_PERSIST); $this->buffers[$connectionId] = $buffer; event_del($this->events[$connectionId]); event_free($this->events[$connectionId]); unset($this->events[$connectionId]); }
public function onRead($socket, $event, $args) { while ($chunk = fread($socket, 4096)) { $this->response .= $chunk; } if (feof($socket)) { fclose($socket); event_del($args[0]); if ($this->config['callback']) { call_user_func($this->config['callback'], array('response' => $this->response)); } } }
public function onRequest($clientSocket, $events, $arg) { try { //$transport = new TBufferedTransport(new TNonblockingSocket($clientSocket)); $transport = new TNonblockingSocket($clientSocket); call_user_func($this->callback, $transport); } catch (Exception $e) { \event_del($arg[0]); \event_free($arg[0]); // close socket @stream_socket_shutdown($clientSocket, STREAM_SHUT_RDWR); @fclose($clientSocket); return; } }
/** * Free from loop and close the stream */ public function __destruct() { if (!empty($this->ev_read)) { event_del($this->ev_read); event_free($this->ev_read); unset($this->ev_read); } if (!empty($this->ev_write)) { event_del($this->ev_write); event_free($this->ev_write); unset($this->ev_write); } if (!empty($this->stream)) { fclose($this->stream); unset($this->stream); } }
/** * 关闭socket * @param $socket * @param $event * @return unknown_type */ function sw_socket_close($socket, $event = null) { if ($event) { event_del($event); event_free($event); } stream_socket_shutdown($socket, STREAM_SHUT_RDWR); fclose($socket); }
public function closeConnection($connId) { if (Daemon::$settings['logevents']) { Daemon::log('[WORKER ' . Daemon::$worker->pid . '] closeConnection(' . $connId . ').'); } if (!isset($this->buf[$connId])) { return; } if (isset($this->readEvents[$connId])) { event_del($this->readEvents[$connId]); event_free($this->readEvents[$connId]); unset($this->readEvents[$connId]); } event_buffer_free($this->buf[$connId]); if (Daemon::$useSockets) { socket_close(Daemon::$worker->pool[$connId]); } else { fclose(Daemon::$worker->pool[$connId]); } unset(Daemon::$worker->pool[$connId]); unset(Daemon::$worker->poolApp[$connId]); unset(Daemon::$worker->readPoolState[$connId]); unset($this->buf[$connId]); unset($this->poolQueue[$connId]); unset(Daemon::$worker->poolState[$connId]); }
public function cancelTimer($signature) { if (isset($this->timers[$signature])) { $timer = $this->timers[$signature]; $timer->cancelled = true; event_del($timer->resource); event_free($timer->resource); unset($this->timers[$signature]); } }
public function removeStream($stream) { $id = (int) $stream; if (isset($this->events[$id])) { $event = $this->events[$id]; unset($this->events[$id], $this->flags[$id], $this->readCallbacks[$id], $this->writeCallbacks[$id]); event_del($event); event_free($event); } }
/** * Disable all events of sockets * @return void */ public function disable() { return; // possible critical bug for (; sizeof($this->socketEvents);) { if (!is_resource($ev = array_pop($this->socketEvents))) { continue; } event_del($ev); event_free($ev); } }
function remove($event) { $ev = $event->handle; event_del($ev); return $this; }
/** * 删除所有定时器 * @return void */ public function clearAllTimer() { foreach ($this->_eventTimer as $task_data) { event_del($task_data[2]); } $this->_eventTimer = array(); }
/** * Close the connection * @param integer Connection's ID * @return void */ public function close() { if (!isset($this->buffer)) { return; } if (isset($this->event)) { event_del($this->event); event_free($this->event); $this->event = null; } event_buffer_free($this->buffer); $this->buffer = null; if (isset($this->fd)) { $this->closeFd(); } }
public function __destruct() { if (is_resource($this->ev)) { event_del($this->ev); event_free($this->ev); } $this->onDestruct(); }
private function become_intern($request_message) { $intern = new Prefork_Intern($this); $pid = $this->fork_process(); if ($pid === 0) { // Interns only past this point event_base_loopbreak($this->event_base); event_base_reinit($this->event_base); foreach ($this->events as $i => $event) { event_del($event); event_free($event); unset($this->events[$i]); } event_base_free($this->event_base); $intern->start_request($request_message); $this->intern = $intern; return true; } $this->intern_pid = $pid; if (!$this->single_interns) { $this->make_offer(); } return false; }
/** * {@inheritdoc} */ public function cancel(SocketEventInterface $socket) { $id = (int) $socket->getResource(); if (isset($this->sockets[$id], $this->events[$id]) && $socket === $this->sockets[$id]) { event_del($this->events[$id]); $this->pending[$id] = false; } }
/** * Close the connection * @param integer Connection's ID * @return void */ public function closeConnection($connId) { if (Daemon::$config->logevents->value) { Daemon::$process->log('closeConnection(' . $connId . ').'); } if (!isset($this->buf[$connId])) { return; } if (isset($this->readEvents[$connId])) { event_del($this->readEvents[$connId]); event_free($this->readEvents[$connId]); unset($this->readEvents[$connId]); } event_buffer_free($this->buf[$connId]); if (isset(Daemon::$process->pool[$connId])) { if (Daemon::$useSockets) { socket_close(Daemon::$process->pool[$connId]); } else { fclose(Daemon::$process->pool[$connId]); } } unset(Daemon::$process->pool[$connId]); unset(Daemon::$process->poolApp[$connId]); unset(Daemon::$process->readPoolState[$connId]); unset($this->buf[$connId]); unset($this->poolQueue[$connId]); unset($this->poolState[$connId]); unset(Daemon::$process->poolState[$connId]); }
private function _clearSend() { if (!is_null($this->_sendEvent)) { event_del($this->_sendEvent); event_free($this->_sendEvent); $this->_sendEvent = NULL; } $this->_sendBuf = ''; while (!empty($this->_sendBufCallbacks)) { $callback = array_shift($this->_sendBufCallbacks); $callback->func && call_user_func($callback->func, $this->_name, FALSE); // FALSE indicates send fails } }
/** * {@inheritDoc} */ public function disable($watcherId) { if (empty($this->watchers[$watcherId])) { return; } $watcher = $this->watchers[$watcherId]; if (!$watcher->isEnabled) { return; } $watcher->isEnabled = false; $this->keepAliveCount -= $watcher->keepAlive; switch ($watcher->type) { case Watcher::IMMEDIATE: unset($this->immediates[$watcherId]); break; case Watcher::IO_READER: // fallthrough // fallthrough case Watcher::IO_WRITER: // fallthrough // fallthrough case Watcher::SIGNAL: // fallthrough // fallthrough case Watcher::TIMER_ONCE: // fallthrough // fallthrough case Watcher::TIMER_REPEAT: \event_del($watcher->eventResource); break; } }
/** * 删除fd的某个事件 * @see \Man\Core\Events\BaseEvent::del() */ public function del($fd, $flag) { $fd_key = (int) $fd; switch ($flag) { // 读事件 case \Man\Core\Events\BaseEvent::EV_READ: case \Man\Core\Events\BaseEvent::EV_WRITE: if (isset($this->allEvents[$fd_key][$flag])) { event_del($this->allEvents[$fd_key][$flag]); } unset($this->allEvents[$fd_key][$flag]); if (empty($this->allEvents[$fd_key])) { unset($this->allEvents[$fd_key]); } case \Man\Core\Events\BaseEvent::EV_SIGNAL: if (isset($this->eventSignal[$fd_key])) { event_del($this->eventSignal[$fd_key]); } unset($this->eventSignal[$fd_key]); } return true; }
public function closeSockets() { foreach (Daemon::$socketEvents as $k => $ev) { event_del($ev); event_free($ev); unset($this->socketEvents[$k]); } foreach (Daemon::$sockets as $k => &$s) { if (Daemon::$useSockets) { socket_close($s[0]); } else { fclose($s[0]); } unset(Daemon::$sockets[$k]); } }
/** * Update the ext-libevent event resource for this stream to stop listening to * the given event type, or remove it entirely if it's no longer needed. * * @param resource $stream * @param integer $flag EV_READ or EV_WRITE */ private function unsubscribeStreamEvent($stream, $flag) { $key = (int) $stream; $flags = $this->streamFlags[$key] &= ~$flag; if (0 === $flags) { $this->removeStream($stream); return; } $event = $this->streamEvents[$key]; event_del($event); event_set($event, $stream, EV_PERSIST | $flags, $this->streamCallback); event_add($event); }
function do_read($fd, $what, $arg) { $recv_buf = ''; while (1) { $buffer = fread($fd, 8192); #echo "123\n"; if ($buffer === '' || $buffer === false) { break; } $recv_buf .= $buffer; } #echo 'I have received that : '.$recv_buf; #fwrite(SwooleController::$client, " OK\n"); $write_event = event_new(); SwooleController::$write_event[$arg] = $write_event; event_set(SwooleController::$write_event[$arg], $fd, EV_WRITE | EV_PERSIST, 'do_write', $arg); event_base_set(SwooleController::$write_event[$arg], SwooleController::$event_base); event_add(SwooleController::$write_event[$arg]); #fclose(SwooleController::$client); event_del(SwooleController::$read_event[$arg]); }
private function collectGarbage() { $this->garbage = []; $this->isGCScheduled = FALSE; event_del($this->gcEvent); }
public function __destruct() { event_del($this->ev); event_free($this->ev); }
/** * {@inheritdoc} */ public function cancel(Io $io) { $id = (int) $io->getResource(); if (isset($this->sockets[$id], $this->events[$id]) && $io === $this->sockets[$id]) { event_del($this->events[$id]); $this->pending[$id] = false; } }