コード例 #1
0
 /**
  * Callback for when server should be shut down
  *
  * @return vid
  */
 public static function shutdown()
 {
     $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
     $c->connect();
     $c->write("HALT\n");
     $c->close();
 }
コード例 #2
0
 /**
  * Callback for when server should be shut down
  */
 public static function shutdown()
 {
     $s = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
     $s->connect();
     $s->write(pack('Nc4Na*', DEFAULT_PROTOCOL_MAGIC_NUMBER, 1, 0, 61, false, 0, null));
     $s->close();
 }
コード例 #3
0
 /**
  * Connect to a socket. If socket still open from last request (which
  * is the case when unread data is left on it by not reading the body,
  * e.g.), use the quick & dirty way: Close and reopen!
  *
  * @param  peer.Socket $s
  * @param  double $read Read timeout
  * @param  double $connect Connect timeout
  * @return peer.Socket
  */
 protected function connect($s, $read, $connect)
 {
     $s->isConnected() && $s->close();
     $s->setTimeout($read);
     $s->connect($connect);
     return $s;
 }
コード例 #4
0
 /**
  * Connect, then enable crypto
  * 
  * @param   float $timeout
  * @return  bool
  * @throws  peer.SSLUnverifiedPeerException if peer verification fails
  * @throws  peer.SSLHandshakeException if handshake fails for any other reasons
  * @throws  peer.ConnectException for all other reasons
  */
 public function connect($timeout = 2.0)
 {
     if ($this->isConnected()) {
         return true;
     }
     parent::connect($timeout);
     if (stream_socket_enable_crypto($this->_sock, true, $this->cryptoImpl)) {
         return true;
     }
     // Parse OpenSSL errors:
     if (preg_match('/error:(\\d+):(.+)/', key(end(\xp::$errors[__FILE__])), $matches)) {
         switch ($matches[1]) {
             case '14090086':
                 $e = new SSLUnverifiedPeerException($matches[2]);
                 break;
             default:
                 $e = new SSLHandshakeException($matches[2]);
                 break;
         }
     } else {
         $e = new SSLHandshakeException('Unable to enable crypto.');
     }
     $this->close();
     throw $e;
 }
コード例 #5
0
 public static function shutdownServer()
 {
     // Tell the server to shut down
     try {
         $c = new Socket(self::$bindAddress[0], self::$bindAddress[1]);
         $c->connect();
         $c->write("HALT\n");
         $c->close();
     } catch (\lang\Throwable $ignored) {
         // Fall through, below should terminate the process anyway
     }
     $status = self::$serverProcess->out->readLine();
     if (!strlen($status) || '+' != $status[0]) {
         while ($l = self::$serverProcess->out->readLine()) {
             $status .= $l;
         }
         while ($l = self::$serverProcess->err->readLine()) {
             $status .= $l;
         }
         self::$serverProcess->close();
         throw new \lang\IllegalStateException($status);
     }
     self::$serverProcess->close();
 }
コード例 #6
0
 /**
  * Retrieve transfer socket
  *
  * @return  peer.Socket
  */
 public function transferSocket()
 {
     $port = $this->expect($this->sendCommand('PASV'), [227]);
     $a = $p = [];
     sscanf($port, '%*[^(] (%d,%d,%d,%d,%d,%d)', $a[0], $a[1], $a[2], $a[3], $p[0], $p[1]);
     // Open transfer socket
     $transfer = new Socket(implode('.', $a), $p[0] * 256 + $p[1]);
     $transfer->connect();
     return $transfer;
 }