watch() 공개 정적인 메소드

public static watch ( $fd, $opts )
예제 #1
0
파일: jaxl_cli.php 프로젝트: jaxl/JAXL
 public function __construct($recv_cb = null, $quit_cb = null)
 {
     $this->recv_cb = $recv_cb;
     $this->quit_cb = $quit_cb;
     // catch read event on stdin
     $this->in = fopen('php://stdin', 'r');
     stream_set_blocking($this->in, false);
     JAXLLoop::watch($this->in, array('read' => array(&$this, 'on_read_ready')));
 }
예제 #2
0
 public function __construct($name, $perm = 0600)
 {
     $this->name = $name;
     $this->perm = $perm;
     $pipe_path = $this->get_pipe_file_path();
     if (!file_exists($pipe_path)) {
         posix_mkfifo($pipe_path, $this->perm);
         $this->fd = fopen($pipe_path, 'r+');
         if (!$this->fd) {
             _error("unable to open pipe");
         }
         stream_set_blocking($this->fd, false);
         // watch for incoming data on pipe
         JAXLLoop::watch($this->fd, array('read' => array(&$this, 'on_read_ready')));
     } else {
         _error("pipe with name {$name} already exists");
     }
 }
 public function send($data)
 {
     $this->obuffer .= $data;
     // add watch for write events
     if ($this->writing) {
         return;
     }
     JAXLLoop::watch($this->fd, array('write' => array(&$this, 'on_write_ready')));
     $this->writing = true;
 }
예제 #4
0
 protected function add_write_cb($client_id)
 {
     if ($this->clients[$client_id]['writing']) {
         return;
     }
     JAXLLoop::watch($this->clients[$client_id]['fd'], array('write' => array(&$this, 'on_client_write_ready')));
     $this->clients[$client_id]['writing'] = true;
 }
예제 #5
0
function manager_read()
{
    global $astman;
    $response = $astman->wait_response(true);
    $reconnects = $astman->reconnects;
    $oldsocket = $astman->socket;
    while ($response === false && $reconnects > 0) {
        $astman->disconnect();
        if ($astman->connect($astman->server . ':' . $astman->port, $astman->username, $astman->secret, $astman->events) !== false) {
            JAXLLoop::watch($astman->socket, array('read' => 'manager_read'));
            JAXLLoop::unwatch($oldsocket, array('read' => true));
            $response = true;
        } else {
            if ($reconnects > 1) {
                $astman->log("reconnect command failed, sleeping before next attempt");
                sleep(1);
            } else {
                $astman->log("FATAL: no reconnect attempts left, command permanently failed");
                exit;
            }
        }
        $reconnects--;
    }
}