Closed clue closed 3 years ago
I've updated this to use the above work-around only when applicable. This is only known to work on Linux and known to not work on Mac and Windows. Using ext-sockets
to access the SO_ERROR
remains the preferred way, so most other platforms should be supported as well.
For future reference: This work-around uses "error slippage" which has been known to work for decades, see e.g. https://cr.yp.to/docs/connect.html. The recommended way would be to use a read(fd, 0)
call, but PHP's fread($stream, 0)
rejects empty reads and a fread($stream, 1)
will return false
without exposing the errno/errstr. Using fwrite($stream, $data)
is known to work on Linux, but we might be able to find other platforms that could potentially also take advantage of this. Given that this is only used when ext-sockets
is not available and this changeset already provides value on its own, I would suggest leaving this up for a future PR.
This is ready for review :shipit:
This changeset improves error messages for failed TCP/IP connections when
ext-sockets
is not available on Linux. This means it will now consistently report errno/errstr on most supported platforms such as this:Builds on top of #265, #171, reactphp/dns#171, reactphp/dns#172 and others