ソースを参照

ssl using nonblocking socket

stream_socket_enable_crypto using nonblocking socket
walkor 8 年 前
コミット
8b60aee583
1 ファイル変更11 行追加4 行削除
  1. 11 4
      Connection/TcpConnection.php

+ 11 - 4
Connection/TcpConnection.php

@@ -387,12 +387,19 @@ class TcpConnection extends ConnectionInterface
     {
         // SSL handshake.
         if ($this->transport === 'ssl' && $this->_sslHandshakeCompleted !== true) {
-            stream_set_blocking($socket, true);
-            stream_set_timeout($socket, 1);
             $ret = stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
-            if(!$ret) {
-                echo new \Exception('ssl handshake fail, stream_socket_enable_crypto return ' . var_export($ret, true));
+            // Negotiation has failed.
+            if(false === $ret) {
+                $error = error_get_last();
+                $error_msg = '';
+                if ($error) {
+                    $error_msg = "{$error['message']} in {$error['file']} on line {$error['line']}";
+                }
+                echo new \Exception("SSL handshake fail $error_msg");
                 return $this->destroy();
+            } elseif(0 === $ret) {
+                // There isn't enough data and should try again.
+                return;
             }
             if (isset($this->onSslHandshake)) {
                 try {