Skip to content

Commit

Permalink
Add more cases to fall back to fcntl when setting non-blocking mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Apr 2, 2024
1 parent 6fca427 commit 19b9106
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 14 deletions.
41 changes: 31 additions & 10 deletions asio/include/asio/detail/impl/descriptor_ops.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,25 @@ int close(int d, state_type& state, asio::error_code& ec)
::fcntl(d, F_SETFL, flags & ~O_NONBLOCK);
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = 0;
# if defined(ENOTTY)
# if defined(ENOTTY) || defined(ENOTCAPABLE)
result = ::ioctl(d, FIONBIO, &arg);
get_last_error(ec, result < 0);
if (ec.value() == ENOTTY)
if (false
# if defined(ENOTTY)
|| ec.value() == ENOTTY
# endif // defined(ENOTTY)
# if defined(ENOTCAPABLE)
|| ec.value() == ENOTCAPABLE
# endif // defined(ENOTCAPABLE)
)
{
int flags = ::fcntl(d, F_GETFL, 0);
if (flags >= 0)
::fcntl(d, F_SETFL, flags & ~O_NONBLOCK);
}
# else // defined(ENOTTY)
# else // defined(ENOTTY) || defined(ENOTCAPABLE)
::ioctl(d, FIONBIO, &arg);
# endif // defined(ENOTTY)
# endif // defined(ENOTTY) || defined(ENOTCAPABLE)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
state &= ~non_blocking;

Expand Down Expand Up @@ -114,8 +121,15 @@ bool set_user_non_blocking(int d, state_type& state,
ioctl_arg_type arg = (value ? 1 : 0);
int result = ::ioctl(d, FIONBIO, &arg);
get_last_error(ec, result < 0);
# if defined(ENOTTY)
if (ec.value() == ENOTTY)
# if defined(ENOTTY) || defined(ENOTCAPABLE)
if (false
# if defined(ENOTTY)
|| ec.value() == ENOTTY
# endif // defined(ENOTTY)
# if defined(ENOTCAPABLE)
|| ec.value() == ENOTCAPABLE
# endif // defined(ENOTCAPABLE)
)
{
result = ::fcntl(d, F_GETFL, 0);
get_last_error(ec, result < 0);
Expand All @@ -126,7 +140,7 @@ bool set_user_non_blocking(int d, state_type& state,
get_last_error(ec, result < 0);
}
}
# endif // defined(ENOTTY)
# endif // defined(ENOTTY) || defined(ENOTCAPABLE)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)

if (result >= 0)
Expand Down Expand Up @@ -177,8 +191,15 @@ bool set_internal_non_blocking(int d, state_type& state,
ioctl_arg_type arg = (value ? 1 : 0);
int result = ::ioctl(d, FIONBIO, &arg);
get_last_error(ec, result < 0);
# if defined(ENOTTY)
if (ec.value() == ENOTTY)
# if defined(ENOTTY) || defined(ENOTCAPABLE)
if (false
# if defined(ENOTTY)
|| ec.value() == ENOTTY
# endif // defined(ENOTTY)
# if defined(ENOTCAPABLE)
|| ec.value() == ENOTCAPABLE
# endif // defined(ENOTCAPABLE)
)
{
result = ::fcntl(d, F_GETFL, 0);
get_last_error(ec, result < 0);
Expand All @@ -189,7 +210,7 @@ bool set_internal_non_blocking(int d, state_type& state,
get_last_error(ec, result < 0);
}
}
# endif // defined(ENOTTY)
# endif // defined(ENOTTY) || defined(ENOTCAPABLE)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)

if (result >= 0)
Expand Down
66 changes: 62 additions & 4 deletions asio/include/asio/detail/impl/socket_ops.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,25 @@ int close(socket_type s, state_type& state,
::fcntl(s, F_SETFL, flags & ~O_NONBLOCK);
# else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = 0;
# if defined(ENOTTY) || defined(ENOTCAPABLE)
result = ::ioctl(s, FIONBIO, &arg);
get_last_error(ec, result < 0);
if (false
# if defined(ENOTTY)
|| ec.value() == ENOTTY
# endif // defined(ENOTTY)
# if defined(ENOTCAPABLE)
|| ec.value() == ENOTCAPABLE
# endif // defined(ENOTCAPABLE)
)
{
int flags = ::fcntl(s, F_GETFL, 0);
if (flags >= 0)
::fcntl(s, F_SETFL, flags & ~O_NONBLOCK);
}
# else // defined(ENOTTY) || defined(ENOTCAPABLE)
::ioctl(s, FIONBIO, &arg);
# endif // defined(ENOTTY) || defined(ENOTCAPABLE)
# endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
state &= ~non_blocking;
Expand Down Expand Up @@ -378,11 +396,31 @@ bool set_user_non_blocking(socket_type s,
result = ::fcntl(s, F_SETFL, flag);
get_last_error(ec, result < 0);
}
#else
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = (value ? 1 : 0);
int result = ::ioctl(s, FIONBIO, &arg);
get_last_error(ec, result < 0);
#endif
# if defined(ENOTTY) || defined(ENOTCAPABLE)
if (false
# if defined(ENOTTY)
|| ec.value() == ENOTTY
# endif // defined(ENOTTY)
# if defined(ENOTCAPABLE)
|| ec.value() == ENOTCAPABLE
# endif // defined(ENOTCAPABLE)
)
{
result = ::fcntl(s, F_GETFL, 0);
get_last_error(ec, result < 0);
if (result >= 0)
{
int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK));
result = ::fcntl(s, F_SETFL, flag);
get_last_error(ec, result < 0);
}
}
# endif // defined(ENOTTY) || defined(ENOTCAPABLE)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)

if (result >= 0)
{
Expand Down Expand Up @@ -432,11 +470,31 @@ bool set_internal_non_blocking(socket_type s,
result = ::fcntl(s, F_SETFL, flag);
get_last_error(ec, result < 0);
}
#else
#else // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)
ioctl_arg_type arg = (value ? 1 : 0);
int result = ::ioctl(s, FIONBIO, &arg);
get_last_error(ec, result < 0);
#endif
# if defined(ENOTTY) || defined(ENOTCAPABLE)
if (false
# if defined(ENOTTY)
|| ec.value() == ENOTTY
# endif // defined(ENOTTY)
# if defined(ENOTCAPABLE)
|| ec.value() == ENOTCAPABLE
# endif // defined(ENOTCAPABLE)
)
{
result = ::fcntl(s, F_GETFL, 0);
get_last_error(ec, result < 0);
if (result >= 0)
{
int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK));
result = ::fcntl(s, F_SETFL, flag);
get_last_error(ec, result < 0);
}
}
# endif // defined(ENOTTY) || defined(ENOTCAPABLE)
#endif // defined(__SYMBIAN32__) || defined(__EMSCRIPTEN__)

if (result >= 0)
{
Expand Down

0 comments on commit 19b9106

Please sign in to comment.