Skip to content

Commit f46694e

Browse files
authored
Merge pull request #17 from hotfix31/fix/add-previous-exception-on-stream-exception
Add previous exception to StreamException on socket accept failure
2 parents 6d22044 + ab05ef1 commit f46694e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/SocketServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function accept(int|float|null $timeout = null): SocketStream|null
166166
if ($this->getMetadata('blocked') === false && substr_count($e->getMessage(), 'timed out') > 0) {
167167
return null;
168168
}
169-
throw new StreamException(StreamException::SERVER_ACCEPT_ERR);
169+
throw new StreamException(StreamException::SERVER_ACCEPT_ERR, [], $e);
170170
});
171171
return $stream ? new SocketStream($stream) : null;
172172
}

tests/suites/SocketServerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ public function testBlockingServerTimeout(): void
130130
], $server->getMetadata());
131131
$this->expectException(StreamException::class);
132132
$this->expectExceptionCode(StreamException::SERVER_ACCEPT_ERR);
133-
$this->expectExceptionMessage('Could not accept on socket.');
133+
$this->expectExceptionMessageMatches(
134+
'/Could not accept on socket\. \(stream_socket_accept\(\):.*timed out.*\)/i'
135+
);
134136
$stream = $server->accept(0);
135137
$server->close();
136138
}

0 commit comments

Comments
 (0)