Esempio n. 1
0
 public function inheritFromRequest($req, $appInstance)
 {
     $connId = $req->attrs->connId;
     unset(Daemon::$worker->queue[$connId . '-' . $req->attrs->id]);
     $this->buf[$connId] = $appInstance->buf[$connId];
     unset($appInstance->buf[$connId]);
     unset($appInstance->poolState[$connId]);
     $set = event_buffer_set_callback($this->buf[$connId], $this->directReads ? NULL : array($this, 'onReadEvent'), array($this, 'onWriteEvent'), array($this, 'onFailureEvent'), array($connId));
     unset(Daemon::$worker->readPoolState[$connId]);
     $this->poolState[$connId] = array();
     $this->sessions[$connId] = new WebSocketSession($connId, $this);
     $this->sessions[$connId]->clientAddr = $req->attrs->server['REMOTE_ADDR'];
     $this->sessions[$connId]->server = $req->attrs->server;
     $this->sessions[$connId]->firstline = TRUE;
     $this->sessions[$connId]->stdin("\r\n" . $req->attrs->inbuf);
 }
Esempio n. 2
0
 /**
  * Called when a request to HTTP-server looks like WebSocket handshake query.
  * @return void
  */
 public function inheritFromRequest($req, $pool)
 {
     $oldConn = $req->conn;
     if ($req instanceof Request) {
         $req->free();
     }
     if (!$oldConn) {
         return false;
     }
     $class = $this->connectionClass;
     $conn = new $class(null, $oldConn->id, $this);
     $conn->fd = $oldConn->fd;
     $this->list[$oldConn->id] = $conn;
     $conn->buffer = $oldConn->buffer;
     $conn->fd = $oldConn->fd;
     unset($oldConn->buffer);
     unset($oldConn->fd);
     $pool->removeConnection($oldConn->id);
     $set = event_buffer_set_callback($conn->buffer, array($conn, 'onReadEvent'), array($conn, 'onWriteEvent'), array($conn, 'onFailureEvent'));
     $conn->addr = $req->attrs->server['REMOTE_ADDR'];
     $conn->server = $req->attrs->server;
     $conn->firstline = true;
     $conn->onInheritanceFromRequest($req);
 }
Esempio n. 3
0
 private function monitor($conn, $buffer)
 {
     event_buffer_set_callback($buffer, [$this, 'readcb'], null, [$this, 'errorcb'], $conn);
     event_buffer_timeout_set($buffer, 1200, 1200);
     event_buffer_watermark_set($buffer, EV_READ, 1, null);
     event_buffer_enable($buffer, EV_READ | EV_PERSIST | EVLOOP_NONBLOCK);
     unset($this->unauthorized[(int) $conn]);
     $this->buffers[(int) $conn] = $buffer;
 }
Esempio n. 4
0
 public function read_request_header()
 {
     $header = event_buffer_read($this->offer_event, 4);
     $length = current(unpack('N', $header));
     if ($length > $this->max_message_length) {
         error_log("Worker {$this->worker_pid} received request length {$length}, aborting");
         exit(0);
     }
     event_buffer_watermark_set($this->offer_event, EV_READ, $length, $length);
     event_buffer_set_callback($this->offer_event, array($this, 'read_request'), null, array($this, 'read_request_error'), $length);
     event_buffer_enable($this->offer_event, EV_READ);
 }
Esempio n. 5
0
 /**
  * Sets or changes existing callbacks for the buffered event.
  *
  * @see event_buffer_set_callback
  *
  * @throws EventException
  *
  * @param callable|null $readcb 
  * Callback to invoke where there is data to read, or NULL if no callback is desired.
  * function(resource $buf, array $args(CLibEventBuffer $e, mixed $arg)){}
  * 
  * @param callable|null $writecb 
  * Callback to invoke where the descriptor is ready for writing, or NULL if no callback is desired.
  * function(resource $buf, array $args(CLibEventBuffer $e, mixed $arg)){}
  * 
  * @param callable $errorcb 
  * Callback to invoke where there is an error on the descriptor, cannot be NULL.
  * function(resource $buf, int $what, array $args(CLibEventBuffer $e, mixed $arg)){}
  * 
  * @param mixed $arg [optional] 
  * An argument that will be passed to each of the callbacks.
  * 
  *
  * @return EventBuffer
  */
 public function setCallback($readcb, $writecb, $errorcb, $arg = null)
 {
     if (!event_buffer_set_callback($this->resource, $readcb, $writecb, $errorcb, array($this, $arg))) {
         throw $this->exception('Could not set buffered event callbacks (event_buffer_set_callback).');
     }
     return $this;
 }