Ejemplo n.º 1
0
 /**
  * @return Observable
  */
 protected function createSocketForAddress()
 {
     $socket = parent::createSocketForAddress();
     return Observable::create(function (ObserverInterface $observer) use($socket) {
         $stream = new Datagram($socket, $this->loop);
         $observer->onNext(new ConnectorEvent('/connector/connected', $stream));
         $observer->onCompleted();
     });
 }
Ejemplo n.º 2
0
 /**
  * @return Observable\AnonymousObservable
  * @throws \Exception
  */
 protected function createSocketForAddress()
 {
     $socket = parent::createSocketForAddress();
     // Wait TCP handshake
     return Observable::create(function (ObserverInterface $observer) use($socket) {
         $this->loop->addWriteStream($socket, function ($socket) use($observer) {
             $this->onConnected($socket, $observer);
         });
         return new CallbackDisposable(function () use($socket, $observer) {
             $this->loop->removeStream($socket);
             if (is_resource($socket)) {
                 fclose($socket);
             }
         });
     });
 }