Exemplo n.º 1
0
 public function enableCrypto($socket, ResolverInterface $resolver)
 {
     $result = stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
     if (true === $result) {
         $this->loop->removeWriteStream($socket);
         $this->loop->removeReadStream($socket);
         $resolver->resolve(new Stream($socket, $this->loop));
     } else {
         if (false === $result) {
             $this->loop->removeWriteStream($socket);
             $this->loop->removeReadStream($socket);
             $resolver->reject();
         } else {
             // need more data, will retry
         }
     }
 }
Exemplo n.º 2
0
 public function toggleCrypto($socket, ResolverInterface $resolver, $toggle)
 {
     set_error_handler(array($this, 'handleError'));
     $result = stream_socket_enable_crypto($socket, $toggle, $this->method);
     restore_error_handler();
     if (true === $result) {
         $this->loop->removeWriteStream($socket);
         $this->loop->removeReadStream($socket);
         $resolver->resolve();
     } else {
         if (false === $result) {
             $this->loop->removeWriteStream($socket);
             $this->loop->removeReadStream($socket);
             $resolver->reject(new UnexpectedValueException(sprintf("Unable to complete SSL/TLS handshake: %s", $this->errstr), $this->errno));
         } else {
             // need more data, will retry
         }
     }
 }