接收到数据后进行处理
@param $client_socket
@param $events
@param $arg
@return unknown_type
509239
function event_receive($client_socket, $events, $client_id)
    {
        $data = Stream::read($client_socket, $this->buffer_size);
        if($data !== false)
        {
            $this->protocol->onReceive($this, $client_id, 0, $data);
        }
        else
        {
            $this->close($client_id);
        }
    }
626981
function emit(eventName, id, args) {
  var js = "function () { window.socket.emit(\"" + eventName + "\"";

  // we're assuming args is an array of function arguments
  // if not, wrap it
  if (!(args instanceof Array)) {
    args = [args];
  }

  if (id) {
    js += ", " + id + ", " + JSON.stringify(args);
  }

  js += ");}";

  controlPage.evaluate(js);
}
99607
public EventBus emitAsync(Enum<?> event, Object... args) {
        return _emitWithOnceBus(eventContextAsync(event, args));
    }
1147922
private function dispatchEvent($event, $args = null)
    {
        return $this->onEventEmitterEnabled(function ($emitter) use($event, $args) {
            return $emitter->emit($event, ! is_array($args) ? [$args] : $args);
        });
    }
499237
public function triggerGroup(?array $events = [], ?array $args = null)
  {
    foreach($events as $callback) {
      if (is_callable($callback)) {
        call_user_func_array($callback, isset($args) ? $args : []);
      }
      else if (is_string($callback)) {
        $call = new $callback;
        call_user_func_array([$call, 'persist'], $args ?? []);
      }
    }
  }
888424
public function _dispatch($event, $args = array())
    {
        if($event != "onLog") {
            Log::d("Event " . $event, array('events'));
        }
        $eventResult = new EventResult();
        global $context;
        $buffer = array();
        if (!is_array($args)) {
            $args = array($args);
        }
        if (isset($this->handlers[$event]) && count($this->handlers[$event]) > 0) {
            $handlers = $this->handlers[$event];
            foreach ($handlers as $item) {
                $eventResult->addHandler($item);
                $result = $item->run($args);
                if($result !== false) {
                    $eventResult->addResult($result, $item);
                }
            }
        }
        return $eventResult;
    }
1223468
function ElementsEventHandler(socket) {
  var _this = this;
  //Call EventEmmiter _contructor_
  events.EventEmitter.call(this);
  this.socket = socket;

  // On every message event received by socket we get
  // an message event object like {event:, data:} 
  // we emit  a local event through an EventEmitter interface
  // with .event as event type and .data as
  // event data;
  this.socket.on('message', function(message, callback) {
    debug("Forwarding frontend message '%s', with data %j", message.event, message.data);
    if (message.event !== undefined) {
      _this.emit(message.event, message.data);
      if (typeof callback === 'function') {
        callback();
      }
    }
    if (message.event === "userinput" && message.scope !== undefined) {
      debug("userinput received: %s", JSON.stringify(message));
      _this.emit(message.scope, message.data);
    }
  });
  this.socket.on("disconnect", function() {
    delete(this.socket);
    _this.emit("disconnect");
  });
}
123113
public function add($fd, $flag, $func, $args = null)
    {
        $callback = function ($event, $socket) use ($fd, $func) {
            try {
                call_user_func($func, $fd);
            } catch (\Exception $e) {
                Worker::log($e);
                exit(250);
            } catch (\Error $e) {
                Worker::log($e);
                exit(250);
            }
        };
        switch ($flag) {
            case self::EV_SIGNAL:
                $event                   = new \EvSignal($fd, $callback);
                $this->_eventSignal[$fd] = $event;
                return true;
            case self::EV_TIMER:
            case self::EV_TIMER_ONCE:
                $repeat                             = $flag == self::EV_TIMER_ONCE ? 0 : $fd;
                $param                              = array($func, (array)$args, $flag, $fd, self::$_timerId);
                $event                              = new \EvTimer($fd, $repeat, array($this, 'timerCallback'), $param);
                $this->_eventTimer[self::$_timerId] = $event;
                return self::$_timerId++;
            default :
                $fd_key                           = (int)$fd;
                $real_flag                        = $flag === self::EV_READ ? \Ev::READ : \Ev::WRITE;
                $event                            = new \EvIo($fd, $real_flag, $callback);
                $this->_allEvents[$fd_key][$flag] = $event;
                return true;
        }

    }
1276090
function sendAll($client_id = null, $data)
    {
        foreach ($this->client_sock as $k => $sock)
        {
            if ($client_id and $k == $client_id) continue;
            $this->sendData($sock, $data);
        }
    }
82128
public function triggerEvent($event, $args = [])
    {
        /** @var \Windwalker\Event\Dispatcher $dispatcher */
        $dispatcher = $this->container->get('dispatcher');

        $dispatcher->triggerEvent($event, $args);

        return $event;
    }
874153
function () {
    clearTimeout(timeoutId);
    var args = [];
    for (var index = 0, length = arguments.length; index < length; index++) {
      args.push(arguments[index]);
    }
    self.socketEvent = {
      namespace: action.namespace,
      eventType: action.eventType,
      args: args
    };
    callback(null, self.socketEvent);
  }
534078
function(events, args) {
    let ev,
        i = -1,
        l = events.length,
        a1 = args[0],
        a2 = args[1],
        a3 = args[2];
    switch (args.length) {
        case 0:
            while (++i < l) (ev = events[i]).callback.call(ev.ctx);
            return;
        case 1:
            while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1);
            return;
        case 2:
            while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2);
            return;
        case 3:
            while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3);
            return;
        default:
            while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
            return;
    }
}
357278
function Server(/* [options], [connectionListener] */) {
    events.EventEmitter.call(this);
    var self = this;

    var options;
    if (typeof arguments[0] === 'function') {
        options = {};
        this.on('connection', arguments[0]);
    } else {
        options = arguments[0] || {};
        if (typeof arguments[1] === 'function') {
            this.on('connection', arguments[1]);
        }
    }

    this._server = net.createServer(options, this._handler.bind(this));
    this._server.on('listening', function () {
        self.emit('listening');
    })
    this._server.on('close', function () {
        self.emit('close');
    })
    this._server.on('error', function (e) {
        self.emit('error', e);
    });
}
459143
public EventBus emitSync(ActEvent event, Object... args) {
        return _emitWithOnceBus(eventContextSync(event, args));
    }
427078
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                parent::onQuickFormEvent($event, $arg, $caller);
                if ($caller->isNoSubmitButton($arg[0])){
                    //need this to bypass client validation
                    //for buttons that submit but do not process the
                    //whole form.
                    $onClick = $this->getAttribute('onclick');
                    $skip = 'skipClientValidation = true;';
                    $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
                    $this->updateAttributes(array('onclick'=>$onClick));
                }
                return true;
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);

    }
872603
public function onReadUdp($stream = null, $events = 0, $arg = null)
    {
        if (Daemon::$process->reload) {
            return false;
        }

        if ($this->pool->maxConcurrency) {
            if ($this->pool->count() >= $this->pool->maxConcurrency) {
                $this->overload = true;
                return false;
            }
        }

        $host = null;
        do {
            $l = @socket_recvfrom($this->fd, $buf, 10240, MSG_DONTWAIT, $host, $port);
            if (!$l) {
                break;
            }
            $key = '[' . $host . ']:' . $port;
            if (!isset($this->portsMap[$key])) {
                if ($this->pool->allowedClients !== null) {
                    if (!self::netMatch($this->pool->allowedClients, $host)) {
                        Daemon::log('Connection is not allowed (' . $host . ')');
                    }
                    continue;
                }
                $class = $this->pool->connectionClass;
                $conn = new $class(null, $this->pool);
                $conn->setDgram(true);
                $conn->onWriteEv(null);
                $conn->setPeername($host, $port);
                $conn->setParentSocket($this);
                $this->portsMap[$key] = $conn;
                $conn->timeoutRef = setTimeout(function ($timer) use ($conn) {
                    $conn->finish();
                    $timer->finish();
                }, $conn->timeout * 1e6);
                $conn->onUdpPacket($buf);
            } else {
                $conn = $this->portsMap[$key];
                $conn->onUdpPacket($buf);
                Timer::setTimeout($conn->timeoutRef);
            }
        } while (true);
        return $host !== null;
    }
972130
function eventLoop()
    {
        // Socket not connected at all?
        if($this->socket == null) {
            return;
        }

        // Server closed connection?
        if(feof($this->socket)) {
            stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
            $this->socket = null;
            return;
        }

        // See if there's data waiting?
        $byte = $this->readBytes(1, true);
        if(strlen($byte) > 0) {
            $cmd = ord($byte);

            // Read the length of packet..
            $bytes=0;
            $multiplier=1;

            do {
                $t_byte = ord($this->readBytes(1,true));
                $bytes+=($t_byte & 127)*$multiplier;
                $multiplier*=128;

                if($multiplier>128*128*128) {
                    break;
                }
            } while( ($t_byte&128) != 0);

            //
            $payload = "";
            if($bytes>0)
                $payload = $this->readBytes($bytes, false);

            switch( $cmd & 0xf0 ) {
                case 0xd0:      // PINGRESP
                    $this->debugMessage("Ping response received");
                    break;

                case 0x30:      // PUBLISH
                    $msg_qos = ( $cmd & 0x06 ) >> 1; // QoS = bits 1 & 2
                    $this->processMessage( $payload, $msg_qos );
                    break;

                case 0x40:      // PUBACK
                    $msg_qos = ( $cmd & 0x06 ) >> 1; // QoS = bits 1 & 2
                    $this->processPubAck( $payload, $msg_qos );
                    break;
            }

            $this->timeSincePingReq = time();
            $this->timeSincePingResp = time();
        }

        if( $this->timeSincePingReq < (time() - $this->keepAlive ) ) {
            $this->debugMessage("Nothing received for a while, pinging..");
            $this->sendPing();
        }


        if( $this->timeSincePingResp < (time() - ($this->keepAlive*2)) ) {
            $this->debugMessage("Not seen a package in a while, reconnecting..");
            stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
            $this->socket = null;
        }

    }