/**
  * Construct an exec channel from a @{class:ExecFuture}. The future should
  * **NOT** have been started yet (e.g., with `isReady()` or `start()`),
  * because @{class:ExecFuture} closes stdin by default when futures start.
  * If stdin has been closed, you will be unable to write on the channel.
  *
  * @param ExecFuture Future to use as an underlying I/O source.
  * @task construct
  */
 public function __construct(ExecFuture $future)
 {
     parent::__construct();
     // Make an empty write to keep the stdin pipe open. By default, futures
     // close this pipe when they start.
     $future->write('', $keep_pipe = true);
     // Start the future so that reads and writes work immediately.
     $future->isReady();
     $this->future = $future;
 }
 /**
  * Construct a socket channel from a socket or a socket pair.
  *
  * NOTE: This must be a //stream// socket from `stream_socket_client()` or
  * `stream_socket_server()` or similar, not a //plain// socket from
  * `socket_create()` or similar.
  *
  * @param socket  Socket (stream socket, not plain socket). If only one
  *                socket is provided, it is used for reading and writing.
  * @param socket? Optional write socket.
  *
  * @task construct
  */
 public function __construct($read_socket, $write_socket = null)
 {
     parent::__construct();
     foreach (array($read_socket, $write_socket) as $socket) {
         if (!$socket) {
             continue;
         }
         $ok = stream_set_blocking($socket, false);
         if (!$ok) {
             throw new Exception("Failed to set socket nonblocking!");
         }
     }
     $this->readSocket = $read_socket;
     if ($write_socket) {
         $this->writeSocket = $write_socket;
     } else {
         $this->writeSocket = $read_socket;
         $this->isSingleSocket = true;
     }
 }
示例#3
0
 public function __construct(PhutilChannel $channel)
 {
     parent::__construct();
     $this->channel = $channel;
     $this->didConstruct();
 }