public function start() { $this->parts = parse_url($this->url); $transport = $this->_transport(); $ip = $this->_ip(); $port = $this->_port(); $socket_path = $transport . '://' . $ip . ':' . $port; if ($this->client->connect($socket_path)) { _debug("connection to {$this->url} established"); // send request data $this->send_request(); // start loop and wait for response JAXLLoop::run(); } else { _debug("unable to open {$this->url}"); } }
public function start($opts = array()) { // is bosh bot? if (@$this->cfg['bosh_url']) { $this->trans->session_start(); for (;;) { // while any of the curl request is pending // keep receiving response while (sizeof($this->trans->chs) != 0) { $this->trans->recv(); } // if no request in queue, ping bosh end point // and repeat recv $this->trans->ping(); } $this->trans->session_end(); return; } // is xmpp client or component? // if on_connect event have no callbacks // set default on_connect callback to $this->start_stream() // i.e. xmpp client mode if (!$this->ev->exists('on_connect')) { $this->add_cb('on_connect', array($this, 'start_stream')); } // connect to the destination host/port if ($this->connect($this->get_socket_path())) { // reset in case we connected back after retries $this->retry_attempt = 0; // emit $this->ev->emit('on_connect'); // parse opts if (@$opts['--with-debug-shell']) { $this->enable_debug_shell(); } if (@$opts['--with-unix-sock']) { $this->enable_unix_sock(); } // run main loop JAXLLoop::run(); // emit $this->ev->emit('on_disconnect'); } else { if ($this->trans->errno == 61 || $this->trans->errno == 110 || $this->trans->errno == 111) { _debug("unable to connect with errno " . $this->trans->errno . " (" . $this->trans->errstr . ")"); $this->retry(); } else { $this->ev->emit('on_connect_error', array($this->trans->errno, $this->trans->errstr)); } } }
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ require dirname(__FILE__) . '/_bootstrap.php'; if ($argc < 2) { echo "Usage: {$argv['0']} /path/to/server.sock" . PHP_EOL; exit; } JAXLLogger::$level = JAXLLogger::INFO; $server = null; function on_request($client, $raw) { global $server; $server->send($client, $raw); JAXLLogger::info("got client callback " . $raw); } if (file_exists($argv[1])) { unlink($argv[1]); } $server = new JAXLSocketServer('unix://' . $argv[1], null, 'on_request'); JAXLLoop::run(); echo "done" . PHP_EOL;
public function start($cb = null) { $this->cb = $cb; JAXLLoop::run(); }
public function run() { JAXLCli::prompt(); JAXLLoop::run(); }
public function start($opts = array(), $pami_client) { // injection for pami_client // is bosh bot? if (@$this->cfg['bosh_url']) { $this->trans->session_start(); for (;;) { // while any of the curl request is pending // keep receiving response while (sizeof($this->trans->chs) != 0) { $this->trans->recv(); } // echo "eee"; // if no request in queue, ping bosh end point // and repeat recv $this->trans->ping(); } $this->trans->session_end(); return; } // is xmpp client or component? // if on_connect event have no callbacks // set default on_connect callback to $this->start_stream() // i.e. xmpp client mode if (!$this->ev->exists('on_connect')) { $this->add_cb('on_connect', array($this, 'start_stream')); } // connect to the destination host/port if ($this->connect(($this->cfg['port'] == 5223 ? "ssl" : "tcp") . "://" . $this->cfg['host'] . ":" . $this->cfg['port'])) { // emit $this->ev->emit('on_connect'); // parse opts if (@$opts['--with-debug-shell']) { $this->enable_debug_shell(); } if (@$opts['--with-unix-sock']) { $this->enable_unix_sock(); } // run main loop JAXLLoop::run($pami_client); // emit $this->ev->emit('on_disconnect'); } else { if ($this->trans->errno == 61 || $this->trans->errno == 110 || $this->trans->errno == 111) { $retry_after = pow(2, $this->retry_attempt) * $this->retry_interval; $this->retry_attempt++; _debug("unable to connect with errno " . $this->trans->errno . " (" . $this->trans->errstr . "), will try again in " . $retry_after . " seconds"); // TODO: use sigalrm instead // they usually doesn't gel well inside select loop sleep($retry_after); $this->start(); } else { $this->ev->emit('on_connect_error', array($this->trans->errno, $this->trans->errstr)); } } }
send_status($stanza->to, $stanza->from, 'unsubscribed'); break; case 'unavailable': roster_resource_set($jid->node, $jid->resource); break; case NULL: $status = $stanza->show ? $stanza->show : 'available'; $message = $stanza->status; roster_resource_set($jid->node, $jid->resource, $status, $message); break; } }); // connect to the destination host/port if ($comp->connect($comp->get_socket_path())) { $comp->emit('on_connect'); JAXLLoop::run(2, 0); $comp->emit('on_disconnect'); } sleep(2); unset($comp); } 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'));