Skip to content

Commit 8b60aee

Browse files
authored
ssl using nonblocking socket
stream_socket_enable_crypto using nonblocking socket
1 parent 83f23d6 commit 8b60aee

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Connection/TcpConnection.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,19 @@ public function baseRead($socket, $check_eof = true)
387387
{
388388
// SSL handshake.
389389
if ($this->transport === 'ssl' && $this->_sslHandshakeCompleted !== true) {
390-
stream_set_blocking($socket, true);
391-
stream_set_timeout($socket, 1);
392390
$ret = stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
393-
if(!$ret) {
394-
echo new \Exception('ssl handshake fail, stream_socket_enable_crypto return ' . var_export($ret, true));
391+
// Negotiation has failed.
392+
if(false === $ret) {
393+
$error = error_get_last();
394+
$error_msg = '';
395+
if ($error) {
396+
$error_msg = "{$error['message']} in {$error['file']} on line {$error['line']}";
397+
}
398+
echo new \Exception("SSL handshake fail $error_msg");
395399
return $this->destroy();
400+
} elseif(0 === $ret) {
401+
// There isn't enough data and should try again.
402+
return;
396403
}
397404
if (isset($this->onSslHandshake)) {
398405
try {

0 commit comments

Comments
 (0)