Exemple #1
0
            $res = $input->readLine(EventBuffer::EOL_CRLF);
            if (is_null($res)) {
                break;
            }
            $data .= $res;
        }
        var_dump($data);
    }
    public function echoEventCallback($bev, $events, $ctx)
    {
        if ($events & EventBufferEvent::ERROR) {
            echo "Error from bufferevent\n";
        }
        if ($events & (EventBufferEvent::EOF | EventBufferEvent::ERROR)) {
            $bev->free();
            $error_no = EventUtil::getLastSocketErrno();
            $error_msg = EventUtil::getLastSocketError();
            $log = "line: " . __LINE__ . ", {$error_msg} ({$error_no})";
            var_dump($log);
        }
    }
}
$port = 9808;
if ($argc > 1) {
    $port = (int) $argv[1];
}
if ($port <= 0 || $port > 65535) {
    exit("Invalid port");
}
$l = new MyListener($port);
$l->run();
Exemple #2
0
            exit(1);
        }
        $this->listener->setErrorCallback(array($this, "accept_error_cb"));
    }
    public function dispatch()
    {
        $this->base->dispatch();
    }
    // This callback is invoked when there is data to read on $bev
    public function acceptConnCallback($listener, $fd, $address, $ctx)
    {
        // We got a new connection! Set up a bufferevent for it. */
        $base = $this->base;
        $this->conn[] = new MyListenerConnection($base, $fd);
    }
    public function accept_error_cb($listener, $ctx)
    {
        $base = $this->base;
        fprintf(STDERR, "Got an error %d (%s) on the listener. " . "Shutting down.\n", EventUtil::getLastSocketErrno(), EventUtil::getLastSocketError());
        $base->exit(NULL);
    }
}
$port = 9808;
if ($argc > 1) {
    $port = (int) $argv[1];
}
if ($port <= 0 || $port > 65535) {
    exit("Invalid port");
}
$l = new MyListener($port);
$l->dispatch();