Skip to content

Commit

Permalink
Improve constant guard
Browse files Browse the repository at this point in the history
e.g. Windows doesn't have EAGAIN
  • Loading branch information
kelunik committed Mar 31, 2022
1 parent b1e6ce0 commit f79d943
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Internal/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
use League\Uri\UriString;
use Revolt\EventLoop;

if (\extension_loaded('sockets')) {
\define(__NAMESPACE__ . '\\CONNECTION_BUSY', \SOCKET_EAGAIN);
\define(__NAMESPACE__ . '\\CONNECTION_TIMEOUT', \SOCKET_ETIMEDOUT);
\define(__NAMESPACE__ . '\\CONNECTION_REFUSED', \SOCKET_ECONNREFUSED);
} else {
// Use Linux error codes if the socket extension is not available
\define(__NAMESPACE__ . '\\CONNECTION_BUSY', 11);
\define(__NAMESPACE__ . '\\CONNECTION_TIMEOUT', 110);
\define(__NAMESPACE__ . '\\CONNECTION_REFUSED', 111);
}
// Use Linux error codes if the socket extension is not available
\define(__NAMESPACE__ . '\CONNECTION_BUSY', \defined('SOCKET_EAGAIN') ? \SOCKET_EAGAIN : 11);
\define(__NAMESPACE__ . '\CONNECTION_TIMEOUT', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 110);
\define(__NAMESPACE__ . '\CONNECTION_REFUSED', \defined('SOCKET_ECONNREFUSED') ? \SOCKET_ECONNREFUSED : 111);

/**
* Parse an URI into [scheme, host, port].
Expand Down

0 comments on commit f79d943

Please sign in to comment.