From Windows 10, UNIX domain sockets (a.k.a "local" sockets) are
supported on Windows, with the exception of the connect_pair
function (which will fail with an operation_not_supported error).
The as_single completion token adapter can be used to specify that the
completion handler arguments should be combined into a single argument.
For completion signatures with a single parameter, the argument is
passed through as-is. For signatures with two or more parameters, the
arguments are combined into a tuple.
The as_single adapter may be used in conjunction with use_awaitable and
structured bindings as follows:
auto [e, n] = co_await socket.async_read_some(
asio::buffer(data), as_single(use_awaitable));
Alternatively, it may be used as a default completion token like so:
using default_token = as_single_t<use_awaitable_t<>>;
using tcp_socket = default_token::as_default_on_t<tcp::socket>;
// ...
awaitable<void> do_read(tcp_socket socket)
{
// ...
auto [e, n] = co_await socket.async_read_some(asio::buffer(data));
// ...
}
This flag for sendmsg(2) was standardised in POSIX.1-2008 so all systems
that support at least that version should have it. This prevents
unexpected SIGPIPEs on at least OpenBSD and possibly others.
MSG_NOSIGNAL is used unconditionally on Linux to match existing
behaviour and also because this was present on Linux long before
standardisation.
In some cases, using libpthread on Windows is desired, for example
when porting software that's already using libpthread, avoiding
mixing the two libraries, which can be troublesome.
This change will allow using libthread when targetting Windows and
ASIO_HAS_PTHREADS is set.
Lock should not be held while executing post_deferred_completions.
The unlock call is present everywhere (in all implementations, including in this file) except in this function.
Lock contention has been observed via Windows Performance Analyzer:
ntdll.dll!RtlpWaitOnCriticalSection
ntdll.dll!RtlpEnterCriticalSectionContended
ntdll.dll!RtlEnterCriticalSection
IxServer.exe!boost::asio::detail::win_iocp_io_context::cancel_timer<boost::asio::detail::chrono_time_traits<boost::chrono::steady_clock,boost::asio::wait_traits<boost::chrono::steady_clock> > >
IxServer.exe!boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<boost::chrono::steady_clock,boost::asio::wait_traits<boost::chrono::steady_clock> > >::expires_at