Skip to content

Commit

Permalink
Add emscripten compatibility patches (Use O_NONBLOCK instead of FIONB…
Browse files Browse the repository at this point in the history
…IO + Fix usage of strerror_r).
  • Loading branch information
cynecx authored and chriskohlhoff committed Apr 7, 2020
1 parent 46aa35f commit 607f99b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
18 changes: 9 additions & 9 deletions asio/include/asio/detail/impl/descriptor_ops.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ int close(int d, state_type& state, asio::error_code& ec)
// current OS where this behaviour is seen, Windows, says that the socket
// remains open. Therefore we'll put the descriptor back into blocking
// mode and have another attempt at closing it.
#if defined(__SYMBIAN32__)
#if defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
int flags = ::fcntl(d, F_GETFL, 0);
if (flags >= 0)
::fcntl(d, F_SETFL, flags & ~O_NONBLOCK);
#else // defined(__SYMBIAN32__)
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = 0;
::ioctl(d, FIONBIO, &arg);
#endif // defined(__SYMBIAN32__)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
state &= ~non_blocking;

errno = 0;
Expand All @@ -87,18 +87,18 @@ bool set_user_non_blocking(int d, state_type& state,
}

errno = 0;
#if defined(__SYMBIAN32__)
#if defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
int result = error_wrapper(::fcntl(d, F_GETFL, 0), ec);
if (result >= 0)
{
errno = 0;
int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK));
result = error_wrapper(::fcntl(d, F_SETFL, flag), ec);
}
#else // defined(__SYMBIAN32__)
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = (value ? 1 : 0);
int result = error_wrapper(::ioctl(d, FIONBIO, &arg), ec);
#endif // defined(__SYMBIAN32__)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)

if (result >= 0)
{
Expand Down Expand Up @@ -137,18 +137,18 @@ bool set_internal_non_blocking(int d, state_type& state,
}

errno = 0;
#if defined(__SYMBIAN32__)
#if defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
int result = error_wrapper(::fcntl(d, F_GETFL, 0), ec);
if (result >= 0)
{
errno = 0;
int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK));
result = error_wrapper(::fcntl(d, F_SETFL, flag), ec);
}
#else // defined(__SYMBIAN32__)
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = (value ? 1 : 0);
int result = error_wrapper(::ioctl(d, FIONBIO, &arg), ec);
#endif // defined(__SYMBIAN32__)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)

if (result >= 0)
{
Expand Down
13 changes: 8 additions & 5 deletions asio/include/asio/detail/impl/socket_ops.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ int close(socket_type s, state_type& state,
ioctl_arg_type arg = 0;
::ioctlsocket(s, FIONBIO, &arg);
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if defined(__SYMBIAN32__)
# if defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
int flags = ::fcntl(s, F_GETFL, 0);
if (flags >= 0)
::fcntl(s, F_SETFL, flags & ~O_NONBLOCK);
# else // defined(__SYMBIAN32__)
# else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = 0;
::ioctl(s, FIONBIO, &arg);
# endif // defined(__SYMBIAN32__)
# endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
state &= ~non_blocking;

Expand Down Expand Up @@ -368,7 +368,7 @@ bool set_user_non_blocking(socket_type s,
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
ioctl_arg_type arg = (value ? 1 : 0);
int result = error_wrapper(::ioctlsocket(s, FIONBIO, &arg), ec);
#elif defined(__SYMBIAN32__)
#elif defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
int result = error_wrapper(::fcntl(s, F_GETFL, 0), ec);
if (result >= 0)
{
Expand Down Expand Up @@ -421,7 +421,7 @@ bool set_internal_non_blocking(socket_type s,
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
ioctl_arg_type arg = (value ? 1 : 0);
int result = error_wrapper(::ioctlsocket(s, FIONBIO, &arg), ec);
#elif defined(__SYMBIAN32__)
#elif defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
int result = error_wrapper(::fcntl(s, F_GETFL, 0), ec);
if (result >= 0)
{
Expand Down Expand Up @@ -1762,6 +1762,9 @@ int select(int nfds, fd_set* readfds, fd_set* writefds,
fd_set* exceptfds, timeval* timeout, asio::error_code& ec)
{
clear_last_error();
#if defined(__EMSCRIPTEN__)
exceptfds = 0;
#endif // defined(__EMSCRIPTEN__)
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
if (!readfds && !writefds && !exceptfds && timeout)
{
Expand Down

0 comments on commit 607f99b

Please sign in to comment.