Skip to content

Commit bd4fe8a

Browse files
committed
Consistently report default errno when ext-sockets is not available
1 parent 8178edc commit bd4fe8a

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/StreamEncryption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function toggleCrypto($socket, Deferred $deferred, $toggle, $method)
126126
// EOF or failed without error => connection closed during handshake
127127
$d->reject(new \UnexpectedValueException(
128128
'Connection lost during TLS handshake',
129-
\defined('SOCKET_ECONNRESET') ? \SOCKET_ECONNRESET : 0
129+
\defined('SOCKET_ECONNRESET') ? \SOCKET_ECONNRESET : 104
130130
));
131131
} else {
132132
// handshake failed with error message

src/TimeoutConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static function handler($uri)
4141
if ($e instanceof TimeoutException) {
4242
throw new \RuntimeException(
4343
'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds',
44-
\defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 0
44+
\defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 110
4545
);
4646
}
4747

tests/FunctionalSecureServerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,11 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()
664664

665665
$error = Block\await($errorEvent, $loop, self::TIMEOUT);
666666

667-
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshak
667+
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake
668668
$this->assertInstanceOf('RuntimeException', $error);
669669
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
670670
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
671-
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
671+
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104, $error->getCode());
672672
$this->assertNull($error->getPrevious());
673673
}
674674

@@ -692,11 +692,11 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
692692

693693
$error = Block\await($errorEvent, $loop, self::TIMEOUT);
694694

695-
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshak
695+
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake
696696
$this->assertInstanceOf('RuntimeException', $error);
697697
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
698698
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
699-
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
699+
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104, $error->getCode());
700700
$this->assertNull($error->getPrevious());
701701
}
702702

tests/TimeoutConnectorTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ public function testRejectsWithTimeoutReasonOnTimeout()
3434

3535
$timeout = new TimeoutConnector($connector, 0.01, $loop);
3636

37-
$this->setExpectedException('RuntimeException', 'Connection to google.com:80 timed out after 0.01 seconds');
37+
$this->setExpectedException(
38+
'RuntimeException',
39+
'Connection to google.com:80 timed out after 0.01 seconds',
40+
\defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 110
41+
);
3842
Block\await($timeout->connect('google.com:80'), $loop);
3943
}
4044

4145
public function testRejectsWithOriginalReasonWhenConnectorRejects()
4246
{
43-
$promise = Promise\reject(new \RuntimeException('Failed'));
47+
$promise = Promise\reject(new \RuntimeException('Failed', 42));
4448

4549
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
4650
$connector->expects($this->once())->method('connect')->with('google.com:80')->will($this->returnValue($promise));
@@ -49,7 +53,11 @@ public function testRejectsWithOriginalReasonWhenConnectorRejects()
4953

5054
$timeout = new TimeoutConnector($connector, 5.0, $loop);
5155

52-
$this->setExpectedException('RuntimeException', 'Failed');
56+
$this->setExpectedException(
57+
'RuntimeException',
58+
'Failed',
59+
42
60+
);
5361
Block\await($timeout->connect('google.com:80'), $loop);
5462
}
5563

0 commit comments

Comments
 (0)