diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-08-02 20:41:55 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-08-02 21:03:09 (GMT) |
commit | d5ace22054203c7989691ae8b3fa4e4784d1b57e (patch) | |
tree | 64d400cdb10644967df183d0f202fcbf8160a773 /3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp | |
parent | 6f26d9aa86f0909af13b23b1a925b8d492e74154 (diff) | |
download | swift-contrib-d5ace22054203c7989691ae8b3fa4e4784d1b57e.zip swift-contrib-d5ace22054203c7989691ae8b3fa4e4784d1b57e.tar.bz2 |
Add two extra Boost dependencies, upgrade to 1.47.0ks/boost1.47
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp | 85 |
1 files changed, 75 insertions, 10 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp b/3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp index 9a2bb3b..ca2222c 100644 --- a/3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp +++ b/3rdParty/Boost/src/boost/asio/detail/impl/descriptor_ops.ipp @@ -43,8 +43,19 @@ int close(int d, state_type& state, boost::system::error_code& ec) int result = 0; if (d != -1) { - if (state & internal_non_blocking) + errno = 0; + result = error_wrapper(::close(d), ec); + + if (result != 0 + && (ec == boost::asio::error::would_block + || ec == boost::asio::error::try_again)) { + // According to UNIX Network Programming Vol. 1, it is possible for + // close() to fail with EWOULDBLOCK under certain circumstances. What + // isn't clear is the state of the descriptor after this error. The one + // 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__) int flags = ::fcntl(d, F_GETFL, 0); if (flags >= 0) @@ -53,11 +64,11 @@ int close(int d, state_type& state, boost::system::error_code& ec) ioctl_arg_type arg = 0; ::ioctl(d, FIONBIO, &arg); #endif // defined(__SYMBIAN32__) - state &= ~internal_non_blocking; - } + state &= ~non_blocking; - errno = 0; - result = error_wrapper(::close(d), ec); + errno = 0; + result = error_wrapper(::close(d), ec); + } } if (result == 0) @@ -65,8 +76,49 @@ int close(int d, state_type& state, boost::system::error_code& ec) return result; } -bool set_internal_non_blocking(int d, - state_type& state, boost::system::error_code& ec) +bool set_user_non_blocking(int d, state_type& state, + bool value, boost::system::error_code& ec) +{ + if (d == -1) + { + ec = boost::asio::error::bad_descriptor; + return false; + } + + errno = 0; +#if defined(__SYMBIAN32__) + 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__) + ioctl_arg_type arg = (value ? 1 : 0); + int result = error_wrapper(::ioctl(d, FIONBIO, &arg), ec); +#endif // defined(__SYMBIAN32__) + + if (result >= 0) + { + ec = boost::system::error_code(); + if (value) + state |= user_set_non_blocking; + else + { + // Clearing the user-set non-blocking mode always overrides any + // internally-set non-blocking flag. Any subsequent asynchronous + // operations will need to re-enable non-blocking I/O. + state &= ~(user_set_non_blocking | internal_non_blocking); + } + return true; + } + + return false; +} + +bool set_internal_non_blocking(int d, state_type& state, + bool value, boost::system::error_code& ec) { if (d == -1) { @@ -74,23 +126,36 @@ bool set_internal_non_blocking(int d, return false; } + if (!value && (state & user_set_non_blocking)) + { + // It does not make sense to clear the internal non-blocking flag if the + // user still wants non-blocking behaviour. Return an error and let the + // caller figure out whether to update the user-set non-blocking flag. + ec = boost::asio::error::invalid_argument; + return false; + } + errno = 0; #if defined(__SYMBIAN32__) int result = error_wrapper(::fcntl(d, F_GETFL, 0), ec); if (result >= 0) { errno = 0; - result = error_wrapper(::fcntl(d, F_SETFL, result | O_NONBLOCK), ec); + int flag = (value ? (result | O_NONBLOCK) : (result & ~O_NONBLOCK)); + result = error_wrapper(::fcntl(d, F_SETFL, flag), ec); } #else // defined(__SYMBIAN32__) - ioctl_arg_type arg = 1; + ioctl_arg_type arg = (value ? 1 : 0); int result = error_wrapper(::ioctl(d, FIONBIO, &arg), ec); #endif // defined(__SYMBIAN32__) if (result >= 0) { ec = boost::system::error_code(); - state |= internal_non_blocking; + if (value) + state |= internal_non_blocking; + else + state &= ~internal_non_blocking; return true; } |