示例#1
0
 /**
  * 关闭socket
  * @param $socket
  * @param $event
  * @return unknown_type
  */
 static function close($socket, $event = null)
 {
     if ($event) {
         event_del($event);
         event_free($event);
     }
     fclose($socket);
 }
示例#2
0
 /**
  * Free from loop
  */
 public function __destruct()
 {
     if (!empty($this->event)) {
         event_del($this->event);
         event_free($this->event);
         unset($this->event);
     }
 }
 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]);
     }
 }
示例#4
0
 public function free()
 {
     if (is_resource($this->ev)) {
         event_del($this->ev);
         event_free($this->ev);
     }
     if (isset($this->conn)) {
         $this->conn->freeRequest($this);
     }
 }
示例#5
0
 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 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;
     }
 }
示例#8
0
 /**
  * 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);
     }
 }
示例#9
0
 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);
     }
 }
示例#10
0
 /**
  * Unregister a stream
  * 
  * @param   resource    $stream
  * @param   integer     $type
  * @return  this
  */
 public function remove($stream, $type = null)
 {
     $i = (int) $stream;
     $type = is_null($type) ? array(self::READ, self::WRITE) : array($type);
     // using libevent
     if ($this->evbase) {
         foreach ($type as $t) {
             if (isset($this->streams[$t])) {
                 event_del($this->streams[$t][$i]);
                 event_free($this->streams[$t][$i]);
             }
         }
     } else {
         foreach ($type as $t) {
             unset($this->streams[$t][$i], $this->handlers[$t][$i]);
         }
     }
     return $this;
 }
示例#11
0
 /**
  * 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);
     }
 }
示例#12
0
 /**
  * {@inheritdoc}
  */
 public function cancelTimer(TimerInterface $timer)
 {
     if ($this->isTimerActive($timer)) {
         $event = $this->timerEvents[$timer];
         event_del($event);
         event_free($event);
         $this->timerEvents->detach($timer);
     }
 }
示例#13
0
文件: Php.php 项目: tempbottle/zphp
 private function _closeSocket($socket, $event = null)
 {
     if ($event) {
         \event_del($event);
         \event_free($event);
     }
     \stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
     \fclose($socket);
 }
示例#14
0
 /**
  * Destroy event handle
  *
  * @return void
  */
 private function destroy()
 {
     if ($this->handle) {
         event_del($this->handle);
         event_free($this->handle);
         $this->handle = null;
     }
 }
示例#15
0
 /**
  * @codeCoverageIgnore
  */
 public function __destruct()
 {
     foreach ($this->events as $event) {
         event_free($event);
     }
 }
示例#16
0
 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 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]);
     }
 }
示例#18
0
 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]);
     }
 }
示例#19
0
 /**
  * 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();
     }
 }
示例#20
0
 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;
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     for ($this->timers->rewind(); $this->timers->valid(); $this->timers->next()) {
         event_free($this->timers->getInfo());
     }
     $this->timers = new ObjectStorage();
 }
示例#22
0
 public function kill()
 {
     if ($this->process) {
         if ($this->busy) {
             $this->parent->requeue($this->task);
             $this->busy = false;
         }
         proc_close($this->process);
         if ($this->event) {
             event_del($this->event);
             event_free($this->event);
         }
         $this->process = null;
     }
 }
示例#23
0
/**
 * 关闭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);
}
示例#24
0
 public function stop()
 {
     if (!$this->_started) {
         return;
     }
     self::$_logger->info('Server stops.  The event loop ends.');
     event_base_loopbreak($this->_eventBase);
     if ($this->_listenEvent) {
         event_del($this->_listenEvent);
         event_free($this->_listenEvent);
         $this->_listenEvent = NULL;
     }
     if ($this->_sock) {
         socket_close($this->_sock);
         $this->_sock = NULL;
     }
     foreach ($this->_streams as $stream) {
         $stream->forceClose();
     }
     // TODO: need to clear the streams too
     foreach ($this->_signalEvents as $signo => $event) {
         event_del($event);
         event_free($event);
         unset($this->_signalEvents[$signo]);
     }
     $this->_started = FALSE;
 }
示例#25
0
 public function __destruct()
 {
     if (is_resource($this->ev)) {
         event_del($this->ev);
         event_free($this->ev);
     }
     $this->onDestruct();
 }
示例#26
0
 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
     }
 }
示例#27
0
 /**
  * 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]);
 }
示例#28
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     foreach ($this->events as $event) {
         event_free($event);
     }
     $this->events = [];
     $this->sockets = [];
     $this->pending = [];
 }
示例#29
0
 public function __destruct()
 {
     event_del($this->ev);
     event_free($this->ev);
 }
示例#30
0
 public function free()
 {
     unset(Timer::$list[$this->id]);
     if (is_resource($this->ev)) {
         event_timer_del($this->ev);
         event_free($this->ev);
     }
 }