Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/handler_cont_helpers.hpp | //
// detail/handler_cont_helpers.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_HANDLER_CONT_HELPERS_HPP
#define ASIO_DETAIL_HANDLER_CONT_HELPERS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/memory.hpp"
#include "asio/handler_continuation_hook.hpp"
#include "asio/detail/push_options.hpp"
// Calls to asio_handler_is_continuation must be made from a namespace that
// does not contain overloads of this function. This namespace is defined here
// for that purpose.
namespace asio_handler_cont_helpers {
template <typename Context>
inline bool is_continuation(Context& context)
{
#if !defined(ASIO_HAS_HANDLER_HOOKS)
return false;
#else
using asio::asio_handler_is_continuation;
return asio_handler_is_continuation(
asio::detail::addressof(context));
#endif
}
} // namespace asio_handler_cont_helpers
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_HANDLER_CONT_HELPERS_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_send_op.hpp | //
// detail/io_uring_socket_send_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_SEND_OP_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_SEND_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename ConstBufferSequence>
class io_uring_socket_send_op_base : public io_uring_operation
{
public:
io_uring_socket_send_op_base(const asio::error_code& success_ec,
socket_type socket, socket_ops::state_type state,
const ConstBufferSequence& buffers,
socket_base::message_flags flags, func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_socket_send_op_base::do_prepare,
&io_uring_socket_send_op_base::do_perform, complete_func),
socket_(socket),
state_(state),
buffers_(buffers),
flags_(flags),
bufs_(buffers),
msghdr_()
{
msghdr_.msg_iov = bufs_.buffers();
msghdr_.msg_iovlen = static_cast<int>(bufs_.count());
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_socket_send_op_base* o(
static_cast<io_uring_socket_send_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
::io_uring_prep_poll_add(sqe, o->socket_, POLLOUT);
}
else if (o->bufs_.is_single_buffer
&& o->bufs_.is_registered_buffer && o->flags_ == 0)
{
::io_uring_prep_write_fixed(sqe, o->socket_,
o->bufs_.buffers()->iov_base, o->bufs_.buffers()->iov_len,
0, o->bufs_.registered_id().native_handle());
}
else
{
::io_uring_prep_sendmsg(sqe, o->socket_, &o->msghdr_, o->flags_);
}
}
static bool do_perform(io_uring_operation* base, bool after_completion)
{
ASIO_ASSUME(base != 0);
io_uring_socket_send_op_base* o(
static_cast<io_uring_socket_send_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
if (o->bufs_.is_single_buffer)
{
return socket_ops::non_blocking_send1(o->socket_,
o->bufs_.first(o->buffers_).data(),
o->bufs_.first(o->buffers_).size(), o->flags_,
o->ec_, o->bytes_transferred_);
}
else
{
return socket_ops::non_blocking_send(o->socket_,
o->bufs_.buffers(), o->bufs_.count(), o->flags_,
o->ec_, o->bytes_transferred_);
}
}
if (o->ec_ && o->ec_ == asio::error::would_block)
{
o->state_ |= socket_ops::internal_non_blocking;
return false;
}
return after_completion;
}
private:
socket_type socket_;
socket_ops::state_type state_;
ConstBufferSequence buffers_;
socket_base::message_flags flags_;
buffer_sequence_adapter<asio::const_buffer, ConstBufferSequence> bufs_;
msghdr msghdr_;
};
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
class io_uring_socket_send_op
: public io_uring_socket_send_op_base<ConstBufferSequence>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_send_op);
io_uring_socket_send_op(const asio::error_code& success_ec,
int socket, socket_ops::state_type state,
const ConstBufferSequence& buffers, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
: io_uring_socket_send_op_base<ConstBufferSequence>(success_ec,
socket, state, buffers, flags, &io_uring_socket_send_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_send_op* o
(static_cast<io_uring_socket_send_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_SEND_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/posix_thread.hpp | //
// detail/posix_thread.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_POSIX_THREAD_HPP
#define ASIO_DETAIL_POSIX_THREAD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_PTHREADS)
#include <cstddef>
#include <pthread.h>
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
extern "C"
{
ASIO_DECL void* asio_detail_posix_thread_function(void* arg);
}
class posix_thread
: private noncopyable
{
public:
// Constructor.
template <typename Function>
posix_thread(Function f, unsigned int = 0)
: joined_(false)
{
start_thread(new func<Function>(f));
}
// Destructor.
ASIO_DECL ~posix_thread();
// Wait for the thread to exit.
ASIO_DECL void join();
// Get number of CPUs.
ASIO_DECL static std::size_t hardware_concurrency();
private:
friend void* asio_detail_posix_thread_function(void* arg);
class func_base
{
public:
virtual ~func_base() {}
virtual void run() = 0;
};
struct auto_func_base_ptr
{
func_base* ptr;
~auto_func_base_ptr() { delete ptr; }
};
template <typename Function>
class func
: public func_base
{
public:
func(Function f)
: f_(f)
{
}
virtual void run()
{
f_();
}
private:
Function f_;
};
ASIO_DECL void start_thread(func_base* arg);
::pthread_t thread_;
bool joined_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/posix_thread.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_PTHREADS)
#endif // ASIO_DETAIL_POSIX_THREAD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/winrt_utils.hpp | //
// detail/winrt_utils.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WINRT_UTILS_HPP
#define ASIO_DETAIL_WINRT_UTILS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
#include <codecvt>
#include <cstdlib>
#include <future>
#include <locale>
#include <robuffer.h>
#include <windows.storage.streams.h>
#include <wrl/implements.h>
#include "asio/buffer.hpp"
#include "asio/error_code.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
namespace winrt_utils {
inline Platform::String^ string(const char* from)
{
std::wstring tmp(from, from + std::strlen(from));
return ref new Platform::String(tmp.c_str());
}
inline Platform::String^ string(const std::string& from)
{
std::wstring tmp(from.begin(), from.end());
return ref new Platform::String(tmp.c_str());
}
inline std::string string(Platform::String^ from)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(from->Data());
}
inline Platform::String^ string(unsigned short from)
{
return string(std::to_string(from));
}
template <typename T>
inline Platform::String^ string(const T& from)
{
return string(from.to_string());
}
inline int integer(Platform::String^ from)
{
return _wtoi(from->Data());
}
template <typename T>
inline Windows::Networking::HostName^ host_name(const T& from)
{
return ref new Windows::Networking::HostName((string)(from));
}
template <typename ConstBufferSequence>
inline Windows::Storage::Streams::IBuffer^ buffer_dup(
const ConstBufferSequence& buffers)
{
using Microsoft::WRL::ComPtr;
using asio::buffer_size;
std::size_t size = buffer_size(buffers);
auto b = ref new Windows::Storage::Streams::Buffer(size);
ComPtr<IInspectable> insp = reinterpret_cast<IInspectable*>(b);
ComPtr<Windows::Storage::Streams::IBufferByteAccess> bacc;
insp.As(&bacc);
byte* bytes = nullptr;
bacc->Buffer(&bytes);
asio::buffer_copy(asio::buffer(bytes, size), buffers);
b->Length = size;
return b;
}
} // namespace winrt_utils
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_WINRT_UTILS_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/null_fenced_block.hpp | //
// detail/null_fenced_block.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_NULL_FENCED_BLOCK_HPP
#define ASIO_DETAIL_NULL_FENCED_BLOCK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class null_fenced_block
: private noncopyable
{
public:
enum half_or_full_t { half, full };
// Constructor.
explicit null_fenced_block(half_or_full_t)
{
}
// Destructor.
~null_fenced_block()
{
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_NULL_FENCED_BLOCK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/is_buffer_sequence.hpp | //
// detail/is_buffer_sequence.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
#define ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
class mutable_buffer;
class const_buffer;
class mutable_registered_buffer;
class const_registered_buffer;
namespace detail {
struct buffer_sequence_memfns_base
{
void begin();
void end();
void size();
void max_size();
void capacity();
void data();
void prepare();
void commit();
void consume();
void grow();
void shrink();
};
template <typename T>
struct buffer_sequence_memfns_derived
: T, buffer_sequence_memfns_base
{
};
template <typename T, T>
struct buffer_sequence_memfns_check
{
};
template <typename>
char buffer_sequence_begin_helper(...);
template <typename T>
char (&buffer_sequence_begin_helper(T* t,
enable_if_t<!is_same<
decltype(asio::buffer_sequence_begin(*t)),
void>::value>*))[2];
template <typename>
char buffer_sequence_end_helper(...);
template <typename T>
char (&buffer_sequence_end_helper(T* t,
enable_if_t<!is_same<
decltype(asio::buffer_sequence_end(*t)),
void>::value>*))[2];
template <typename>
char (&size_memfn_helper(...))[2];
template <typename T>
char size_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::size>*);
template <typename>
char (&max_size_memfn_helper(...))[2];
template <typename T>
char max_size_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::max_size>*);
template <typename>
char (&capacity_memfn_helper(...))[2];
template <typename T>
char capacity_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::capacity>*);
template <typename>
char (&data_memfn_helper(...))[2];
template <typename T>
char data_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::data>*);
template <typename>
char (&prepare_memfn_helper(...))[2];
template <typename T>
char prepare_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::prepare>*);
template <typename>
char (&commit_memfn_helper(...))[2];
template <typename T>
char commit_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::commit>*);
template <typename>
char (&consume_memfn_helper(...))[2];
template <typename T>
char consume_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::consume>*);
template <typename>
char (&grow_memfn_helper(...))[2];
template <typename T>
char grow_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::grow>*);
template <typename>
char (&shrink_memfn_helper(...))[2];
template <typename T>
char shrink_memfn_helper(
buffer_sequence_memfns_check<
void (buffer_sequence_memfns_base::*)(),
&buffer_sequence_memfns_derived<T>::shrink>*);
template <typename, typename>
char (&buffer_sequence_element_type_helper(...))[2];
template <typename T, typename Buffer>
char buffer_sequence_element_type_helper(T* t,
enable_if_t<is_convertible<
decltype(*asio::buffer_sequence_begin(*t)),
Buffer>::value>*);
template <typename>
char (&const_buffers_type_typedef_helper(...))[2];
template <typename T>
char const_buffers_type_typedef_helper(
typename T::const_buffers_type*);
template <typename>
char (&mutable_buffers_type_typedef_helper(...))[2];
template <typename T>
char mutable_buffers_type_typedef_helper(
typename T::mutable_buffers_type*);
template <typename T, typename Buffer>
struct is_buffer_sequence_class
: integral_constant<bool,
sizeof(buffer_sequence_begin_helper<T>(0, 0)) != 1 &&
sizeof(buffer_sequence_end_helper<T>(0, 0)) != 1 &&
sizeof(buffer_sequence_element_type_helper<T, Buffer>(0, 0)) == 1>
{
};
template <typename T, typename Buffer>
struct is_buffer_sequence
: conditional<is_class<T>::value,
is_buffer_sequence_class<T, Buffer>,
false_type>::type
{
};
template <>
struct is_buffer_sequence<mutable_buffer, mutable_buffer>
: true_type
{
};
template <>
struct is_buffer_sequence<mutable_buffer, const_buffer>
: true_type
{
};
template <>
struct is_buffer_sequence<const_buffer, const_buffer>
: true_type
{
};
template <>
struct is_buffer_sequence<const_buffer, mutable_buffer>
: false_type
{
};
template <>
struct is_buffer_sequence<mutable_registered_buffer, mutable_buffer>
: true_type
{
};
template <>
struct is_buffer_sequence<mutable_registered_buffer, const_buffer>
: true_type
{
};
template <>
struct is_buffer_sequence<const_registered_buffer, const_buffer>
: true_type
{
};
template <>
struct is_buffer_sequence<const_registered_buffer, mutable_buffer>
: false_type
{
};
template <typename T>
struct is_dynamic_buffer_class_v1
: integral_constant<bool,
sizeof(size_memfn_helper<T>(0)) != 1 &&
sizeof(max_size_memfn_helper<T>(0)) != 1 &&
sizeof(capacity_memfn_helper<T>(0)) != 1 &&
sizeof(data_memfn_helper<T>(0)) != 1 &&
sizeof(consume_memfn_helper<T>(0)) != 1 &&
sizeof(prepare_memfn_helper<T>(0)) != 1 &&
sizeof(commit_memfn_helper<T>(0)) != 1 &&
sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 &&
sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1>
{
};
template <typename T>
struct is_dynamic_buffer_v1
: conditional<is_class<T>::value,
is_dynamic_buffer_class_v1<T>,
false_type>::type
{
};
template <typename T>
struct is_dynamic_buffer_class_v2
: integral_constant<bool,
sizeof(size_memfn_helper<T>(0)) != 1 &&
sizeof(max_size_memfn_helper<T>(0)) != 1 &&
sizeof(capacity_memfn_helper<T>(0)) != 1 &&
sizeof(data_memfn_helper<T>(0)) != 1 &&
sizeof(consume_memfn_helper<T>(0)) != 1 &&
sizeof(grow_memfn_helper<T>(0)) != 1 &&
sizeof(shrink_memfn_helper<T>(0)) != 1 &&
sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 &&
sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1>
{
};
template <typename T>
struct is_dynamic_buffer_v2
: conditional<is_class<T>::value,
is_dynamic_buffer_class_v2<T>,
false_type>::type
{
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/initiation_base.hpp | //
// detail/initiation_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_INITIATION_BASE_HPP
#define ASIO_DETAIL_INITIATION_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Initiation, typename = void>
class initiation_base : public Initiation
{
public:
template <typename I>
explicit initiation_base(I&& initiation)
: Initiation(static_cast<I&&>(initiation))
{
}
};
template <typename Initiation>
class initiation_base<Initiation, enable_if_t<!is_class<Initiation>::value>>
{
public:
template <typename I>
explicit initiation_base(I&& initiation)
: initiation_(static_cast<I&&>(initiation))
{
}
template <typename... Args>
void operator()(Args&&... args) const
{
initiation_(static_cast<Args&&>(args)...);
}
private:
Initiation initiation_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_INITIATION_BASE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/null_thread.hpp | //
// detail/null_thread.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_NULL_THREAD_HPP
#define ASIO_DETAIL_NULL_THREAD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_HAS_THREADS)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class null_thread
: private noncopyable
{
public:
// Constructor.
template <typename Function>
null_thread(Function, unsigned int = 0)
{
asio::detail::throw_error(
asio::error::operation_not_supported, "thread");
}
// Destructor.
~null_thread()
{
}
// Wait for the thread to exit.
void join()
{
}
// Get number of CPUs.
static std::size_t hardware_concurrency()
{
return 1;
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // !defined(ASIO_HAS_THREADS)
#endif // ASIO_DETAIL_NULL_THREAD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/signal_set_service.hpp | //
// detail/signal_set_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SIGNAL_SET_SERVICE_HPP
#define ASIO_DETAIL_SIGNAL_SET_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <cstddef>
#include <signal.h>
#include "asio/associated_cancellation_slot.hpp"
#include "asio/cancellation_type.hpp"
#include "asio/error.hpp"
#include "asio/execution_context.hpp"
#include "asio/signal_set_base.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/signal_handler.hpp"
#include "asio/detail/signal_op.hpp"
#include "asio/detail/socket_types.hpp"
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/win_iocp_io_context.hpp"
#else // defined(ASIO_HAS_IOCP)
# include "asio/detail/scheduler.hpp"
#endif // defined(ASIO_HAS_IOCP)
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
# if defined(ASIO_HAS_IO_URING_AS_DEFAULT)
# include "asio/detail/io_uring_service.hpp"
# else // defined(ASIO_HAS_IO_URING_AS_DEFAULT)
# include "asio/detail/reactor.hpp"
# endif // defined(ASIO_HAS_IO_URING_AS_DEFAULT)
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
#if defined(NSIG) && (NSIG > 0)
enum { max_signal_number = NSIG };
#else
enum { max_signal_number = 128 };
#endif
extern ASIO_DECL struct signal_state* get_signal_state();
extern "C" ASIO_DECL void asio_signal_handler(int signal_number);
class signal_set_service :
public execution_context_service_base<signal_set_service>
{
public:
// Type used for tracking an individual signal registration.
class registration
{
public:
// Default constructor.
registration()
: signal_number_(0),
queue_(0),
undelivered_(0),
next_in_table_(0),
prev_in_table_(0),
next_in_set_(0)
{
}
private:
// Only this service will have access to the internal values.
friend class signal_set_service;
// The signal number that is registered.
int signal_number_;
// The waiting signal handlers.
op_queue<signal_op>* queue_;
// The number of undelivered signals.
std::size_t undelivered_;
// Pointers to adjacent registrations in the registrations_ table.
registration* next_in_table_;
registration* prev_in_table_;
// Link to next registration in the signal set.
registration* next_in_set_;
};
// The implementation type of the signal_set.
class implementation_type
{
public:
// Default constructor.
implementation_type()
: signals_(0)
{
}
private:
// Only this service will have access to the internal values.
friend class signal_set_service;
// The pending signal handlers.
op_queue<signal_op> queue_;
// Linked list of registered signals.
registration* signals_;
};
// Constructor.
ASIO_DECL signal_set_service(execution_context& context);
// Destructor.
ASIO_DECL ~signal_set_service();
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Perform fork-related housekeeping.
ASIO_DECL void notify_fork(
asio::execution_context::fork_event fork_ev);
// Construct a new signal_set implementation.
ASIO_DECL void construct(implementation_type& impl);
// Destroy a signal_set implementation.
ASIO_DECL void destroy(implementation_type& impl);
// Add a signal to a signal_set.
asio::error_code add(implementation_type& impl,
int signal_number, asio::error_code& ec)
{
return add(impl, signal_number, signal_set_base::flags::dont_care, ec);
}
// Add a signal to a signal_set with the specified flags.
ASIO_DECL asio::error_code add(implementation_type& impl,
int signal_number, signal_set_base::flags_t f,
asio::error_code& ec);
// Remove a signal to a signal_set.
ASIO_DECL asio::error_code remove(implementation_type& impl,
int signal_number, asio::error_code& ec);
// Remove all signals from a signal_set.
ASIO_DECL asio::error_code clear(implementation_type& impl,
asio::error_code& ec);
// Cancel all operations associated with the signal set.
ASIO_DECL asio::error_code cancel(implementation_type& impl,
asio::error_code& ec);
// Cancel a specific operation associated with the signal set.
ASIO_DECL void cancel_ops_by_key(implementation_type& impl,
void* cancellation_key);
// Start an asynchronous operation to wait for a signal to be delivered.
template <typename Handler, typename IoExecutor>
void async_wait(implementation_type& impl,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef signal_handler<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<signal_op_cancellation>(this, &impl);
}
ASIO_HANDLER_CREATION((scheduler_.context(),
*p.p, "signal_set", &impl, 0, "async_wait"));
start_wait_op(impl, p.p);
p.v = p.p = 0;
}
// Deliver notification that a particular signal occurred.
ASIO_DECL static void deliver_signal(int signal_number);
private:
// Helper function to add a service to the global signal state.
ASIO_DECL static void add_service(signal_set_service* service);
// Helper function to remove a service from the global signal state.
ASIO_DECL static void remove_service(signal_set_service* service);
// Helper function to create the pipe descriptors.
ASIO_DECL static void open_descriptors();
// Helper function to close the pipe descriptors.
ASIO_DECL static void close_descriptors();
// Helper function to start a wait operation.
ASIO_DECL void start_wait_op(implementation_type& impl, signal_op* op);
// Helper class used to implement per-operation cancellation
class signal_op_cancellation
{
public:
signal_op_cancellation(signal_set_service* s, implementation_type* i)
: service_(s),
implementation_(i)
{
}
void operator()(cancellation_type_t type)
{
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
service_->cancel_ops_by_key(*implementation_, this);
}
}
private:
signal_set_service* service_;
implementation_type* implementation_;
};
// The scheduler used for dispatching handlers.
#if defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context scheduler_impl;
#else
typedef class scheduler scheduler_impl;
#endif
scheduler_impl& scheduler_;
#if !defined(ASIO_WINDOWS) \
&& !defined(ASIO_WINDOWS_RUNTIME) \
&& !defined(__CYGWIN__)
// The type used for processing pipe readiness notifications.
class pipe_read_op;
# if defined(ASIO_HAS_IO_URING_AS_DEFAULT)
// The io_uring service used for waiting for pipe readiness.
io_uring_service& io_uring_service_;
// The per I/O object data used for the pipe.
io_uring_service::per_io_object_data io_object_data_;
# else // defined(ASIO_HAS_IO_URING_AS_DEFAULT)
// The reactor used for waiting for pipe readiness.
reactor& reactor_;
// The per-descriptor reactor data used for the pipe.
reactor::per_descriptor_data reactor_data_;
# endif // defined(ASIO_HAS_IO_URING_AS_DEFAULT)
#endif // !defined(ASIO_WINDOWS)
// && !defined(ASIO_WINDOWS_RUNTIME)
// && !defined(__CYGWIN__)
// A mapping from signal number to the registered signal sets.
registration* registrations_[max_signal_number];
// Pointers to adjacent services in linked list.
signal_set_service* next_;
signal_set_service* prev_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/signal_set_service.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // ASIO_DETAIL_SIGNAL_SET_SERVICE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_overlapped_ptr.hpp | //
// detail/win_iocp_overlapped_ptr.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_OVERLAPPED_PTR_HPP
#define ASIO_DETAIL_WIN_IOCP_OVERLAPPED_PTR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/io_context.hpp"
#include "asio/query.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/win_iocp_overlapped_op.hpp"
#include "asio/detail/win_iocp_io_context.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O.
class win_iocp_overlapped_ptr
: private noncopyable
{
public:
// Construct an empty win_iocp_overlapped_ptr.
win_iocp_overlapped_ptr()
: ptr_(0),
iocp_service_(0)
{
}
// Construct an win_iocp_overlapped_ptr to contain the specified handler.
template <typename Executor, typename Handler>
explicit win_iocp_overlapped_ptr(const Executor& ex,
Handler&& handler)
: ptr_(0),
iocp_service_(0)
{
this->reset(ex, static_cast<Handler&&>(handler));
}
// Destructor automatically frees the OVERLAPPED object unless released.
~win_iocp_overlapped_ptr()
{
reset();
}
// Reset to empty.
void reset()
{
if (ptr_)
{
ptr_->destroy();
ptr_ = 0;
iocp_service_->work_finished();
iocp_service_ = 0;
}
}
// Reset to contain the specified handler, freeing any current OVERLAPPED
// object.
template <typename Executor, typename Handler>
void reset(const Executor& ex, Handler handler)
{
win_iocp_io_context* iocp_service = this->get_iocp_service(ex);
typedef win_iocp_overlapped_op<Handler, Executor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(handler, ex);
ASIO_HANDLER_CREATION((ex.context(), *p.p,
"iocp_service", iocp_service, 0, "overlapped"));
iocp_service->work_started();
reset();
ptr_ = p.p;
p.v = p.p = 0;
iocp_service_ = iocp_service;
}
// Get the contained OVERLAPPED object.
OVERLAPPED* get()
{
return ptr_;
}
// Get the contained OVERLAPPED object.
const OVERLAPPED* get() const
{
return ptr_;
}
// Release ownership of the OVERLAPPED object.
OVERLAPPED* release()
{
if (ptr_)
iocp_service_->on_pending(ptr_);
OVERLAPPED* tmp = ptr_;
ptr_ = 0;
iocp_service_ = 0;
return tmp;
}
// Post completion notification for overlapped operation. Releases ownership.
void complete(const asio::error_code& ec,
std::size_t bytes_transferred)
{
if (ptr_)
{
iocp_service_->on_completion(ptr_, ec,
static_cast<DWORD>(bytes_transferred));
ptr_ = 0;
iocp_service_ = 0;
}
}
private:
template <typename Executor>
static win_iocp_io_context* get_iocp_service(const Executor& ex,
enable_if_t<
can_query<const Executor&, execution::context_t>::value
>* = 0)
{
return &use_service<win_iocp_io_context>(
asio::query(ex, execution::context));
}
template <typename Executor>
static win_iocp_io_context* get_iocp_service(const Executor& ex,
enable_if_t<
!can_query<const Executor&, execution::context_t>::value
>* = 0)
{
return &use_service<win_iocp_io_context>(ex.context());
}
static win_iocp_io_context* get_iocp_service(
const io_context::executor_type& ex)
{
return &asio::query(ex, execution::context).impl_;
}
win_iocp_operation* ptr_;
win_iocp_io_context* iocp_service_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_OVERLAPPED_PTR_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/executor_op.hpp | //
// detail/executor_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_EXECUTOR_OP_HPP
#define ASIO_DETAIL_EXECUTOR_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/scheduler_operation.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Handler, typename Alloc,
typename Operation = scheduler_operation>
class executor_op : public Operation
{
public:
ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(executor_op);
template <typename H>
executor_op(H&& h, const Alloc& allocator)
: Operation(&executor_op::do_complete),
handler_(static_cast<H&&>(h)),
allocator_(allocator)
{
}
static void do_complete(void* owner, Operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
executor_op* o(static_cast<executor_op*>(base));
Alloc allocator(o->allocator_);
ptr p = { detail::addressof(allocator), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
Handler handler(static_cast<Handler&&>(o->handler_));
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN(());
static_cast<Handler&&>(handler)();
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
Alloc allocator_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_EXECUTOR_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/reactive_socket_sendto_op.hpp | //
// detail/reactive_socket_sendto_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_OP_HPP
#define ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename ConstBufferSequence, typename Endpoint>
class reactive_socket_sendto_op_base : public reactor_op
{
public:
reactive_socket_sendto_op_base(const asio::error_code& success_ec,
socket_type socket, const ConstBufferSequence& buffers,
const Endpoint& endpoint, socket_base::message_flags flags,
func_type complete_func)
: reactor_op(success_ec,
&reactive_socket_sendto_op_base::do_perform, complete_func),
socket_(socket),
buffers_(buffers),
destination_(endpoint),
flags_(flags)
{
}
static status do_perform(reactor_op* base)
{
ASIO_ASSUME(base != 0);
reactive_socket_sendto_op_base* o(
static_cast<reactive_socket_sendto_op_base*>(base));
typedef buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs_type;
status result;
if (bufs_type::is_single_buffer)
{
result = socket_ops::non_blocking_sendto1(o->socket_,
bufs_type::first(o->buffers_).data(),
bufs_type::first(o->buffers_).size(), o->flags_,
o->destination_.data(), o->destination_.size(),
o->ec_, o->bytes_transferred_) ? done : not_done;
}
else
{
bufs_type bufs(o->buffers_);
result = socket_ops::non_blocking_sendto(o->socket_,
bufs.buffers(), bufs.count(), o->flags_,
o->destination_.data(), o->destination_.size(),
o->ec_, o->bytes_transferred_) ? done : not_done;
}
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_sendto",
o->ec_, o->bytes_transferred_));
return result;
}
private:
socket_type socket_;
ConstBufferSequence buffers_;
Endpoint destination_;
socket_base::message_flags flags_;
};
template <typename ConstBufferSequence, typename Endpoint,
typename Handler, typename IoExecutor>
class reactive_socket_sendto_op :
public reactive_socket_sendto_op_base<ConstBufferSequence, Endpoint>
{
public:
typedef Handler handler_type;
typedef IoExecutor io_executor_type;
ASIO_DEFINE_HANDLER_PTR(reactive_socket_sendto_op);
reactive_socket_sendto_op(const asio::error_code& success_ec,
socket_type socket, const ConstBufferSequence& buffers,
const Endpoint& endpoint, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
: reactive_socket_sendto_op_base<ConstBufferSequence, Endpoint>(
success_ec, socket, buffers, endpoint, flags,
&reactive_socket_sendto_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
reactive_socket_sendto_op* o(static_cast<reactive_socket_sendto_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
static void do_immediate(operation* base, bool, const void* io_ex)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
reactive_socket_sendto_op* o(static_cast<reactive_socket_sendto_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
immediate_handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_, io_ex);
ASIO_HANDLER_INVOCATION_END;
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/array_fwd.hpp | //
// detail/array_fwd.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_ARRAY_FWD_HPP
#define ASIO_DETAIL_ARRAY_FWD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
namespace boost {
template<class T, std::size_t N>
class array;
} // namespace boost
// Standard library components can't be forward declared, so we'll have to
// include the array header. Fortunately, it's fairly lightweight and doesn't
// add significantly to the compile time.
#include <array>
#endif // ASIO_DETAIL_ARRAY_FWD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/bind_handler.hpp | //
// detail/bind_handler.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_BIND_HANDLER_HPP
#define ASIO_DETAIL_BIND_HANDLER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/associator.hpp"
#include "asio/detail/handler_cont_helpers.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Handler>
class binder0
{
public:
template <typename T>
binder0(int, T&& handler)
: handler_(static_cast<T&&>(handler))
{
}
binder0(Handler& handler)
: handler_(static_cast<Handler&&>(handler))
{
}
binder0(const binder0& other)
: handler_(other.handler_)
{
}
binder0(binder0&& other)
: handler_(static_cast<Handler&&>(other.handler_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)();
}
void operator()() const
{
handler_();
}
//private:
Handler handler_;
};
template <typename Handler>
inline bool asio_handler_is_continuation(
binder0<Handler>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler>
inline binder0<decay_t<Handler>> bind_handler(
Handler&& handler)
{
return binder0<decay_t<Handler>>(
0, static_cast<Handler&&>(handler));
}
template <typename Handler, typename Arg1>
class binder1
{
public:
template <typename T>
binder1(int, T&& handler, const Arg1& arg1)
: handler_(static_cast<T&&>(handler)),
arg1_(arg1)
{
}
binder1(Handler& handler, const Arg1& arg1)
: handler_(static_cast<Handler&&>(handler)),
arg1_(arg1)
{
}
binder1(const binder1& other)
: handler_(other.handler_),
arg1_(other.arg1_)
{
}
binder1(binder1&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<const Arg1&>(arg1_));
}
void operator()() const
{
handler_(arg1_);
}
//private:
Handler handler_;
Arg1 arg1_;
};
template <typename Handler, typename Arg1>
inline bool asio_handler_is_continuation(
binder1<Handler, Arg1>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler, typename Arg1>
inline binder1<decay_t<Handler>, Arg1> bind_handler(
Handler&& handler, const Arg1& arg1)
{
return binder1<decay_t<Handler>, Arg1>(0,
static_cast<Handler&&>(handler), arg1);
}
template <typename Handler, typename Arg1, typename Arg2>
class binder2
{
public:
template <typename T>
binder2(int, T&& handler,
const Arg1& arg1, const Arg2& arg2)
: handler_(static_cast<T&&>(handler)),
arg1_(arg1),
arg2_(arg2)
{
}
binder2(Handler& handler, const Arg1& arg1, const Arg2& arg2)
: handler_(static_cast<Handler&&>(handler)),
arg1_(arg1),
arg2_(arg2)
{
}
binder2(const binder2& other)
: handler_(other.handler_),
arg1_(other.arg1_),
arg2_(other.arg2_)
{
}
binder2(binder2&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_)),
arg2_(static_cast<Arg2&&>(other.arg2_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<const Arg1&>(arg1_),
static_cast<const Arg2&>(arg2_));
}
void operator()() const
{
handler_(arg1_, arg2_);
}
//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
};
template <typename Handler, typename Arg1, typename Arg2>
inline bool asio_handler_is_continuation(
binder2<Handler, Arg1, Arg2>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler, typename Arg1, typename Arg2>
inline binder2<decay_t<Handler>, Arg1, Arg2> bind_handler(
Handler&& handler, const Arg1& arg1, const Arg2& arg2)
{
return binder2<decay_t<Handler>, Arg1, Arg2>(0,
static_cast<Handler&&>(handler), arg1, arg2);
}
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
class binder3
{
public:
template <typename T>
binder3(int, T&& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3)
: handler_(static_cast<T&&>(handler)),
arg1_(arg1),
arg2_(arg2),
arg3_(arg3)
{
}
binder3(Handler& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3)
: handler_(static_cast<Handler&&>(handler)),
arg1_(arg1),
arg2_(arg2),
arg3_(arg3)
{
}
binder3(const binder3& other)
: handler_(other.handler_),
arg1_(other.arg1_),
arg2_(other.arg2_),
arg3_(other.arg3_)
{
}
binder3(binder3&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_)),
arg2_(static_cast<Arg2&&>(other.arg2_)),
arg3_(static_cast<Arg3&&>(other.arg3_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<const Arg1&>(arg1_),
static_cast<const Arg2&>(arg2_),
static_cast<const Arg3&>(arg3_));
}
void operator()() const
{
handler_(arg1_, arg2_, arg3_);
}
//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
Arg3 arg3_;
};
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
inline bool asio_handler_is_continuation(
binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
inline binder3<decay_t<Handler>, Arg1, Arg2, Arg3> bind_handler(
Handler&& handler, const Arg1& arg1, const Arg2& arg2,
const Arg3& arg3)
{
return binder3<decay_t<Handler>, Arg1, Arg2, Arg3>(0,
static_cast<Handler&&>(handler), arg1, arg2, arg3);
}
template <typename Handler, typename Arg1,
typename Arg2, typename Arg3, typename Arg4>
class binder4
{
public:
template <typename T>
binder4(int, T&& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
: handler_(static_cast<T&&>(handler)),
arg1_(arg1),
arg2_(arg2),
arg3_(arg3),
arg4_(arg4)
{
}
binder4(Handler& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
: handler_(static_cast<Handler&&>(handler)),
arg1_(arg1),
arg2_(arg2),
arg3_(arg3),
arg4_(arg4)
{
}
binder4(const binder4& other)
: handler_(other.handler_),
arg1_(other.arg1_),
arg2_(other.arg2_),
arg3_(other.arg3_),
arg4_(other.arg4_)
{
}
binder4(binder4&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_)),
arg2_(static_cast<Arg2&&>(other.arg2_)),
arg3_(static_cast<Arg3&&>(other.arg3_)),
arg4_(static_cast<Arg4&&>(other.arg4_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<const Arg1&>(arg1_),
static_cast<const Arg2&>(arg2_),
static_cast<const Arg3&>(arg3_),
static_cast<const Arg4&>(arg4_));
}
void operator()() const
{
handler_(arg1_, arg2_, arg3_, arg4_);
}
//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
Arg3 arg3_;
Arg4 arg4_;
};
template <typename Handler, typename Arg1,
typename Arg2, typename Arg3, typename Arg4>
inline bool asio_handler_is_continuation(
binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler, typename Arg1,
typename Arg2, typename Arg3, typename Arg4>
inline binder4<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4>
bind_handler(Handler&& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
{
return binder4<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4>(0,
static_cast<Handler&&>(handler), arg1, arg2, arg3, arg4);
}
template <typename Handler, typename Arg1, typename Arg2,
typename Arg3, typename Arg4, typename Arg5>
class binder5
{
public:
template <typename T>
binder5(int, T&& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
: handler_(static_cast<T&&>(handler)),
arg1_(arg1),
arg2_(arg2),
arg3_(arg3),
arg4_(arg4),
arg5_(arg5)
{
}
binder5(Handler& handler, const Arg1& arg1, const Arg2& arg2,
const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
: handler_(static_cast<Handler&&>(handler)),
arg1_(arg1),
arg2_(arg2),
arg3_(arg3),
arg4_(arg4),
arg5_(arg5)
{
}
binder5(const binder5& other)
: handler_(other.handler_),
arg1_(other.arg1_),
arg2_(other.arg2_),
arg3_(other.arg3_),
arg4_(other.arg4_),
arg5_(other.arg5_)
{
}
binder5(binder5&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_)),
arg2_(static_cast<Arg2&&>(other.arg2_)),
arg3_(static_cast<Arg3&&>(other.arg3_)),
arg4_(static_cast<Arg4&&>(other.arg4_)),
arg5_(static_cast<Arg5&&>(other.arg5_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<const Arg1&>(arg1_),
static_cast<const Arg2&>(arg2_),
static_cast<const Arg3&>(arg3_),
static_cast<const Arg4&>(arg4_),
static_cast<const Arg5&>(arg5_));
}
void operator()() const
{
handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
}
//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
Arg3 arg3_;
Arg4 arg4_;
Arg5 arg5_;
};
template <typename Handler, typename Arg1, typename Arg2,
typename Arg3, typename Arg4, typename Arg5>
inline bool asio_handler_is_continuation(
binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler, typename Arg1, typename Arg2,
typename Arg3, typename Arg4, typename Arg5>
inline binder5<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4, Arg5>
bind_handler(Handler&& handler, const Arg1& arg1,
const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
{
return binder5<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4, Arg5>(0,
static_cast<Handler&&>(handler), arg1, arg2, arg3, arg4, arg5);
}
template <typename Handler, typename Arg1>
class move_binder1
{
public:
move_binder1(int, Handler&& handler,
Arg1&& arg1)
: handler_(static_cast<Handler&&>(handler)),
arg1_(static_cast<Arg1&&>(arg1))
{
}
move_binder1(move_binder1&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<Arg1&&>(arg1_));
}
//private:
Handler handler_;
Arg1 arg1_;
};
template <typename Handler, typename Arg1>
inline bool asio_handler_is_continuation(
move_binder1<Handler, Arg1>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Handler, typename Arg1, typename Arg2>
class move_binder2
{
public:
move_binder2(int, Handler&& handler,
const Arg1& arg1, Arg2&& arg2)
: handler_(static_cast<Handler&&>(handler)),
arg1_(arg1),
arg2_(static_cast<Arg2&&>(arg2))
{
}
move_binder2(move_binder2&& other)
: handler_(static_cast<Handler&&>(other.handler_)),
arg1_(static_cast<Arg1&&>(other.arg1_)),
arg2_(static_cast<Arg2&&>(other.arg2_))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)(
static_cast<const Arg1&>(arg1_),
static_cast<Arg2&&>(arg2_));
}
//private:
Handler handler_;
Arg1 arg1_;
Arg2 arg2_;
};
template <typename Handler, typename Arg1, typename Arg2>
inline bool asio_handler_is_continuation(
move_binder2<Handler, Arg1, Arg2>* this_handler)
{
return asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
} // namespace detail
template <template <typename, typename> class Associator,
typename Handler, typename DefaultCandidate>
struct associator<Associator,
detail::binder0<Handler>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::binder0<Handler>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::binder0<Handler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename DefaultCandidate>
struct associator<Associator,
detail::binder1<Handler, Arg1>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::binder1<Handler, Arg1>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::binder1<Handler, Arg1>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename Arg2,
typename DefaultCandidate>
struct associator<Associator,
detail::binder2<Handler, Arg1, Arg2>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::binder2<Handler, Arg1, Arg2>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::binder2<Handler, Arg1, Arg2>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename Arg2, typename Arg3,
typename DefaultCandidate>
struct associator<Associator,
detail::binder3<Handler, Arg1, Arg2, Arg3>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::binder3<Handler, Arg1, Arg2, Arg3>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::binder3<Handler, Arg1, Arg2, Arg3>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename DefaultCandidate>
struct associator<Associator,
detail::binder4<Handler, Arg1, Arg2, Arg3, Arg4>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::binder4<Handler, Arg1, Arg2, Arg3, Arg4>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::binder4<Handler, Arg1, Arg2, Arg3, Arg4>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5, typename DefaultCandidate>
struct associator<Associator,
detail::binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename DefaultCandidate>
struct associator<Associator,
detail::move_binder1<Handler, Arg1>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::move_binder1<Handler, Arg1>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::move_binder1<Handler, Arg1>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Arg1, typename Arg2, typename DefaultCandidate>
struct associator<Associator,
detail::move_binder2<Handler, Arg1, Arg2>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::move_binder2<Handler, Arg1, Arg2>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::move_binder2<Handler, Arg1, Arg2>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_BIND_HANDLER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/conditionally_enabled_mutex.hpp | //
// detail/conditionally_enabled_mutex.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_CONDITIONALLY_ENABLED_MUTEX_HPP
#define ASIO_DETAIL_CONDITIONALLY_ENABLED_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Mutex adapter used to conditionally enable or disable locking.
class conditionally_enabled_mutex
: private noncopyable
{
public:
// Helper class to lock and unlock a mutex automatically.
class scoped_lock
: private noncopyable
{
public:
// Tag type used to distinguish constructors.
enum adopt_lock_t { adopt_lock };
// Constructor adopts a lock that is already held.
scoped_lock(conditionally_enabled_mutex& m, adopt_lock_t)
: mutex_(m),
locked_(m.enabled_)
{
}
// Constructor acquires the lock.
explicit scoped_lock(conditionally_enabled_mutex& m)
: mutex_(m)
{
if (m.enabled_)
{
mutex_.mutex_.lock();
locked_ = true;
}
else
locked_ = false;
}
// Destructor releases the lock.
~scoped_lock()
{
if (locked_)
mutex_.mutex_.unlock();
}
// Explicitly acquire the lock.
void lock()
{
if (mutex_.enabled_ && !locked_)
{
mutex_.mutex_.lock();
locked_ = true;
}
}
// Explicitly release the lock.
void unlock()
{
if (locked_)
{
mutex_.unlock();
locked_ = false;
}
}
// Test whether the lock is held.
bool locked() const
{
return locked_;
}
// Get the underlying mutex.
asio::detail::mutex& mutex()
{
return mutex_.mutex_;
}
private:
friend class conditionally_enabled_event;
conditionally_enabled_mutex& mutex_;
bool locked_;
};
// Constructor.
explicit conditionally_enabled_mutex(bool enabled)
: enabled_(enabled)
{
}
// Destructor.
~conditionally_enabled_mutex()
{
}
// Determine whether locking is enabled.
bool enabled() const
{
return enabled_;
}
// Lock the mutex.
void lock()
{
if (enabled_)
mutex_.lock();
}
// Unlock the mutex.
void unlock()
{
if (enabled_)
mutex_.unlock();
}
private:
friend class scoped_lock;
friend class conditionally_enabled_event;
asio::detail::mutex mutex_;
const bool enabled_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_CONDITIONALLY_ENABLED_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_file_service.hpp | //
// detail/io_uring_file_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_FILE_SERVICE_HPP
#define ASIO_DETAIL_IO_URING_FILE_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_FILE) \
&& defined(ASIO_HAS_IO_URING)
#include <string>
#include "asio/detail/cstdint.hpp"
#include "asio/detail/descriptor_ops.hpp"
#include "asio/detail/io_uring_descriptor_service.hpp"
#include "asio/error.hpp"
#include "asio/execution_context.hpp"
#include "asio/file_base.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Extend the io_uring_descriptor_service to provide file support.
class io_uring_file_service :
public execution_context_service_base<io_uring_file_service>
{
public:
typedef io_uring_descriptor_service descriptor_service;
// The native type of a file.
typedef descriptor_service::native_handle_type native_handle_type;
// The implementation type of the file.
class implementation_type : descriptor_service::implementation_type
{
private:
// Only this service will have access to the internal values.
friend class io_uring_file_service;
bool is_stream_;
};
ASIO_DECL io_uring_file_service(execution_context& context);
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Construct a new file implementation.
void construct(implementation_type& impl)
{
descriptor_service_.construct(impl);
impl.is_stream_ = false;
}
// Move-construct a new file implementation.
void move_construct(implementation_type& impl,
implementation_type& other_impl)
{
descriptor_service_.move_construct(impl, other_impl);
impl.is_stream_ = other_impl.is_stream_;
}
// Move-assign from another file implementation.
void move_assign(implementation_type& impl,
io_uring_file_service& other_service,
implementation_type& other_impl)
{
descriptor_service_.move_assign(impl,
other_service.descriptor_service_, other_impl);
impl.is_stream_ = other_impl.is_stream_;
}
// Destroy a file implementation.
void destroy(implementation_type& impl)
{
descriptor_service_.destroy(impl);
}
// Open the file using the specified path name.
ASIO_DECL asio::error_code open(implementation_type& impl,
const char* path, file_base::flags open_flags,
asio::error_code& ec);
// Assign a native descriptor to a file implementation.
asio::error_code assign(implementation_type& impl,
const native_handle_type& native_descriptor,
asio::error_code& ec)
{
return descriptor_service_.assign(impl, native_descriptor, ec);
}
// Set whether the implementation is stream-oriented.
void set_is_stream(implementation_type& impl, bool is_stream)
{
impl.is_stream_ = is_stream;
}
// Determine whether the file is open.
bool is_open(const implementation_type& impl) const
{
return descriptor_service_.is_open(impl);
}
// Destroy a file implementation.
asio::error_code close(implementation_type& impl,
asio::error_code& ec)
{
return descriptor_service_.close(impl, ec);
}
// Get the native file representation.
native_handle_type native_handle(const implementation_type& impl) const
{
return descriptor_service_.native_handle(impl);
}
// Release ownership of the native descriptor representation.
native_handle_type release(implementation_type& impl,
asio::error_code& ec)
{
return descriptor_service_.release(impl, ec);
}
// Cancel all operations associated with the file.
asio::error_code cancel(implementation_type& impl,
asio::error_code& ec)
{
return descriptor_service_.cancel(impl, ec);
}
// Get the size of the file.
ASIO_DECL uint64_t size(const implementation_type& impl,
asio::error_code& ec) const;
// Alter the size of the file.
ASIO_DECL asio::error_code resize(implementation_type& impl,
uint64_t n, asio::error_code& ec);
// Synchronise the file to disk.
ASIO_DECL asio::error_code sync_all(implementation_type& impl,
asio::error_code& ec);
// Synchronise the file data to disk.
ASIO_DECL asio::error_code sync_data(implementation_type& impl,
asio::error_code& ec);
// Seek to a position in the file.
ASIO_DECL uint64_t seek(implementation_type& impl, int64_t offset,
file_base::seek_basis whence, asio::error_code& ec);
// Write the given data. Returns the number of bytes written.
template <typename ConstBufferSequence>
size_t write_some(implementation_type& impl,
const ConstBufferSequence& buffers, asio::error_code& ec)
{
return descriptor_service_.write_some(impl, buffers, ec);
}
// Start an asynchronous write. The data being written must be valid for the
// lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_write_some(implementation_type& impl,
const ConstBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
descriptor_service_.async_write_some(impl, buffers, handler, io_ex);
}
// Write the given data at the specified location. Returns the number of
// bytes written.
template <typename ConstBufferSequence>
size_t write_some_at(implementation_type& impl, uint64_t offset,
const ConstBufferSequence& buffers, asio::error_code& ec)
{
return descriptor_service_.write_some_at(impl, offset, buffers, ec);
}
// Start an asynchronous write at the specified location. The data being
// written must be valid for the lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_write_some_at(implementation_type& impl,
uint64_t offset, const ConstBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
descriptor_service_.async_write_some_at(
impl, offset, buffers, handler, io_ex);
}
// Read some data. Returns the number of bytes read.
template <typename MutableBufferSequence>
size_t read_some(implementation_type& impl,
const MutableBufferSequence& buffers, asio::error_code& ec)
{
return descriptor_service_.read_some(impl, buffers, ec);
}
// Start an asynchronous read. The buffer for the data being read must be
// valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_read_some(implementation_type& impl,
const MutableBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
descriptor_service_.async_read_some(impl, buffers, handler, io_ex);
}
// Read some data. Returns the number of bytes read.
template <typename MutableBufferSequence>
size_t read_some_at(implementation_type& impl, uint64_t offset,
const MutableBufferSequence& buffers, asio::error_code& ec)
{
return descriptor_service_.read_some_at(impl, offset, buffers, ec);
}
// Start an asynchronous read. The buffer for the data being read must be
// valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_read_some_at(implementation_type& impl,
uint64_t offset, const MutableBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
descriptor_service_.async_read_some_at(
impl, offset, buffers, handler, io_ex);
}
private:
// The implementation used for initiating asynchronous operations.
descriptor_service descriptor_service_;
// Cached success value to avoid accessing category singleton.
const asio::error_code success_ec_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/io_uring_file_service.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_FILE)
// && defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_FILE_SERVICE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/completion_message.hpp | //
// detail/completion_message.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_COMPLETION_MESSAGE_HPP
#define ASIO_DETAIL_COMPLETION_MESSAGE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <tuple>
#include "asio/detail/type_traits.hpp"
#include "asio/detail/utility.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Signature>
class completion_message;
template <typename R>
class completion_message<R()>
{
public:
completion_message(int)
{
}
template <typename Handler>
void receive(Handler& handler)
{
static_cast<Handler&&>(handler)();
}
};
template <typename R, typename Arg0>
class completion_message<R(Arg0)>
{
public:
template <typename T0>
completion_message(int, T0&& t0)
: arg0_(static_cast<T0&&>(t0))
{
}
template <typename Handler>
void receive(Handler& handler)
{
static_cast<Handler&&>(handler)(
static_cast<arg0_type&&>(arg0_));
}
private:
typedef decay_t<Arg0> arg0_type;
arg0_type arg0_;
};
template <typename R, typename Arg0, typename Arg1>
class completion_message<R(Arg0, Arg1)>
{
public:
template <typename T0, typename T1>
completion_message(int, T0&& t0, T1&& t1)
: arg0_(static_cast<T0&&>(t0)),
arg1_(static_cast<T1&&>(t1))
{
}
template <typename Handler>
void receive(Handler& handler)
{
static_cast<Handler&&>(handler)(
static_cast<arg0_type&&>(arg0_),
static_cast<arg1_type&&>(arg1_));
}
private:
typedef decay_t<Arg0> arg0_type;
arg0_type arg0_;
typedef decay_t<Arg1> arg1_type;
arg1_type arg1_;
};
template <typename R, typename... Args>
class completion_message<R(Args...)>
{
public:
template <typename... T>
completion_message(int, T&&... t)
: args_(static_cast<T&&>(t)...)
{
}
template <typename Handler>
void receive(Handler& h)
{
this->do_receive(h, asio::detail::index_sequence_for<Args...>());
}
private:
template <typename Handler, std::size_t... I>
void do_receive(Handler& h, asio::detail::index_sequence<I...>)
{
static_cast<Handler&&>(h)(
std::get<I>(static_cast<args_type&&>(args_))...);
}
typedef std::tuple<decay_t<Args>...> args_type;
args_type args_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_COMPLETION_MESSAGE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/keyword_tss_ptr.hpp | //
// detail/keyword_tss_ptr.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_KEYWORD_TSS_PTR_HPP
#define ASIO_DETAIL_KEYWORD_TSS_PTR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename T>
class keyword_tss_ptr
: private noncopyable
{
public:
// Constructor.
keyword_tss_ptr()
{
}
// Destructor.
~keyword_tss_ptr()
{
}
// Get the value.
operator T*() const
{
return value_;
}
// Set the value.
void operator=(T* value)
{
value_ = value;
}
private:
static ASIO_THREAD_KEYWORD T* value_;
};
template <typename T>
ASIO_THREAD_KEYWORD T* keyword_tss_ptr<T>::value_;
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
#endif // ASIO_DETAIL_KEYWORD_TSS_PTR_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/signal_init.hpp | //
// detail/signal_init.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SIGNAL_INIT_HPP
#define ASIO_DETAIL_SIGNAL_INIT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
#include <csignal>
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <int Signal = SIGPIPE>
class signal_init
{
public:
// Constructor.
signal_init()
{
std::signal(Signal, SIG_IGN);
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
#endif // ASIO_DETAIL_SIGNAL_INIT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/timer_scheduler_fwd.hpp | //
// detail/timer_scheduler_fwd.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_TIMER_SCHEDULER_FWD_HPP
#define ASIO_DETAIL_TIMER_SCHEDULER_FWD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
namespace asio {
namespace detail {
#if defined(ASIO_WINDOWS_RUNTIME)
typedef class winrt_timer_scheduler timer_scheduler;
#elif defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context timer_scheduler;
#elif defined(ASIO_HAS_IO_URING_AS_DEFAULT)
typedef class io_uring_service timer_scheduler;
#elif defined(ASIO_HAS_EPOLL)
typedef class epoll_reactor timer_scheduler;
#elif defined(ASIO_HAS_KQUEUE)
typedef class kqueue_reactor timer_scheduler;
#elif defined(ASIO_HAS_DEV_POLL)
typedef class dev_poll_reactor timer_scheduler;
#else
typedef class select_reactor timer_scheduler;
#endif
} // namespace detail
} // namespace asio
#endif // ASIO_DETAIL_TIMER_SCHEDULER_FWD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/memory.hpp | //
// detail/memory.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_MEMORY_HPP
#define ASIO_DETAIL_MEMORY_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <cstddef>
#include <cstdlib>
#include <memory>
#include <new>
#include "asio/detail/cstdint.hpp"
#include "asio/detail/throw_exception.hpp"
#if !defined(ASIO_HAS_STD_ALIGNED_ALLOC) \
&& defined(ASIO_HAS_BOOST_ALIGN)
# include <boost/align/aligned_alloc.hpp>
#endif // !defined(ASIO_HAS_STD_ALIGNED_ALLOC)
// && defined(ASIO_HAS_BOOST_ALIGN)
namespace asio {
namespace detail {
using std::allocate_shared;
using std::make_shared;
using std::shared_ptr;
using std::weak_ptr;
using std::addressof;
#if defined(ASIO_HAS_STD_TO_ADDRESS)
using std::to_address;
#else // defined(ASIO_HAS_STD_TO_ADDRESS)
template <typename T>
inline T* to_address(T* p) { return p; }
template <typename T>
inline const T* to_address(const T* p) { return p; }
template <typename T>
inline volatile T* to_address(volatile T* p) { return p; }
template <typename T>
inline const volatile T* to_address(const volatile T* p) { return p; }
#endif // defined(ASIO_HAS_STD_TO_ADDRESS)
inline void* align(std::size_t alignment,
std::size_t size, void*& ptr, std::size_t& space)
{
return std::align(alignment, size, ptr, space);
}
} // namespace detail
using std::allocator_arg_t;
# define ASIO_USES_ALLOCATOR(t) \
namespace std { \
template <typename Allocator> \
struct uses_allocator<t, Allocator> : true_type {}; \
} \
/**/
# define ASIO_REBIND_ALLOC(alloc, t) \
typename std::allocator_traits<alloc>::template rebind_alloc<t>
/**/
inline void* aligned_new(std::size_t align, std::size_t size)
{
#if defined(ASIO_HAS_STD_ALIGNED_ALLOC)
align = (align < ASIO_DEFAULT_ALIGN) ? ASIO_DEFAULT_ALIGN : align;
size = (size % align == 0) ? size : size + (align - size % align);
void* ptr = std::aligned_alloc(align, size);
if (!ptr)
{
std::bad_alloc ex;
asio::detail::throw_exception(ex);
}
return ptr;
#elif defined(ASIO_HAS_BOOST_ALIGN)
align = (align < ASIO_DEFAULT_ALIGN) ? ASIO_DEFAULT_ALIGN : align;
size = (size % align == 0) ? size : size + (align - size % align);
void* ptr = boost::alignment::aligned_alloc(align, size);
if (!ptr)
{
std::bad_alloc ex;
asio::detail::throw_exception(ex);
}
return ptr;
#elif defined(ASIO_MSVC)
align = (align < ASIO_DEFAULT_ALIGN) ? ASIO_DEFAULT_ALIGN : align;
size = (size % align == 0) ? size : size + (align - size % align);
void* ptr = _aligned_malloc(size, align);
if (!ptr)
{
std::bad_alloc ex;
asio::detail::throw_exception(ex);
}
return ptr;
#else // defined(ASIO_MSVC)
(void)align;
return ::operator new(size);
#endif // defined(ASIO_MSVC)
}
inline void aligned_delete(void* ptr)
{
#if defined(ASIO_HAS_STD_ALIGNED_ALLOC)
std::free(ptr);
#elif defined(ASIO_HAS_BOOST_ALIGN)
boost::alignment::aligned_free(ptr);
#elif defined(ASIO_MSVC)
_aligned_free(ptr);
#else // defined(ASIO_MSVC)
::operator delete(ptr);
#endif // defined(ASIO_MSVC)
}
} // namespace asio
#endif // ASIO_DETAIL_MEMORY_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/null_static_mutex.hpp | //
// detail/null_static_mutex.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_NULL_STATIC_MUTEX_HPP
#define ASIO_DETAIL_NULL_STATIC_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_HAS_THREADS)
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
struct null_static_mutex
{
typedef asio::detail::scoped_lock<null_static_mutex> scoped_lock;
// Initialise the mutex.
void init()
{
}
// Lock the mutex.
void lock()
{
}
// Unlock the mutex.
void unlock()
{
}
int unused_;
};
#define ASIO_NULL_STATIC_MUTEX_INIT { 0 }
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // !defined(ASIO_HAS_THREADS)
#endif // ASIO_DETAIL_NULL_STATIC_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_socket_recvfrom_op.hpp | //
// detail/win_iocp_socket_recvfrom_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP
#define ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename MutableBufferSequence, typename Endpoint,
typename Handler, typename IoExecutor>
class win_iocp_socket_recvfrom_op : public operation
{
public:
ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recvfrom_op);
win_iocp_socket_recvfrom_op(Endpoint& endpoint,
socket_ops::weak_cancel_token_type cancel_token,
const MutableBufferSequence& buffers, Handler& handler,
const IoExecutor& io_ex)
: operation(&win_iocp_socket_recvfrom_op::do_complete),
endpoint_(endpoint),
endpoint_size_(static_cast<int>(endpoint.capacity())),
cancel_token_(cancel_token),
buffers_(buffers),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
int& endpoint_size()
{
return endpoint_size_;
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
asio::error_code ec(result_ec);
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
win_iocp_socket_recvfrom_op* o(
static_cast<win_iocp_socket_recvfrom_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
// Check whether buffers are still valid.
if (owner)
{
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::validate(o->buffers_);
}
#endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
socket_ops::complete_iocp_recvfrom(o->cancel_token_, ec);
// Record the size of the endpoint returned by the operation.
o->endpoint_.resize(o->endpoint_size_);
ASIO_ERROR_LOCATION(ec);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, ec, bytes_transferred);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Endpoint& endpoint_;
int endpoint_size_;
socket_ops::weak_cancel_token_type cancel_token_;
MutableBufferSequence buffers_;
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/scheduler_operation.hpp | //
// detail/scheduler_operation.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SCHEDULER_OPERATION_HPP
#define ASIO_DETAIL_SCHEDULER_OPERATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/error_code.hpp"
#include "asio/detail/handler_tracking.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class scheduler;
// Base class for all operations. A function pointer is used instead of virtual
// functions to avoid the associated overhead.
class scheduler_operation ASIO_INHERIT_TRACKED_HANDLER
{
public:
typedef scheduler_operation operation_type;
void complete(void* owner, const asio::error_code& ec,
std::size_t bytes_transferred)
{
func_(owner, this, ec, bytes_transferred);
}
void destroy()
{
func_(0, this, asio::error_code(), 0);
}
protected:
typedef void (*func_type)(void*,
scheduler_operation*,
const asio::error_code&, std::size_t);
scheduler_operation(func_type func)
: next_(0),
func_(func),
task_result_(0)
{
}
// Prevents deletion through this type.
~scheduler_operation()
{
}
private:
friend class op_queue_access;
scheduler_operation* next_;
func_type func_;
protected:
friend class scheduler;
unsigned int task_result_; // Passed into bytes transferred.
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_SCHEDULER_OPERATION_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/resolve_endpoint_op.hpp | //
// detail/resolve_endpoint_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_RESOLVER_ENDPOINT_OP_HPP
#define ASIO_DETAIL_RESOLVER_ENDPOINT_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/resolve_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/error.hpp"
#include "asio/ip/basic_resolver_results.hpp"
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/win_iocp_io_context.hpp"
#else // defined(ASIO_HAS_IOCP)
# include "asio/detail/scheduler.hpp"
#endif // defined(ASIO_HAS_IOCP)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Protocol, typename Handler, typename IoExecutor>
class resolve_endpoint_op : public resolve_op
{
public:
ASIO_DEFINE_HANDLER_PTR(resolve_endpoint_op);
typedef typename Protocol::endpoint endpoint_type;
typedef asio::ip::basic_resolver_results<Protocol> results_type;
#if defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context scheduler_impl;
#else
typedef class scheduler scheduler_impl;
#endif
resolve_endpoint_op(socket_ops::weak_cancel_token_type cancel_token,
const endpoint_type& endpoint, scheduler_impl& sched,
Handler& handler, const IoExecutor& io_ex)
: resolve_op(&resolve_endpoint_op::do_complete),
cancel_token_(cancel_token),
endpoint_(endpoint),
scheduler_(sched),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
resolve_endpoint_op* o(static_cast<resolve_endpoint_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
if (owner && owner != &o->scheduler_)
{
// The operation is being run on the worker io_context. Time to perform
// the resolver operation.
// Perform the blocking endpoint resolution operation.
char host_name[NI_MAXHOST] = "";
char service_name[NI_MAXSERV] = "";
socket_ops::background_getnameinfo(o->cancel_token_, o->endpoint_.data(),
o->endpoint_.size(), host_name, NI_MAXHOST, service_name, NI_MAXSERV,
o->endpoint_.protocol().type(), o->ec_);
o->results_ = results_type::create(o->endpoint_, host_name, service_name);
// Pass operation back to main io_context for completion.
o->scheduler_.post_deferred_completion(o);
p.v = p.p = 0;
}
else
{
// The operation has been returned to the main io_context. The completion
// handler is ready to be delivered.
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
// Make a copy of the handler so that the memory can be deallocated
// before the upcall is made. Even if we're not about to make an upcall,
// a sub-object of the handler may be the true owner of the memory
// associated with the handler. Consequently, a local copy of the handler
// is required to ensure that any owning sub-object remains valid until
// after we have deallocated the memory here.
detail::binder2<Handler, asio::error_code, results_type>
handler(o->handler_, o->ec_, o->results_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "..."));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
}
private:
socket_ops::weak_cancel_token_type cancel_token_;
endpoint_type endpoint_;
scheduler_impl& scheduler_;
Handler handler_;
handler_work<Handler, IoExecutor> work_;
results_type results_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_RESOLVER_ENDPOINT_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/timer_queue_set.hpp | //
// detail/timer_queue_set.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_TIMER_QUEUE_SET_HPP
#define ASIO_DETAIL_TIMER_QUEUE_SET_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/timer_queue_base.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class timer_queue_set
{
public:
// Constructor.
ASIO_DECL timer_queue_set();
// Add a timer queue to the set.
ASIO_DECL void insert(timer_queue_base* q);
// Remove a timer queue from the set.
ASIO_DECL void erase(timer_queue_base* q);
// Determine whether all queues are empty.
ASIO_DECL bool all_empty() const;
// Get the wait duration in milliseconds.
ASIO_DECL long wait_duration_msec(long max_duration) const;
// Get the wait duration in microseconds.
ASIO_DECL long wait_duration_usec(long max_duration) const;
// Dequeue all ready timers.
ASIO_DECL void get_ready_timers(op_queue<operation>& ops);
// Dequeue all timers.
ASIO_DECL void get_all_timers(op_queue<operation>& ops);
private:
timer_queue_base* first_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/timer_queue_set.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // ASIO_DETAIL_TIMER_QUEUE_SET_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/timer_queue_ptime.hpp | //
// detail/timer_queue_ptime.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
#define ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_BOOST_DATE_TIME)
#include "asio/time_traits.hpp"
#include "asio/detail/timer_queue.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
struct forwarding_posix_time_traits : time_traits<boost::posix_time::ptime> {};
// Template specialisation for the commonly used instantation.
template <>
class timer_queue<time_traits<boost::posix_time::ptime>>
: public timer_queue_base
{
public:
// The time type.
typedef boost::posix_time::ptime time_type;
// The duration type.
typedef boost::posix_time::time_duration duration_type;
// Per-timer data.
typedef timer_queue<forwarding_posix_time_traits>::per_timer_data
per_timer_data;
// Constructor.
ASIO_DECL timer_queue();
// Destructor.
ASIO_DECL virtual ~timer_queue();
// Add a new timer to the queue. Returns true if this is the timer that is
// earliest in the queue, in which case the reactor's event demultiplexing
// function call may need to be interrupted and restarted.
ASIO_DECL bool enqueue_timer(const time_type& time,
per_timer_data& timer, wait_op* op);
// Whether there are no timers in the queue.
ASIO_DECL virtual bool empty() const;
// Get the time for the timer that is earliest in the queue.
ASIO_DECL virtual long wait_duration_msec(long max_duration) const;
// Get the time for the timer that is earliest in the queue.
ASIO_DECL virtual long wait_duration_usec(long max_duration) const;
// Dequeue all timers not later than the current time.
ASIO_DECL virtual void get_ready_timers(op_queue<operation>& ops);
// Dequeue all timers.
ASIO_DECL virtual void get_all_timers(op_queue<operation>& ops);
// Cancel and dequeue operations for the given timer.
ASIO_DECL std::size_t cancel_timer(
per_timer_data& timer, op_queue<operation>& ops,
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
// Cancel and dequeue operations for the given timer and key.
ASIO_DECL void cancel_timer_by_key(per_timer_data* timer,
op_queue<operation>& ops, void* cancellation_key);
// Move operations from one timer to another, empty timer.
ASIO_DECL void move_timer(per_timer_data& target,
per_timer_data& source);
private:
timer_queue<forwarding_posix_time_traits> impl_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/timer_queue_ptime.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_BOOST_DATE_TIME)
#endif // ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/posix_global.hpp | //
// detail/posix_global.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_POSIX_GLOBAL_HPP
#define ASIO_DETAIL_POSIX_GLOBAL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_PTHREADS)
#include <exception>
#include <pthread.h>
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename T>
struct posix_global_impl
{
// Helper function to perform initialisation.
static void do_init()
{
instance_.static_ptr_ = instance_.ptr_ = new T;
}
// Destructor automatically cleans up the global.
~posix_global_impl()
{
delete static_ptr_;
}
static ::pthread_once_t init_once_;
static T* static_ptr_;
static posix_global_impl instance_;
T* ptr_;
};
template <typename T>
::pthread_once_t posix_global_impl<T>::init_once_ = PTHREAD_ONCE_INIT;
template <typename T>
T* posix_global_impl<T>::static_ptr_ = 0;
template <typename T>
posix_global_impl<T> posix_global_impl<T>::instance_;
template <typename T>
T& posix_global()
{
int result = ::pthread_once(
&posix_global_impl<T>::init_once_,
&posix_global_impl<T>::do_init);
if (result != 0)
std::terminate();
return *posix_global_impl<T>::instance_.ptr_;
}
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_PTHREADS)
#endif // ASIO_DETAIL_POSIX_GLOBAL_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/thread_group.hpp | //
// detail/thread_group.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_THREAD_GROUP_HPP
#define ASIO_DETAIL_THREAD_GROUP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/scoped_ptr.hpp"
#include "asio/detail/thread.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class thread_group
{
public:
// Constructor initialises an empty thread group.
thread_group()
: first_(0)
{
}
// Destructor joins any remaining threads in the group.
~thread_group()
{
join();
}
// Create a new thread in the group.
template <typename Function>
void create_thread(Function f)
{
first_ = new item(f, first_);
}
// Create new threads in the group.
template <typename Function>
void create_threads(Function f, std::size_t num_threads)
{
for (std::size_t i = 0; i < num_threads; ++i)
create_thread(f);
}
// Wait for all threads in the group to exit.
void join()
{
while (first_)
{
first_->thread_.join();
item* tmp = first_;
first_ = first_->next_;
delete tmp;
}
}
// Test whether the group is empty.
bool empty() const
{
return first_ == 0;
}
private:
// Structure used to track a single thread in the group.
struct item
{
template <typename Function>
explicit item(Function f, item* next)
: thread_(f),
next_(next)
{
}
asio::detail::thread thread_;
item* next_;
};
// The first thread in the group.
item* first_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_THREAD_GROUP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_accept_op.hpp | //
// detail/io_uring_socket_accept_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_ACCEPT_OP_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_ACCEPT_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Socket, typename Protocol>
class io_uring_socket_accept_op_base : public io_uring_operation
{
public:
io_uring_socket_accept_op_base(const asio::error_code& success_ec,
socket_type socket, socket_ops::state_type state, Socket& peer,
const Protocol& protocol, typename Protocol::endpoint* peer_endpoint,
func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_socket_accept_op_base::do_prepare,
&io_uring_socket_accept_op_base::do_perform, complete_func),
socket_(socket),
state_(state),
peer_(peer),
protocol_(protocol),
peer_endpoint_(peer_endpoint),
addrlen_(peer_endpoint ? peer_endpoint->capacity() : 0)
{
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_socket_accept_op_base* o(
static_cast<io_uring_socket_accept_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
::io_uring_prep_poll_add(sqe, o->socket_, POLLIN);
}
else
{
::io_uring_prep_accept(sqe, o->socket_,
o->peer_endpoint_ ? o->peer_endpoint_->data() : 0,
o->peer_endpoint_ ? &o->addrlen_ : 0, 0);
}
}
static bool do_perform(io_uring_operation* base, bool after_completion)
{
ASIO_ASSUME(base != 0);
io_uring_socket_accept_op_base* o(
static_cast<io_uring_socket_accept_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
socket_type new_socket = invalid_socket;
std::size_t addrlen = static_cast<std::size_t>(o->addrlen_);
bool result = socket_ops::non_blocking_accept(o->socket_,
o->state_, o->peer_endpoint_ ? o->peer_endpoint_->data() : 0,
o->peer_endpoint_ ? &addrlen : 0, o->ec_, new_socket);
o->new_socket_.reset(new_socket);
o->addrlen_ = static_cast<socklen_t>(addrlen);
return result;
}
if (o->ec_ && o->ec_ == asio::error::would_block)
{
o->state_ |= socket_ops::internal_non_blocking;
return false;
}
if (after_completion && !o->ec_)
o->new_socket_.reset(static_cast<int>(o->bytes_transferred_));
return after_completion;
}
void do_assign()
{
if (new_socket_.get() != invalid_socket)
{
if (peer_endpoint_)
peer_endpoint_->resize(addrlen_);
peer_.assign(protocol_, new_socket_.get(), ec_);
if (!ec_)
new_socket_.release();
}
}
private:
socket_type socket_;
socket_ops::state_type state_;
socket_holder new_socket_;
Socket& peer_;
Protocol protocol_;
typename Protocol::endpoint* peer_endpoint_;
socklen_t addrlen_;
};
template <typename Socket, typename Protocol,
typename Handler, typename IoExecutor>
class io_uring_socket_accept_op :
public io_uring_socket_accept_op_base<Socket, Protocol>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_accept_op);
io_uring_socket_accept_op(const asio::error_code& success_ec,
socket_type socket, socket_ops::state_type state, Socket& peer,
const Protocol& protocol, typename Protocol::endpoint* peer_endpoint,
Handler& handler, const IoExecutor& io_ex)
: io_uring_socket_accept_op_base<Socket, Protocol>(
success_ec, socket, state, peer, protocol, peer_endpoint,
&io_uring_socket_accept_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_accept_op* o(static_cast<io_uring_socket_accept_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
// On success, assign new connection to peer socket object.
if (owner)
o->do_assign();
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder1<Handler, asio::error_code>
handler(o->handler_, o->ec_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
template <typename Protocol, typename PeerIoExecutor,
typename Handler, typename IoExecutor>
class io_uring_socket_move_accept_op :
private Protocol::socket::template rebind_executor<PeerIoExecutor>::other,
public io_uring_socket_accept_op_base<
typename Protocol::socket::template rebind_executor<PeerIoExecutor>::other,
Protocol>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_move_accept_op);
io_uring_socket_move_accept_op(const asio::error_code& success_ec,
const PeerIoExecutor& peer_io_ex, socket_type socket,
socket_ops::state_type state, const Protocol& protocol,
typename Protocol::endpoint* peer_endpoint, Handler& handler,
const IoExecutor& io_ex)
: peer_socket_type(peer_io_ex),
io_uring_socket_accept_op_base<peer_socket_type, Protocol>(
success_ec, socket, state, *this, protocol, peer_endpoint,
&io_uring_socket_move_accept_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_move_accept_op* o(
static_cast<io_uring_socket_move_accept_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
// On success, assign new connection to peer socket object.
if (owner)
o->do_assign();
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::move_binder2<Handler,
asio::error_code, peer_socket_type>
handler(0, static_cast<Handler&&>(o->handler_), o->ec_,
static_cast<peer_socket_type&&>(*o));
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "..."));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
typedef typename Protocol::socket::template
rebind_executor<PeerIoExecutor>::other peer_socket_type;
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_ACCEPT_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/socket_select_interrupter.hpp | //
// detail/socket_select_interrupter.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP
#define ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_WINDOWS_RUNTIME)
#if defined(ASIO_WINDOWS) \
|| defined(__CYGWIN__) \
|| defined(__SYMBIAN32__)
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class socket_select_interrupter
{
public:
// Constructor.
ASIO_DECL socket_select_interrupter();
// Destructor.
ASIO_DECL ~socket_select_interrupter();
// Recreate the interrupter's descriptors. Used after a fork.
ASIO_DECL void recreate();
// Interrupt the select call.
ASIO_DECL void interrupt();
// Reset the select interrupter. Returns true if the reset was successful.
ASIO_DECL bool reset();
// Get the read descriptor to be passed to select.
socket_type read_descriptor() const
{
return read_descriptor_;
}
private:
// Open the descriptors. Throws on error.
ASIO_DECL void open_descriptors();
// Close the descriptors.
ASIO_DECL void close_descriptors();
// The read end of a connection used to interrupt the select call. This file
// descriptor is passed to select such that when it is time to stop, a single
// byte will be written on the other end of the connection and this
// descriptor will become readable.
socket_type read_descriptor_;
// The write end of a connection used to interrupt the select call. A single
// byte may be written to this to wake up the select which is waiting for the
// other end to become readable.
socket_type write_descriptor_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/socket_select_interrupter.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS)
// || defined(__CYGWIN__)
// || defined(__SYMBIAN32__)
#endif // !defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/config.hpp | //
// detail/config.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_CONFIG_HPP
#define ASIO_DETAIL_CONFIG_HPP
// boostify: non-boost code starts here
#if !defined(ASIO_STANDALONE)
# if !defined(ASIO_ENABLE_BOOST)
# if (__cplusplus >= 201103)
# define ASIO_STANDALONE 1
# elif defined(_MSC_VER) && defined(_MSVC_LANG)
# if (_MSC_VER >= 1900) && (_MSVC_LANG >= 201103)
# define ASIO_STANDALONE 1
# endif // (_MSC_VER >= 1900) && (_MSVC_LANG >= 201103)
# endif // defined(_MSC_VER) && defined(_MSVC_LANG)
# endif // !defined(ASIO_ENABLE_BOOST)
#endif // !defined(ASIO_STANDALONE)
// Make standard library feature macros available.
#if defined(__has_include)
# if __has_include(<version>)
# include <version>
# else // __has_include(<version>)
# include <cstddef>
# endif // __has_include(<version>)
#else // defined(__has_include)
# include <cstddef>
#endif // defined(__has_include)
// boostify: non-boost code ends here
#if defined(ASIO_STANDALONE)
# define ASIO_DISABLE_BOOST_ALIGN 1
# define ASIO_DISABLE_BOOST_ARRAY 1
# define ASIO_DISABLE_BOOST_ASSERT 1
# define ASIO_DISABLE_BOOST_BIND 1
# define ASIO_DISABLE_BOOST_CHRONO 1
# define ASIO_DISABLE_BOOST_DATE_TIME 1
# define ASIO_DISABLE_BOOST_LIMITS 1
# define ASIO_DISABLE_BOOST_REGEX 1
# define ASIO_DISABLE_BOOST_STATIC_CONSTANT 1
# define ASIO_DISABLE_BOOST_THROW_EXCEPTION 1
# define ASIO_DISABLE_BOOST_WORKAROUND 1
#else // defined(ASIO_STANDALONE)
// Boost.Config library is available.
# include <boost/config.hpp>
# include <boost/version.hpp>
# define ASIO_HAS_BOOST_CONFIG 1
#endif // defined(ASIO_STANDALONE)
// Default to a header-only implementation. The user must specifically request
// separate compilation by defining either ASIO_SEPARATE_COMPILATION or
// ASIO_DYN_LINK (as a DLL/shared library implies separate compilation).
#if !defined(ASIO_HEADER_ONLY)
# if !defined(ASIO_SEPARATE_COMPILATION)
# if !defined(ASIO_DYN_LINK)
# define ASIO_HEADER_ONLY 1
# endif // !defined(ASIO_DYN_LINK)
# endif // !defined(ASIO_SEPARATE_COMPILATION)
#endif // !defined(ASIO_HEADER_ONLY)
#if defined(ASIO_HEADER_ONLY)
# define ASIO_DECL inline
#else // defined(ASIO_HEADER_ONLY)
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CODEGEARC__)
// We need to import/export our code only if the user has specifically asked
// for it by defining ASIO_DYN_LINK.
# if defined(ASIO_DYN_LINK)
// Export if this is our own source, otherwise import.
# if defined(ASIO_SOURCE)
# define ASIO_DECL __declspec(dllexport)
# else // defined(ASIO_SOURCE)
# define ASIO_DECL __declspec(dllimport)
# endif // defined(ASIO_SOURCE)
# endif // defined(ASIO_DYN_LINK)
# endif // defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CODEGEARC__)
#endif // defined(ASIO_HEADER_ONLY)
// If ASIO_DECL isn't defined yet define it now.
#if !defined(ASIO_DECL)
# define ASIO_DECL
#endif // !defined(ASIO_DECL)
// Helper macro for documentation.
#define ASIO_UNSPECIFIED(e) e
// Microsoft Visual C++ detection.
#if !defined(ASIO_MSVC)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC)
# define ASIO_MSVC BOOST_MSVC
# elif defined(_MSC_VER) && (defined(__INTELLISENSE__) \
|| (!defined(__MWERKS__) && !defined(__EDG_VERSION__)))
# define ASIO_MSVC _MSC_VER
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_MSVC)
#endif // !defined(ASIO_MSVC)
// Clang / libc++ detection.
#if defined(__clang__)
# if (__cplusplus >= 201103)
# if __has_include(<__config>)
# include <__config>
# if defined(_LIBCPP_VERSION)
# define ASIO_HAS_CLANG_LIBCXX 1
# endif // defined(_LIBCPP_VERSION)
# endif // __has_include(<__config>)
# endif // (__cplusplus >= 201103)
#endif // defined(__clang__)
// Android platform detection.
#if defined(__ANDROID__)
# include <android/api-level.h>
#endif // defined(__ANDROID__)
// Always enabled. Retained for backwards compatibility in user code.
#if !defined(ASIO_DISABLE_CXX11_MACROS)
# define ASIO_HAS_MOVE 1
# define ASIO_MOVE_ARG(type) type&&
# define ASIO_MOVE_ARG2(type1, type2) type1, type2&&
# define ASIO_NONDEDUCED_MOVE_ARG(type) type&
# define ASIO_MOVE_CAST(type) static_cast<type&&>
# define ASIO_MOVE_CAST2(type1, type2) static_cast<type1, type2&&>
# define ASIO_MOVE_OR_LVALUE(type) static_cast<type&&>
# define ASIO_MOVE_OR_LVALUE_ARG(type) type&&
# define ASIO_MOVE_OR_LVALUE_TYPE(type) type
# define ASIO_DELETED = delete
# define ASIO_HAS_VARIADIC_TEMPLATES 1
# define ASIO_HAS_CONSTEXPR 1
# define ASIO_STATIC_CONSTEXPR(type, assignment) \
static constexpr type assignment
# define ASIO_HAS_NOEXCEPT 1
# define ASIO_NOEXCEPT noexcept(true)
# define ASIO_NOEXCEPT_OR_NOTHROW noexcept(true)
# define ASIO_NOEXCEPT_IF(c) noexcept(c)
# define ASIO_HAS_DECLTYPE 1
# define ASIO_AUTO_RETURN_TYPE_PREFIX(t) auto
# define ASIO_AUTO_RETURN_TYPE_PREFIX2(t0, t1) auto
# define ASIO_AUTO_RETURN_TYPE_PREFIX3(t0, t1, t2) auto
# define ASIO_AUTO_RETURN_TYPE_SUFFIX(expr) -> decltype expr
# define ASIO_HAS_ALIAS_TEMPLATES 1
# define ASIO_HAS_DEFAULT_FUNCTION_TEMPLATE_ARGUMENTS 1
# define ASIO_HAS_ENUM_CLASS 1
# define ASIO_HAS_REF_QUALIFIED_FUNCTIONS 1
# define ASIO_LVALUE_REF_QUAL &
# define ASIO_RVALUE_REF_QUAL &&
# define ASIO_HAS_USER_DEFINED_LITERALS 1
# define ASIO_HAS_ALIGNOF 1
# define ASIO_ALIGNOF(T) alignof(T)
# define ASIO_HAS_STD_ALIGN 1
# define ASIO_HAS_STD_SYSTEM_ERROR 1
# define ASIO_ERROR_CATEGORY_NOEXCEPT noexcept(true)
# define ASIO_HAS_STD_ARRAY 1
# define ASIO_HAS_STD_SHARED_PTR 1
# define ASIO_HAS_STD_ALLOCATOR_ARG 1
# define ASIO_HAS_STD_ATOMIC 1
# define ASIO_HAS_STD_CHRONO 1
# define ASIO_HAS_STD_ADDRESSOF 1
# define ASIO_HAS_STD_FUNCTION 1
# define ASIO_HAS_STD_REFERENCE_WRAPPER 1
# define ASIO_HAS_STD_TYPE_TRAITS 1
# define ASIO_HAS_NULLPTR 1
# define ASIO_HAS_CXX11_ALLOCATORS 1
# define ASIO_HAS_CSTDINT 1
# define ASIO_HAS_STD_THREAD 1
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
# define ASIO_HAS_STD_CALL_ONCE 1
# define ASIO_HAS_STD_FUTURE 1
# define ASIO_HAS_STD_TUPLE 1
# define ASIO_HAS_STD_IOSTREAM_MOVE 1
# define ASIO_HAS_STD_EXCEPTION_PTR 1
# define ASIO_HAS_STD_NESTED_EXCEPTION 1
# define ASIO_HAS_STD_HASH 1
#endif // !defined(ASIO_DISABLE_CXX11_MACROS)
// Support for static constexpr with default initialisation.
#if !defined(ASIO_STATIC_CONSTEXPR_DEFAULT_INIT)
# if defined(__GNUC__)
# if (__GNUC__ >= 8)
# define ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \
static constexpr const type name{}
# else // (__GNUC__ >= 8)
# define ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \
static const type name
# endif // (__GNUC__ >= 8)
# elif defined(ASIO_MSVC)
# define ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \
static const type name
# else // defined(ASIO_MSVC)
# define ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(type, name) \
static constexpr const type name{}
# endif // defined(ASIO_MSVC)
#endif // !defined(ASIO_STATIC_CONSTEXPR_DEFAULT_INIT)
// Support noexcept on function types on compilers known to allow it.
#if !defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
# if !defined(ASIO_DISABLE_NOEXCEPT_FUNCTION_TYPE)
# if defined(__clang__)
# if (__cplusplus >= 202002)
# define ASIO_HAS_NOEXCEPT_FUNCTION_TYPE 1
# endif // (__cplusplus >= 202002)
# elif defined(__GNUC__)
# if (__cplusplus >= 202002)
# define ASIO_HAS_NOEXCEPT_FUNCTION_TYPE 1
# endif // (__cplusplus >= 202002)
# elif defined(ASIO_MSVC)
# if (_MSC_VER >= 1900 && _MSVC_LANG >= 202002)
# define ASIO_HAS_NOEXCEPT_FUNCTION_TYPE 1
# endif // (_MSC_VER >= 1900 && _MSVC_LANG >= 202002)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_NOEXCEPT_FUNCTION_TYPE)
#endif // !defined(ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
// Support return type deduction on compilers known to allow it.
#if !defined(ASIO_HAS_RETURN_TYPE_DEDUCTION)
# if !defined(ASIO_DISABLE_RETURN_TYPE_DEDUCTION)
# if defined(__clang__)
# if __has_feature(__cxx_return_type_deduction__)
# define ASIO_HAS_RETURN_TYPE_DEDUCTION 1
# endif // __has_feature(__cxx_return_type_deduction__)
# elif (__cplusplus >= 201402)
# define ASIO_HAS_RETURN_TYPE_DEDUCTION 1
# elif defined(__cpp_return_type_deduction)
# if (__cpp_return_type_deduction >= 201304)
# define ASIO_HAS_RETURN_TYPE_DEDUCTION 1
# endif // (__cpp_return_type_deduction >= 201304)
# elif defined(ASIO_MSVC)
# if (_MSC_VER >= 1900 && _MSVC_LANG >= 201402)
# define ASIO_HAS_RETURN_TYPE_DEDUCTION 1
# endif // (_MSC_VER >= 1900 && _MSVC_LANG >= 201402)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_RETURN_TYPE_DEDUCTION)
#endif // !defined(ASIO_HAS_RETURN_TYPE_DEDUCTION)
// Support concepts on compilers known to allow them.
#if !defined(ASIO_HAS_CONCEPTS)
# if !defined(ASIO_DISABLE_CONCEPTS)
# if defined(__cpp_concepts)
# define ASIO_HAS_CONCEPTS 1
# if (__cpp_concepts >= 201707)
# define ASIO_CONCEPT concept
# else // (__cpp_concepts >= 201707)
# define ASIO_CONCEPT concept bool
# endif // (__cpp_concepts >= 201707)
# endif // defined(__cpp_concepts)
# endif // !defined(ASIO_DISABLE_CONCEPTS)
#endif // !defined(ASIO_HAS_CONCEPTS)
// Support concepts on compilers known to allow them.
#if !defined(ASIO_HAS_STD_CONCEPTS)
# if !defined(ASIO_DISABLE_STD_CONCEPTS)
# if defined(ASIO_HAS_CONCEPTS)
# if (__cpp_lib_concepts >= 202002L)
# define ASIO_HAS_STD_CONCEPTS 1
# endif // (__cpp_concepts >= 202002L)
# endif // defined(ASIO_HAS_CONCEPTS)
# endif // !defined(ASIO_DISABLE_STD_CONCEPTS)
#endif // !defined(ASIO_HAS_STD_CONCEPTS)
// Support template variables on compilers known to allow it.
#if !defined(ASIO_HAS_VARIABLE_TEMPLATES)
# if !defined(ASIO_DISABLE_VARIABLE_TEMPLATES)
# if defined(__clang__)
# if (__cplusplus >= 201402)
# if __has_feature(__cxx_variable_templates__)
# define ASIO_HAS_VARIABLE_TEMPLATES 1
# endif // __has_feature(__cxx_variable_templates__)
# endif // (__cplusplus >= 201402)
# elif defined(__GNUC__) && !defined(__INTEL_COMPILER)
# if (__GNUC__ >= 6)
# if (__cplusplus >= 201402)
# define ASIO_HAS_VARIABLE_TEMPLATES 1
# endif // (__cplusplus >= 201402)
# endif // (__GNUC__ >= 6)
# endif // defined(__GNUC__) && !defined(__INTEL_COMPILER)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1901)
# define ASIO_HAS_VARIABLE_TEMPLATES 1
# endif // (_MSC_VER >= 1901)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_VARIABLE_TEMPLATES)
#endif // !defined(ASIO_HAS_VARIABLE_TEMPLATES)
// Support SFINAEd template variables on compilers known to allow it.
#if !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
# if !defined(ASIO_DISABLE_SFINAE_VARIABLE_TEMPLATES)
# if defined(__clang__)
# if (__cplusplus >= 201703)
# if __has_feature(__cxx_variable_templates__)
# define ASIO_HAS_SFINAE_VARIABLE_TEMPLATES 1
# endif // __has_feature(__cxx_variable_templates__)
# endif // (__cplusplus >= 201703)
# elif defined(__GNUC__)
# if ((__GNUC__ == 8) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 8)
# if (__cplusplus >= 201402)
# define ASIO_HAS_SFINAE_VARIABLE_TEMPLATES 1
# endif // (__cplusplus >= 201402)
# endif // ((__GNUC__ == 8) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 8)
# endif // defined(__GNUC__)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1901)
# define ASIO_HAS_SFINAE_VARIABLE_TEMPLATES 1
# endif // (_MSC_VER >= 1901)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_SFINAE_VARIABLE_TEMPLATES)
#endif // !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
// Support SFINAE use of constant expressions on compilers known to allow it.
#if !defined(ASIO_HAS_CONSTANT_EXPRESSION_SFINAE)
# if !defined(ASIO_DISABLE_CONSTANT_EXPRESSION_SFINAE)
# if defined(__clang__)
# if (__cplusplus >= 201402)
# define ASIO_HAS_CONSTANT_EXPRESSION_SFINAE 1
# endif // (__cplusplus >= 201402)
# elif defined(__GNUC__) && !defined(__INTEL_COMPILER)
# if (__GNUC__ >= 7)
# if (__cplusplus >= 201402)
# define ASIO_HAS_CONSTANT_EXPRESSION_SFINAE 1
# endif // (__cplusplus >= 201402)
# endif // (__GNUC__ >= 7)
# endif // defined(__GNUC__) && !defined(__INTEL_COMPILER)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1901)
# define ASIO_HAS_CONSTANT_EXPRESSION_SFINAE 1
# endif // (_MSC_VER >= 1901)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_CONSTANT_EXPRESSION_SFINAE)
#endif // !defined(ASIO_HAS_CONSTANT_EXPRESSION_SFINAE)
// Enable workarounds for lack of working expression SFINAE.
#if !defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
# if !defined(ASIO_DISABLE_WORKING_EXPRESSION_SFINAE)
# if !defined(ASIO_MSVC) && !defined(__INTEL_COMPILER)
# if (__cplusplus >= 201103)
# define ASIO_HAS_WORKING_EXPRESSION_SFINAE 1
# endif // (__cplusplus >= 201103)
# elif defined(ASIO_MSVC) && (_MSC_VER >= 1929)
# if (_MSVC_LANG >= 202000)
# define ASIO_HAS_WORKING_EXPRESSION_SFINAE 1
# endif // (_MSVC_LANG >= 202000)
# endif // defined(ASIO_MSVC) && (_MSC_VER >= 1929)
# endif // !defined(ASIO_DISABLE_WORKING_EXPRESSION_SFINAE)
#endif // !defined(ASIO_HAS_WORKING_EXPRESSION_SFINAE)
// Support for capturing parameter packs in lambdas.
#if !defined(ASIO_HAS_VARIADIC_LAMBDA_CAPTURES)
# if !defined(ASIO_DISABLE_VARIADIC_LAMBDA_CAPTURES)
# if defined(__GNUC__)
# if (__GNUC__ >= 6)
# define ASIO_HAS_VARIADIC_LAMBDA_CAPTURES 1
# endif // (__GNUC__ >= 6)
# elif defined(ASIO_MSVC)
# if (_MSVC_LANG >= 201103)
# define ASIO_HAS_VARIADIC_LAMBDA_CAPTURES 1
# endif // (_MSC_LANG >= 201103)
# else // defined(ASIO_MSVC)
# if (__cplusplus >= 201103)
# define ASIO_HAS_VARIADIC_LAMBDA_CAPTURES 1
# endif // (__cplusplus >= 201103)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_VARIADIC_LAMBDA_CAPTURES)
#endif // !defined(ASIO_HAS_VARIADIC_LAMBDA_CAPTURES)
// Support for inline variables.
#if !defined(ASIO_HAS_INLINE_VARIABLES)
# if !defined(ASIO_DISABLE_INLINE_VARIABLES)
# if (__cplusplus >= 201703) && (__cpp_inline_variables >= 201606)
# define ASIO_HAS_INLINE_VARIABLES 1
# define ASIO_INLINE_VARIABLE inline
# endif // (__cplusplus >= 201703) && (__cpp_inline_variables >= 201606)
# endif // !defined(ASIO_DISABLE_INLINE_VARIABLES)
#endif // !defined(ASIO_HAS_INLINE_VARIABLES)
#if !defined(ASIO_INLINE_VARIABLE)
# define ASIO_INLINE_VARIABLE
#endif // !defined(ASIO_INLINE_VARIABLE)
// Default alignment.
#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
# define ASIO_DEFAULT_ALIGN __STDCPP_DEFAULT_NEW_ALIGNMENT__
#elif defined(__GNUC__)
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
# define ASIO_DEFAULT_ALIGN alignof(std::max_align_t)
# else // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
# define ASIO_DEFAULT_ALIGN alignof(max_align_t)
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
#else // defined(__GNUC__)
# define ASIO_DEFAULT_ALIGN alignof(std::max_align_t)
#endif // defined(__GNUC__)
// Standard library support for aligned allocation.
#if !defined(ASIO_HAS_STD_ALIGNED_ALLOC)
# if !defined(ASIO_DISABLE_STD_ALIGNED_ALLOC)
# if (__cplusplus >= 201703)
# if defined(__clang__)
# if defined(ASIO_HAS_CLANG_LIBCXX)
# if (_LIBCPP_STD_VER > 14) && defined(_LIBCPP_HAS_ALIGNED_ALLOC) \
&& !defined(_LIBCPP_MSVCRT) && !defined(__MINGW32__)
# if defined(__ANDROID__) && (__ANDROID_API__ >= 28)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# elif defined(__APPLE__)
# if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
# if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
# elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
# if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // (__IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
# elif defined(__TV_OS_VERSION_MIN_REQUIRED)
# if (__TV_OS_VERSION_MIN_REQUIRED >= 130000)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // (__TV_OS_VERSION_MIN_REQUIRED >= 130000)
# elif defined(__WATCH_OS_VERSION_MIN_REQUIRED)
# if (__WATCH_OS_VERSION_MIN_REQUIRED >= 60000)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // (__WATCH_OS_VERSION_MIN_REQUIRED >= 60000)
# endif // defined(__WATCH_OS_X_VERSION_MIN_REQUIRED)
# else // defined(__APPLE__)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // defined(__APPLE__)
# endif // (_LIBCPP_STD_VER > 14) && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
// && !defined(_LIBCPP_MSVCRT) && !defined(__MINGW32__)
# elif defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
# elif defined(__GNUC__)
# if ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 7)
# if defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
# define ASIO_HAS_STD_ALIGNED_ALLOC 1
# endif // defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
# endif // ((__GNUC__ == 7) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 7)
# endif // defined(__GNUC__)
# endif // (__cplusplus >= 201703)
# endif // !defined(ASIO_DISABLE_STD_ALIGNED_ALLOC)
#endif // !defined(ASIO_HAS_STD_ALIGNED_ALLOC)
// Boost support for chrono.
#if !defined(ASIO_HAS_BOOST_CHRONO)
# if !defined(ASIO_DISABLE_BOOST_CHRONO)
# if defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 104700)
# define ASIO_HAS_BOOST_CHRONO 1
# endif // defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 104700)
# endif // !defined(ASIO_DISABLE_BOOST_CHRONO)
#endif // !defined(ASIO_HAS_BOOST_CHRONO)
// Some form of chrono library is available.
#if !defined(ASIO_HAS_CHRONO)
# if defined(ASIO_HAS_STD_CHRONO) \
|| defined(ASIO_HAS_BOOST_CHRONO)
# define ASIO_HAS_CHRONO 1
# endif // defined(ASIO_HAS_STD_CHRONO)
// || defined(ASIO_HAS_BOOST_CHRONO)
#endif // !defined(ASIO_HAS_CHRONO)
// Boost support for the DateTime library.
#if !defined(ASIO_HAS_BOOST_DATE_TIME)
# if !defined(ASIO_DISABLE_BOOST_DATE_TIME)
# define ASIO_HAS_BOOST_DATE_TIME 1
# endif // !defined(ASIO_DISABLE_BOOST_DATE_TIME)
#endif // !defined(ASIO_HAS_BOOST_DATE_TIME)
// Boost support for the Coroutine library.
#if !defined(ASIO_HAS_BOOST_COROUTINE)
# if !defined(ASIO_DISABLE_BOOST_COROUTINE)
# define ASIO_HAS_BOOST_COROUTINE 1
# endif // !defined(ASIO_DISABLE_BOOST_COROUTINE)
#endif // !defined(ASIO_HAS_BOOST_COROUTINE)
// Boost support for the Context library's fibers.
#if !defined(ASIO_HAS_BOOST_CONTEXT_FIBER)
# if !defined(ASIO_DISABLE_BOOST_CONTEXT_FIBER)
# if defined(__clang__)
# if (__cplusplus >= 201103)
# define ASIO_HAS_BOOST_CONTEXT_FIBER 1
# endif // (__cplusplus >= 201103)
# elif defined(__GNUC__)
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4)
# if (__cplusplus >= 201103) || defined(__GXX_EXPERIMENTAL_CXX0X__)
# define ASIO_HAS_BOOST_CONTEXT_FIBER 1
# endif // (__cplusplus >= 201103) || defined(__GXX_EXPERIMENTAL_CXX0X__)
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4)
# endif // defined(__GNUC__)
# if defined(ASIO_MSVC)
# if (_MSVC_LANG >= 201103)
# define ASIO_HAS_BOOST_CONTEXT_FIBER 1
# endif // (_MSC_LANG >= 201103)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_BOOST_CONTEXT_FIBER)
#endif // !defined(ASIO_HAS_BOOST_CONTEXT_FIBER)
// Standard library support for std::string_view.
#if !defined(ASIO_HAS_STD_STRING_VIEW)
# if !defined(ASIO_DISABLE_STD_STRING_VIEW)
# if defined(__clang__)
# if defined(ASIO_HAS_CLANG_LIBCXX)
# if (__cplusplus >= 201402)
# if __has_include(<string_view>)
# define ASIO_HAS_STD_STRING_VIEW 1
# endif // __has_include(<string_view>)
# endif // (__cplusplus >= 201402)
# else // defined(ASIO_HAS_CLANG_LIBCXX)
# if (__cplusplus >= 201703)
# if __has_include(<string_view>)
# define ASIO_HAS_STD_STRING_VIEW 1
# endif // __has_include(<string_view>)
# endif // (__cplusplus >= 201703)
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
# elif defined(__GNUC__)
# if (__GNUC__ >= 7)
# if (__cplusplus >= 201703)
# define ASIO_HAS_STD_STRING_VIEW 1
# endif // (__cplusplus >= 201703)
# endif // (__GNUC__ >= 7)
# elif defined(ASIO_MSVC)
# if (_MSC_VER >= 1910 && _MSVC_LANG >= 201703)
# define ASIO_HAS_STD_STRING_VIEW 1
# endif // (_MSC_VER >= 1910 && _MSVC_LANG >= 201703)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_STD_STRING_VIEW)
#endif // !defined(ASIO_HAS_STD_STRING_VIEW)
// Standard library support for std::experimental::string_view.
#if !defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
# if !defined(ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW)
# if defined(__clang__)
# if defined(ASIO_HAS_CLANG_LIBCXX)
# if (_LIBCPP_VERSION < 7000)
# if (__cplusplus >= 201402)
# if __has_include(<experimental/string_view>)
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
# endif // __has_include(<experimental/string_view>)
# endif // (__cplusplus >= 201402)
# endif // (_LIBCPP_VERSION < 7000)
# else // defined(ASIO_HAS_CLANG_LIBCXX)
# if (__cplusplus >= 201402)
# if __has_include(<experimental/string_view>)
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
# endif // __has_include(<experimental/string_view>)
# endif // (__cplusplus >= 201402)
# endif // // defined(ASIO_HAS_CLANG_LIBCXX)
# elif defined(__GNUC__)
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
# if (__cplusplus >= 201402)
# define ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW 1
# endif // (__cplusplus >= 201402)
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4)
# endif // defined(__GNUC__)
# endif // !defined(ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW)
#endif // !defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
// Standard library has a string_view that we can use.
#if !defined(ASIO_HAS_STRING_VIEW)
# if !defined(ASIO_DISABLE_STRING_VIEW)
# if defined(ASIO_HAS_STD_STRING_VIEW)
# define ASIO_HAS_STRING_VIEW 1
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
# define ASIO_HAS_STRING_VIEW 1
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW)
# endif // !defined(ASIO_DISABLE_STRING_VIEW)
#endif // !defined(ASIO_HAS_STRING_VIEW)
// Standard library has invoke_result (which supersedes result_of).
#if !defined(ASIO_HAS_STD_INVOKE_RESULT)
# if !defined(ASIO_DISABLE_STD_INVOKE_RESULT)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1911 && _MSVC_LANG >= 201703)
# define ASIO_HAS_STD_INVOKE_RESULT 1
# endif // (_MSC_VER >= 1911 && _MSVC_LANG >= 201703)
# else // defined(ASIO_MSVC)
# if (__cplusplus >= 201703) && (__cpp_lib_is_invocable >= 201703)
# define ASIO_HAS_STD_INVOKE_RESULT 1
# endif // (__cplusplus >= 201703) && (__cpp_lib_is_invocable >= 201703)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_STD_INVOKE_RESULT)
#endif // !defined(ASIO_HAS_STD_INVOKE_RESULT)
// Standard library support for std::any.
#if !defined(ASIO_HAS_STD_ANY)
# if !defined(ASIO_DISABLE_STD_ANY)
# if defined(__clang__)
# if (__cplusplus >= 201703)
# if __has_include(<any>)
# define ASIO_HAS_STD_ANY 1
# endif // __has_include(<any>)
# endif // (__cplusplus >= 201703)
# elif defined(__GNUC__)
# if (__GNUC__ >= 7)
# if (__cplusplus >= 201703)
# define ASIO_HAS_STD_ANY 1
# endif // (__cplusplus >= 201703)
# endif // (__GNUC__ >= 7)
# endif // defined(__GNUC__)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703)
# define ASIO_HAS_STD_ANY 1
# endif // (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_STD_ANY)
#endif // !defined(ASIO_HAS_STD_ANY)
// Standard library support for std::variant.
#if !defined(ASIO_HAS_STD_VARIANT)
# if !defined(ASIO_DISABLE_STD_VARIANT)
# if defined(__clang__)
# if (__cplusplus >= 201703)
# if __has_include(<variant>)
# define ASIO_HAS_STD_VARIANT 1
# endif // __has_include(<variant>)
# endif // (__cplusplus >= 201703)
# elif defined(__GNUC__)
# if (__GNUC__ >= 7)
# if (__cplusplus >= 201703)
# define ASIO_HAS_STD_VARIANT 1
# endif // (__cplusplus >= 201703)
# endif // (__GNUC__ >= 7)
# endif // defined(__GNUC__)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703)
# define ASIO_HAS_STD_VARIANT 1
# endif // (_MSC_VER >= 1910) && (_MSVC_LANG >= 201703)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_STD_VARIANT)
#endif // !defined(ASIO_HAS_STD_VARIANT)
// Standard library support for std::source_location.
#if !defined(ASIO_HAS_STD_SOURCE_LOCATION)
# if !defined(ASIO_DISABLE_STD_SOURCE_LOCATION)
// ...
# endif // !defined(ASIO_DISABLE_STD_SOURCE_LOCATION)
#endif // !defined(ASIO_HAS_STD_SOURCE_LOCATION)
// Standard library support for std::experimental::source_location.
#if !defined(ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION)
# if !defined(ASIO_DISABLE_STD_EXPERIMENTAL_SOURCE_LOCATION)
# if defined(__GNUC__)
# if (__cplusplus >= 201709)
# if __has_include(<experimental/source_location>)
# define ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION 1
# endif // __has_include(<experimental/source_location>)
# endif // (__cplusplus >= 201709)
# endif // defined(__GNUC__)
# endif // !defined(ASIO_DISABLE_STD_EXPERIMENTAL_SOURCE_LOCATION)
#endif // !defined(ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION)
// Standard library has a source_location that we can use.
#if !defined(ASIO_HAS_SOURCE_LOCATION)
# if !defined(ASIO_DISABLE_SOURCE_LOCATION)
# if defined(ASIO_HAS_STD_SOURCE_LOCATION)
# define ASIO_HAS_SOURCE_LOCATION 1
# elif defined(ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION)
# define ASIO_HAS_SOURCE_LOCATION 1
# endif // defined(ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION)
# endif // !defined(ASIO_DISABLE_SOURCE_LOCATION)
#endif // !defined(ASIO_HAS_SOURCE_LOCATION)
// Boost support for source_location and system errors.
#if !defined(ASIO_HAS_BOOST_SOURCE_LOCATION)
# if !defined(ASIO_DISABLE_BOOST_SOURCE_LOCATION)
# if defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 107900)
# define ASIO_HAS_BOOST_SOURCE_LOCATION 1
# endif // defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 107900)
# endif // !defined(ASIO_DISABLE_BOOST_SOURCE_LOCATION)
#endif // !defined(ASIO_HAS_BOOST_SOURCE_LOCATION)
// Helper macros for working with Boost source locations.
#if defined(ASIO_HAS_BOOST_SOURCE_LOCATION)
# define ASIO_SOURCE_LOCATION_PARAM \
, const boost::source_location& loc
# define ASIO_SOURCE_LOCATION_DEFAULTED_PARAM \
, const boost::source_location& loc = BOOST_CURRENT_LOCATION
# define ASIO_SOURCE_LOCATION_ARG , loc
#else // if defined(ASIO_HAS_BOOST_SOURCE_LOCATION)
# define ASIO_SOURCE_LOCATION_PARAM
# define ASIO_SOURCE_LOCATION_DEFAULTED_PARAM
# define ASIO_SOURCE_LOCATION_ARG
#endif // if defined(ASIO_HAS_BOOST_SOURCE_LOCATION)
// Standard library support for std::index_sequence.
#if !defined(ASIO_HAS_STD_INDEX_SEQUENCE)
# if !defined(ASIO_DISABLE_STD_INDEX_SEQUENCE)
# if defined(__clang__)
# if (__cplusplus >= 201402)
# define ASIO_HAS_STD_INDEX_SEQUENCE 1
# endif // (__cplusplus >= 201402)
# elif defined(__GNUC__)
# if (__GNUC__ >= 7)
# if (__cplusplus >= 201402)
# define ASIO_HAS_STD_INDEX_SEQUENCE 1
# endif // (__cplusplus >= 201402)
# endif // (__GNUC__ >= 7)
# endif // defined(__GNUC__)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1910) && (_MSVC_LANG >= 201402)
# define ASIO_HAS_STD_INDEX_SEQUENCE 1
# endif // (_MSC_VER >= 1910) && (_MSVC_LANG >= 201402)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_STD_INDEX_SEQUENCE)
#endif // !defined(ASIO_HAS_STD_INDEX_SEQUENCE)
// Windows App target. Windows but with a limited API.
#if !defined(ASIO_WINDOWS_APP)
# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0603)
# include <winapifamily.h>
# if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \
|| WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)) \
&& !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define ASIO_WINDOWS_APP 1
# endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
// && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0603)
#endif // !defined(ASIO_WINDOWS_APP)
// Legacy WinRT target. Windows App is preferred.
#if !defined(ASIO_WINDOWS_RUNTIME)
# if !defined(ASIO_WINDOWS_APP)
# if defined(__cplusplus_winrt)
# include <winapifamily.h>
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) \
&& !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define ASIO_WINDOWS_RUNTIME 1
# endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
// && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# endif // defined(__cplusplus_winrt)
# endif // !defined(ASIO_WINDOWS_APP)
#endif // !defined(ASIO_WINDOWS_RUNTIME)
// Windows target. Excludes WinRT but includes Windows App targets.
#if !defined(ASIO_WINDOWS)
# if !defined(ASIO_WINDOWS_RUNTIME)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
# define ASIO_WINDOWS 1
# elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# define ASIO_WINDOWS 1
# elif defined(ASIO_WINDOWS_APP)
# define ASIO_WINDOWS 1
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
# endif // !defined(ASIO_WINDOWS_RUNTIME)
#endif // !defined(ASIO_WINDOWS)
// Windows: target OS version.
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS)
# if defined(_MSC_VER) || (defined(__BORLANDC__) && !defined(__clang__))
# pragma message( \
"Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:\n"\
"- add -D_WIN32_WINNT=0x0601 to the compiler command line; or\n"\
"- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.\n"\
"Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).")
# else // defined(_MSC_VER) || (defined(__BORLANDC__) && !defined(__clang__))
# warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
# warning For example, add -D_WIN32_WINNT=0x0601 to the compiler command line.
# warning Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
# endif // defined(_MSC_VER) || (defined(__BORLANDC__) && !defined(__clang__))
# define _WIN32_WINNT 0x0601
# endif // !defined(_WIN32_WINNT) && !defined(_WIN32_WINDOWS)
# if defined(_MSC_VER)
# if defined(_WIN32) && !defined(WIN32)
# if !defined(_WINSOCK2API_)
# define WIN32 // Needed for correct types in winsock2.h
# else // !defined(_WINSOCK2API_)
# error Please define the macro WIN32 in your compiler options
# endif // !defined(_WINSOCK2API_)
# endif // defined(_WIN32) && !defined(WIN32)
# endif // defined(_MSC_VER)
# if defined(__BORLANDC__)
# if defined(__WIN32__) && !defined(WIN32)
# if !defined(_WINSOCK2API_)
# define WIN32 // Needed for correct types in winsock2.h
# else // !defined(_WINSOCK2API_)
# error Please define the macro WIN32 in your compiler options
# endif // !defined(_WINSOCK2API_)
# endif // defined(__WIN32__) && !defined(WIN32)
# endif // defined(__BORLANDC__)
# if defined(__CYGWIN__)
# if !defined(__USE_W32_SOCKETS)
# error You must add -D__USE_W32_SOCKETS to your compiler options.
# endif // !defined(__USE_W32_SOCKETS)
# endif // defined(__CYGWIN__)
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
// Windows: minimise header inclusion.
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if !defined(ASIO_NO_WIN32_LEAN_AND_MEAN)
# if !defined(WIN32_LEAN_AND_MEAN)
# define WIN32_LEAN_AND_MEAN
# endif // !defined(WIN32_LEAN_AND_MEAN)
# endif // !defined(ASIO_NO_WIN32_LEAN_AND_MEAN)
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
// Windows: suppress definition of "min" and "max" macros.
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if !defined(ASIO_NO_NOMINMAX)
# if !defined(NOMINMAX)
# define NOMINMAX 1
# endif // !defined(NOMINMAX)
# endif // !defined(ASIO_NO_NOMINMAX)
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
// Windows: IO Completion Ports.
#if !defined(ASIO_HAS_IOCP)
# if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)
# if !defined(UNDER_CE) && !defined(ASIO_WINDOWS_APP)
# if !defined(ASIO_DISABLE_IOCP)
# define ASIO_HAS_IOCP 1
# endif // !defined(ASIO_DISABLE_IOCP)
# endif // !defined(UNDER_CE) && !defined(ASIO_WINDOWS_APP)
# endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400)
# endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
#endif // !defined(ASIO_HAS_IOCP)
// On POSIX (and POSIX-like) platforms we need to include unistd.h in order to
// get access to the various platform feature macros, e.g. to be able to test
// for threads support.
#if !defined(ASIO_HAS_UNISTD_H)
# if !defined(ASIO_HAS_BOOST_CONFIG)
# if defined(unix) \
|| defined(__unix) \
|| defined(_XOPEN_SOURCE) \
|| defined(_POSIX_SOURCE) \
|| (defined(__MACH__) && defined(__APPLE__)) \
|| defined(__FreeBSD__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
|| defined(__HAIKU__)
# define ASIO_HAS_UNISTD_H 1
# endif
# endif // !defined(ASIO_HAS_BOOST_CONFIG)
#endif // !defined(ASIO_HAS_UNISTD_H)
#if defined(ASIO_HAS_UNISTD_H)
# include <unistd.h>
#endif // defined(ASIO_HAS_UNISTD_H)
// Linux: epoll, eventfd, timerfd and io_uring.
#if defined(__linux__)
# include <linux/version.h>
# if !defined(ASIO_HAS_EPOLL)
# if !defined(ASIO_DISABLE_EPOLL)
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45)
# define ASIO_HAS_EPOLL 1
# endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45)
# endif // !defined(ASIO_DISABLE_EPOLL)
# endif // !defined(ASIO_HAS_EPOLL)
# if !defined(ASIO_HAS_EVENTFD)
# if !defined(ASIO_DISABLE_EVENTFD)
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
# define ASIO_HAS_EVENTFD 1
# endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
# endif // !defined(ASIO_DISABLE_EVENTFD)
# endif // !defined(ASIO_HAS_EVENTFD)
# if !defined(ASIO_HAS_TIMERFD)
# if defined(ASIO_HAS_EPOLL)
# if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8)
# define ASIO_HAS_TIMERFD 1
# endif // (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8)
# endif // defined(ASIO_HAS_EPOLL)
# endif // !defined(ASIO_HAS_TIMERFD)
# if defined(ASIO_HAS_IO_URING)
# if LINUX_VERSION_CODE < KERNEL_VERSION(5,10,0)
# error Linux kernel 5.10 or later is required to support io_uring
# endif // LINUX_VERSION_CODE < KERNEL_VERSION(5,10,0)
# endif // defined(ASIO_HAS_IO_URING)
#endif // defined(__linux__)
// Linux: io_uring is used instead of epoll.
#if !defined(ASIO_HAS_IO_URING_AS_DEFAULT)
# if !defined(ASIO_HAS_EPOLL) && defined(ASIO_HAS_IO_URING)
# define ASIO_HAS_IO_URING_AS_DEFAULT 1
# endif // !defined(ASIO_HAS_EPOLL) && defined(ASIO_HAS_IO_URING)
#endif // !defined(ASIO_HAS_IO_URING_AS_DEFAULT)
// Mac OS X, FreeBSD, NetBSD, OpenBSD: kqueue.
#if (defined(__MACH__) && defined(__APPLE__)) \
|| defined(__FreeBSD__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__)
# if !defined(ASIO_HAS_KQUEUE)
# if !defined(ASIO_DISABLE_KQUEUE)
# define ASIO_HAS_KQUEUE 1
# endif // !defined(ASIO_DISABLE_KQUEUE)
# endif // !defined(ASIO_HAS_KQUEUE)
#endif // (defined(__MACH__) && defined(__APPLE__))
// || defined(__FreeBSD__)
// || defined(__NetBSD__)
// || defined(__OpenBSD__)
// Solaris: /dev/poll.
#if defined(__sun)
# if !defined(ASIO_HAS_DEV_POLL)
# if !defined(ASIO_DISABLE_DEV_POLL)
# define ASIO_HAS_DEV_POLL 1
# endif // !defined(ASIO_DISABLE_DEV_POLL)
# endif // !defined(ASIO_HAS_DEV_POLL)
#endif // defined(__sun)
// Serial ports.
#if !defined(ASIO_HAS_SERIAL_PORT)
# if defined(ASIO_HAS_IOCP) \
|| !defined(ASIO_WINDOWS) \
&& !defined(ASIO_WINDOWS_RUNTIME) \
&& !defined(__CYGWIN__)
# if !defined(__SYMBIAN32__)
# if !defined(ASIO_DISABLE_SERIAL_PORT)
# define ASIO_HAS_SERIAL_PORT 1
# endif // !defined(ASIO_DISABLE_SERIAL_PORT)
# endif // !defined(__SYMBIAN32__)
# endif // defined(ASIO_HAS_IOCP)
// || !defined(ASIO_WINDOWS)
// && !defined(ASIO_WINDOWS_RUNTIME)
// && !defined(__CYGWIN__)
#endif // !defined(ASIO_HAS_SERIAL_PORT)
// Windows: stream handles.
#if !defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
# if !defined(ASIO_DISABLE_WINDOWS_STREAM_HANDLE)
# if defined(ASIO_HAS_IOCP)
# define ASIO_HAS_WINDOWS_STREAM_HANDLE 1
# endif // defined(ASIO_HAS_IOCP)
# endif // !defined(ASIO_DISABLE_WINDOWS_STREAM_HANDLE)
#endif // !defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
// Windows: random access handles.
#if !defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
# if !defined(ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
# if defined(ASIO_HAS_IOCP)
# define ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE 1
# endif // defined(ASIO_HAS_IOCP)
# endif // !defined(ASIO_DISABLE_WINDOWS_RANDOM_ACCESS_HANDLE)
#endif // !defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
// Windows: object handles.
#if !defined(ASIO_HAS_WINDOWS_OBJECT_HANDLE)
# if !defined(ASIO_DISABLE_WINDOWS_OBJECT_HANDLE)
# if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if !defined(UNDER_CE) && !defined(ASIO_WINDOWS_APP)
# define ASIO_HAS_WINDOWS_OBJECT_HANDLE 1
# endif // !defined(UNDER_CE) && !defined(ASIO_WINDOWS_APP)
# endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# endif // !defined(ASIO_DISABLE_WINDOWS_OBJECT_HANDLE)
#endif // !defined(ASIO_HAS_WINDOWS_OBJECT_HANDLE)
// Windows: OVERLAPPED wrapper.
#if !defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
# if !defined(ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR)
# if defined(ASIO_HAS_IOCP)
# define ASIO_HAS_WINDOWS_OVERLAPPED_PTR 1
# endif // defined(ASIO_HAS_IOCP)
# endif // !defined(ASIO_DISABLE_WINDOWS_OVERLAPPED_PTR)
#endif // !defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
// POSIX: stream-oriented file descriptors.
#if !defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
# if !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
# if !defined(ASIO_WINDOWS) \
&& !defined(ASIO_WINDOWS_RUNTIME) \
&& !defined(__CYGWIN__)
# define ASIO_HAS_POSIX_STREAM_DESCRIPTOR 1
# endif // !defined(ASIO_WINDOWS)
// && !defined(ASIO_WINDOWS_RUNTIME)
// && !defined(__CYGWIN__)
# endif // !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
#endif // !defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
// UNIX domain sockets.
#if !defined(ASIO_HAS_LOCAL_SOCKETS)
# if !defined(ASIO_DISABLE_LOCAL_SOCKETS)
# if !defined(ASIO_WINDOWS_RUNTIME)
# define ASIO_HAS_LOCAL_SOCKETS 1
# endif // !defined(ASIO_WINDOWS_RUNTIME)
# endif // !defined(ASIO_DISABLE_LOCAL_SOCKETS)
#endif // !defined(ASIO_HAS_LOCAL_SOCKETS)
// Files.
#if !defined(ASIO_HAS_FILE)
# if !defined(ASIO_DISABLE_FILE)
# if defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
# define ASIO_HAS_FILE 1
# elif defined(ASIO_HAS_IO_URING)
# define ASIO_HAS_FILE 1
# endif // defined(ASIO_HAS_IO_URING)
# endif // !defined(ASIO_DISABLE_FILE)
#endif // !defined(ASIO_HAS_FILE)
// Pipes.
#if !defined(ASIO_HAS_PIPE)
# if defined(ASIO_HAS_IOCP) \
|| !defined(ASIO_WINDOWS) \
&& !defined(ASIO_WINDOWS_RUNTIME) \
&& !defined(__CYGWIN__)
# if !defined(__SYMBIAN32__)
# if !defined(ASIO_DISABLE_PIPE)
# define ASIO_HAS_PIPE 1
# endif // !defined(ASIO_DISABLE_PIPE)
# endif // !defined(__SYMBIAN32__)
# endif // defined(ASIO_HAS_IOCP)
// || !defined(ASIO_WINDOWS)
// && !defined(ASIO_WINDOWS_RUNTIME)
// && !defined(__CYGWIN__)
#endif // !defined(ASIO_HAS_PIPE)
// Can use sigaction() instead of signal().
#if !defined(ASIO_HAS_SIGACTION)
# if !defined(ASIO_DISABLE_SIGACTION)
# if !defined(ASIO_WINDOWS) \
&& !defined(ASIO_WINDOWS_RUNTIME) \
&& !defined(__CYGWIN__)
# define ASIO_HAS_SIGACTION 1
# endif // !defined(ASIO_WINDOWS)
// && !defined(ASIO_WINDOWS_RUNTIME)
// && !defined(__CYGWIN__)
# endif // !defined(ASIO_DISABLE_SIGACTION)
#endif // !defined(ASIO_HAS_SIGACTION)
// Can use signal().
#if !defined(ASIO_HAS_SIGNAL)
# if !defined(ASIO_DISABLE_SIGNAL)
# if !defined(UNDER_CE)
# define ASIO_HAS_SIGNAL 1
# endif // !defined(UNDER_CE)
# endif // !defined(ASIO_DISABLE_SIGNAL)
#endif // !defined(ASIO_HAS_SIGNAL)
// Can use getaddrinfo() and getnameinfo().
#if !defined(ASIO_HAS_GETADDRINFO)
# if !defined(ASIO_DISABLE_GETADDRINFO)
# if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0501)
# define ASIO_HAS_GETADDRINFO 1
# elif defined(UNDER_CE)
# define ASIO_HAS_GETADDRINFO 1
# endif // defined(UNDER_CE)
# elif defined(__MACH__) && defined(__APPLE__)
# if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
# if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
# define ASIO_HAS_GETADDRINFO 1
# endif // (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
# else // defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
# define ASIO_HAS_GETADDRINFO 1
# endif // defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
# else // defined(__MACH__) && defined(__APPLE__)
# define ASIO_HAS_GETADDRINFO 1
# endif // defined(__MACH__) && defined(__APPLE__)
# endif // !defined(ASIO_DISABLE_GETADDRINFO)
#endif // !defined(ASIO_HAS_GETADDRINFO)
// Whether standard iostreams are disabled.
#if !defined(ASIO_NO_IOSTREAM)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_IOSTREAM)
# define ASIO_NO_IOSTREAM 1
# endif // !defined(BOOST_NO_IOSTREAM)
#endif // !defined(ASIO_NO_IOSTREAM)
// Whether exception handling is disabled.
#if !defined(ASIO_NO_EXCEPTIONS)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_EXCEPTIONS)
# define ASIO_NO_EXCEPTIONS 1
# endif // !defined(BOOST_NO_EXCEPTIONS)
#endif // !defined(ASIO_NO_EXCEPTIONS)
// Whether the typeid operator is supported.
#if !defined(ASIO_NO_TYPEID)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_NO_TYPEID)
# define ASIO_NO_TYPEID 1
# endif // !defined(BOOST_NO_TYPEID)
#endif // !defined(ASIO_NO_TYPEID)
// Threads.
#if !defined(ASIO_HAS_THREADS)
# if !defined(ASIO_DISABLE_THREADS)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_THREADS)
# define ASIO_HAS_THREADS 1
# elif defined(__GNUC__) && !defined(__MINGW32__) \
&& !defined(linux) && !defined(__linux) && !defined(__linux__)
# define ASIO_HAS_THREADS 1
# elif defined(_MT) || defined(__MT__)
# define ASIO_HAS_THREADS 1
# elif defined(_REENTRANT)
# define ASIO_HAS_THREADS 1
# elif defined(__APPLE__)
# define ASIO_HAS_THREADS 1
# elif defined(__HAIKU__)
# define ASIO_HAS_THREADS 1
# elif defined(_POSIX_THREADS) && (_POSIX_THREADS + 0 >= 0)
# define ASIO_HAS_THREADS 1
# elif defined(_PTHREADS)
# define ASIO_HAS_THREADS 1
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_THREADS)
# endif // !defined(ASIO_DISABLE_THREADS)
#endif // !defined(ASIO_HAS_THREADS)
// POSIX threads.
#if !defined(ASIO_HAS_PTHREADS)
# if defined(ASIO_HAS_THREADS)
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS)
# define ASIO_HAS_PTHREADS 1
# elif defined(_POSIX_THREADS) && (_POSIX_THREADS + 0 >= 0)
# define ASIO_HAS_PTHREADS 1
# elif defined(__HAIKU__)
# define ASIO_HAS_PTHREADS 1
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_HAS_PTHREADS)
# endif // defined(ASIO_HAS_THREADS)
#endif // !defined(ASIO_HAS_PTHREADS)
// Helper to prevent macro expansion.
#define ASIO_PREVENT_MACRO_SUBSTITUTION
// Helper to define in-class constants.
#if !defined(ASIO_STATIC_CONSTANT)
# if !defined(ASIO_DISABLE_BOOST_STATIC_CONSTANT)
# define ASIO_STATIC_CONSTANT(type, assignment) \
BOOST_STATIC_CONSTANT(type, assignment)
# else // !defined(ASIO_DISABLE_BOOST_STATIC_CONSTANT)
# define ASIO_STATIC_CONSTANT(type, assignment) \
static const type assignment
# endif // !defined(ASIO_DISABLE_BOOST_STATIC_CONSTANT)
#endif // !defined(ASIO_STATIC_CONSTANT)
// Boost align library.
#if !defined(ASIO_HAS_BOOST_ALIGN)
# if !defined(ASIO_DISABLE_BOOST_ALIGN)
# if defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 105600)
# define ASIO_HAS_BOOST_ALIGN 1
# endif // defined(ASIO_HAS_BOOST_CONFIG) && (BOOST_VERSION >= 105600)
# endif // !defined(ASIO_DISABLE_BOOST_ALIGN)
#endif // !defined(ASIO_HAS_BOOST_ALIGN)
// Boost array library.
#if !defined(ASIO_HAS_BOOST_ARRAY)
# if !defined(ASIO_DISABLE_BOOST_ARRAY)
# define ASIO_HAS_BOOST_ARRAY 1
# endif // !defined(ASIO_DISABLE_BOOST_ARRAY)
#endif // !defined(ASIO_HAS_BOOST_ARRAY)
// Boost assert macro.
#if !defined(ASIO_HAS_BOOST_ASSERT)
# if !defined(ASIO_DISABLE_BOOST_ASSERT)
# define ASIO_HAS_BOOST_ASSERT 1
# endif // !defined(ASIO_DISABLE_BOOST_ASSERT)
#endif // !defined(ASIO_HAS_BOOST_ASSERT)
// Boost limits header.
#if !defined(ASIO_HAS_BOOST_LIMITS)
# if !defined(ASIO_DISABLE_BOOST_LIMITS)
# define ASIO_HAS_BOOST_LIMITS 1
# endif // !defined(ASIO_DISABLE_BOOST_LIMITS)
#endif // !defined(ASIO_HAS_BOOST_LIMITS)
// Boost throw_exception function.
#if !defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
# if !defined(ASIO_DISABLE_BOOST_THROW_EXCEPTION)
# define ASIO_HAS_BOOST_THROW_EXCEPTION 1
# endif // !defined(ASIO_DISABLE_BOOST_THROW_EXCEPTION)
#endif // !defined(ASIO_HAS_BOOST_THROW_EXCEPTION)
// Boost regex library.
#if !defined(ASIO_HAS_BOOST_REGEX)
# if !defined(ASIO_DISABLE_BOOST_REGEX)
# define ASIO_HAS_BOOST_REGEX 1
# endif // !defined(ASIO_DISABLE_BOOST_REGEX)
#endif // !defined(ASIO_HAS_BOOST_REGEX)
// Boost bind function.
#if !defined(ASIO_HAS_BOOST_BIND)
# if !defined(ASIO_DISABLE_BOOST_BIND)
# define ASIO_HAS_BOOST_BIND 1
# endif // !defined(ASIO_DISABLE_BOOST_BIND)
#endif // !defined(ASIO_HAS_BOOST_BIND)
// Boost's BOOST_WORKAROUND macro.
#if !defined(ASIO_HAS_BOOST_WORKAROUND)
# if !defined(ASIO_DISABLE_BOOST_WORKAROUND)
# define ASIO_HAS_BOOST_WORKAROUND 1
# endif // !defined(ASIO_DISABLE_BOOST_WORKAROUND)
#endif // !defined(ASIO_HAS_BOOST_WORKAROUND)
// Microsoft Visual C++'s secure C runtime library.
#if !defined(ASIO_HAS_SECURE_RTL)
# if !defined(ASIO_DISABLE_SECURE_RTL)
# if defined(ASIO_MSVC) \
&& (ASIO_MSVC >= 1400) \
&& !defined(UNDER_CE)
# define ASIO_HAS_SECURE_RTL 1
# endif // defined(ASIO_MSVC)
// && (ASIO_MSVC >= 1400)
// && !defined(UNDER_CE)
# endif // !defined(ASIO_DISABLE_SECURE_RTL)
#endif // !defined(ASIO_HAS_SECURE_RTL)
// Handler hooking. Disabled for ancient Borland C++ and gcc compilers.
#if !defined(ASIO_HAS_HANDLER_HOOKS)
# if !defined(ASIO_DISABLE_HANDLER_HOOKS)
# if defined(__GNUC__)
# if (__GNUC__ >= 3)
# define ASIO_HAS_HANDLER_HOOKS 1
# endif // (__GNUC__ >= 3)
# elif !defined(__BORLANDC__) || defined(__clang__)
# define ASIO_HAS_HANDLER_HOOKS 1
# endif // !defined(__BORLANDC__) || defined(__clang__)
# endif // !defined(ASIO_DISABLE_HANDLER_HOOKS)
#endif // !defined(ASIO_HAS_HANDLER_HOOKS)
// Support for the __thread keyword extension, or equivalent.
#if !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
# if defined(__linux__)
# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
# if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
# if !defined(__INTEL_COMPILER) && !defined(__ICL) \
&& !(defined(__clang__) && defined(__ANDROID__))
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
# define ASIO_THREAD_KEYWORD __thread
# elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100)
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
# endif // defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100)
// && !(defined(__clang__) && defined(__ANDROID__))
# endif // ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
# endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
# endif // defined(__linux__)
# if defined(ASIO_MSVC) && defined(ASIO_WINDOWS_RUNTIME)
# if (_MSC_VER >= 1700)
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
# define ASIO_THREAD_KEYWORD __declspec(thread)
# endif // (_MSC_VER >= 1700)
# endif // defined(ASIO_MSVC) && defined(ASIO_WINDOWS_RUNTIME)
# if defined(__APPLE__)
# if defined(__clang__)
# if defined(__apple_build_version__)
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
# define ASIO_THREAD_KEYWORD __thread
# endif // defined(__apple_build_version__)
# endif // defined(__clang__)
# endif // defined(__APPLE__)
# if !defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
# if defined(ASIO_HAS_BOOST_CONFIG)
# if !defined(BOOST_NO_CXX11_THREAD_LOCAL)
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
# define ASIO_THREAD_KEYWORD thread_local
# endif // !defined(BOOST_NO_CXX11_THREAD_LOCAL)
# endif // defined(ASIO_HAS_BOOST_CONFIG)
# endif // !defined(ASIO_HAS_THREAD_KEYWORD_EXTENSION)
#endif // !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
#if !defined(ASIO_THREAD_KEYWORD)
# define ASIO_THREAD_KEYWORD __thread
#endif // !defined(ASIO_THREAD_KEYWORD)
// Support for POSIX ssize_t typedef.
#if !defined(ASIO_DISABLE_SSIZE_T)
# if defined(__linux__) \
|| (defined(__MACH__) && defined(__APPLE__))
# define ASIO_HAS_SSIZE_T 1
# endif // defined(__linux__)
// || (defined(__MACH__) && defined(__APPLE__))
#endif // !defined(ASIO_DISABLE_SSIZE_T)
// Helper macros to manage transition away from error_code return values.
#if defined(ASIO_NO_DEPRECATED)
# define ASIO_SYNC_OP_VOID void
# define ASIO_SYNC_OP_VOID_RETURN(e) return
#else // defined(ASIO_NO_DEPRECATED)
# define ASIO_SYNC_OP_VOID asio::error_code
# define ASIO_SYNC_OP_VOID_RETURN(e) return e
#endif // defined(ASIO_NO_DEPRECATED)
// Newer gcc, clang need special treatment to suppress unused typedef warnings.
#if defined(__clang__)
# if defined(__apple_build_version__)
# if (__clang_major__ >= 7)
# define ASIO_UNUSED_TYPEDEF __attribute__((__unused__))
# endif // (__clang_major__ >= 7)
# elif ((__clang_major__ == 3) && (__clang_minor__ >= 6)) \
|| (__clang_major__ > 3)
# define ASIO_UNUSED_TYPEDEF __attribute__((__unused__))
# endif // ((__clang_major__ == 3) && (__clang_minor__ >= 6))
// || (__clang_major__ > 3)
#elif defined(__GNUC__)
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4)
# define ASIO_UNUSED_TYPEDEF __attribute__((__unused__))
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4)
#endif // defined(__GNUC__)
#if !defined(ASIO_UNUSED_TYPEDEF)
# define ASIO_UNUSED_TYPEDEF
#endif // !defined(ASIO_UNUSED_TYPEDEF)
// Some versions of gcc generate spurious warnings about unused variables.
#if defined(__GNUC__)
# if (__GNUC__ >= 4)
# define ASIO_UNUSED_VARIABLE __attribute__((__unused__))
# endif // (__GNUC__ >= 4)
#endif // defined(__GNUC__)
#if !defined(ASIO_UNUSED_VARIABLE)
# define ASIO_UNUSED_VARIABLE
#endif // !defined(ASIO_UNUSED_VARIABLE)
// Helper macro to tell the optimiser what may be assumed to be true.
#if defined(ASIO_MSVC)
# define ASIO_ASSUME(expr) __assume(expr)
#elif defined(__clang__)
# if __has_builtin(__builtin_assume)
# define ASIO_ASSUME(expr) __builtin_assume(expr)
# endif // __has_builtin(__builtin_assume)
#elif defined(__GNUC__)
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
# define ASIO_ASSUME(expr) if (expr) {} else { __builtin_unreachable(); }
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4)
#endif // defined(__GNUC__)
#if !defined(ASIO_ASSUME)
# define ASIO_ASSUME(expr) (void)0
#endif // !defined(ASIO_ASSUME)
// Support the co_await keyword on compilers known to allow it.
#if !defined(ASIO_HAS_CO_AWAIT)
# if !defined(ASIO_DISABLE_CO_AWAIT)
# if (__cplusplus >= 202002) \
&& (__cpp_impl_coroutine >= 201902) && (__cpp_lib_coroutine >= 201902)
# define ASIO_HAS_CO_AWAIT 1
# elif defined(ASIO_MSVC)
# if (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705) && !defined(__clang__)
# define ASIO_HAS_CO_AWAIT 1
# elif (_MSC_FULL_VER >= 190023506)
# if defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
# define ASIO_HAS_CO_AWAIT 1
# endif // defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
# endif // (_MSC_FULL_VER >= 190023506)
# elif defined(__clang__)
# if (__clang_major__ >= 14)
# if (__cplusplus >= 202002) && (__cpp_impl_coroutine >= 201902)
# if __has_include(<coroutine>)
# define ASIO_HAS_CO_AWAIT 1
# endif // __has_include(<coroutine>)
# elif (__cplusplus >= 201703) && (__cpp_coroutines >= 201703)
# if __has_include(<experimental/coroutine>)
# define ASIO_HAS_CO_AWAIT 1
# endif // __has_include(<experimental/coroutine>)
# endif // (__cplusplus >= 201703) && (__cpp_coroutines >= 201703)
# else // (__clang_major__ >= 14)
# if (__cplusplus >= 201703) && (__cpp_coroutines >= 201703)
# if __has_include(<experimental/coroutine>)
# define ASIO_HAS_CO_AWAIT 1
# endif // __has_include(<experimental/coroutine>)
# endif // (__cplusplus >= 201703) && (__cpp_coroutines >= 201703)
# endif // (__clang_major__ >= 14)
# elif defined(__GNUC__)
# if (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)
# if __has_include(<coroutine>)
# define ASIO_HAS_CO_AWAIT 1
# endif // __has_include(<coroutine>)
# endif // (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)
# endif // defined(__GNUC__)
# endif // !defined(ASIO_DISABLE_CO_AWAIT)
#endif // !defined(ASIO_HAS_CO_AWAIT)
// Standard library support for coroutines.
#if !defined(ASIO_HAS_STD_COROUTINE)
# if !defined(ASIO_DISABLE_STD_COROUTINE)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705)
# define ASIO_HAS_STD_COROUTINE 1
# endif // (_MSC_VER >= 1928) && (_MSVC_LANG >= 201705)
# elif defined(__clang__)
# if (__clang_major__ >= 14)
# if (__cplusplus >= 202002) && (__cpp_impl_coroutine >= 201902)
# if __has_include(<coroutine>)
# define ASIO_HAS_STD_COROUTINE 1
# endif // __has_include(<coroutine>)
# endif // (__cplusplus >= 202002) && (__cpp_impl_coroutine >= 201902)
# endif // (__clang_major__ >= 14)
# elif defined(__GNUC__)
# if (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)
# if __has_include(<coroutine>)
# define ASIO_HAS_STD_COROUTINE 1
# endif // __has_include(<coroutine>)
# endif // (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)
# endif // defined(__GNUC__)
# endif // !defined(ASIO_DISABLE_STD_COROUTINE)
#endif // !defined(ASIO_HAS_STD_COROUTINE)
// Compiler support for the the [[nodiscard]] attribute.
#if !defined(ASIO_NODISCARD)
# if defined(__has_cpp_attribute)
# if __has_cpp_attribute(nodiscard)
# if (__cplusplus >= 201703)
# define ASIO_NODISCARD [[nodiscard]]
# endif // (__cplusplus >= 201703)
# endif // __has_cpp_attribute(nodiscard)
# endif // defined(__has_cpp_attribute)
#endif // !defined(ASIO_NODISCARD)
#if !defined(ASIO_NODISCARD)
# define ASIO_NODISCARD
#endif // !defined(ASIO_NODISCARD)
// Kernel support for MSG_NOSIGNAL.
#if !defined(ASIO_HAS_MSG_NOSIGNAL)
# if defined(__linux__)
# define ASIO_HAS_MSG_NOSIGNAL 1
# elif defined(_POSIX_VERSION)
# if (_POSIX_VERSION >= 200809L)
# define ASIO_HAS_MSG_NOSIGNAL 1
# endif // _POSIX_VERSION >= 200809L
# endif // defined(_POSIX_VERSION)
#endif // !defined(ASIO_HAS_MSG_NOSIGNAL)
// Standard library support for std::to_address.
#if !defined(ASIO_HAS_STD_TO_ADDRESS)
# if !defined(ASIO_DISABLE_STD_TO_ADDRESS)
# if defined(__clang__)
# if (__cplusplus >= 202002)
# define ASIO_HAS_STD_TO_ADDRESS 1
# endif // (__cplusplus >= 202002)
# elif defined(__GNUC__)
# if (__GNUC__ >= 8)
# if (__cplusplus >= 202002)
# define ASIO_HAS_STD_TO_ADDRESS 1
# endif // (__cplusplus >= 202002)
# endif // (__GNUC__ >= 8)
# endif // defined(__GNUC__)
# if defined(ASIO_MSVC)
# if (_MSC_VER >= 1922) && (_MSVC_LANG >= 202002)
# define ASIO_HAS_STD_TO_ADDRESS 1
# endif // (_MSC_VER >= 1922) && (_MSVC_LANG >= 202002)
# endif // defined(ASIO_MSVC)
# endif // !defined(ASIO_DISABLE_STD_TO_ADDRESS)
#endif // !defined(ASIO_HAS_STD_TO_ADDRESS)
// Standard library support for snprintf.
#if !defined(ASIO_HAS_SNPRINTF)
# if !defined(ASIO_DISABLE_SNPRINTF)
# if defined(__APPLE__)
# define ASIO_HAS_SNPRINTF 1
# endif // defined(__APPLE__)
# endif // !defined(ASIO_DISABLE_SNPRINTF)
#endif // !defined(ASIO_HAS_SNPRINTF)
#endif // ASIO_DETAIL_CONFIG_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_socket_service_base.hpp | //
// detail/win_iocp_socket_service_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_BASE_HPP
#define ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/associated_cancellation_slot.hpp"
#include "asio/error.hpp"
#include "asio/execution_context.hpp"
#include "asio/socket_base.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/select_reactor.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/win_iocp_io_context.hpp"
#include "asio/detail/win_iocp_null_buffers_op.hpp"
#include "asio/detail/win_iocp_socket_connect_op.hpp"
#include "asio/detail/win_iocp_socket_send_op.hpp"
#include "asio/detail/win_iocp_socket_recv_op.hpp"
#include "asio/detail/win_iocp_socket_recvmsg_op.hpp"
#include "asio/detail/win_iocp_wait_op.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class win_iocp_socket_service_base
{
public:
// The implementation type of the socket.
struct base_implementation_type
{
// The native socket representation.
socket_type socket_;
// The current state of the socket.
socket_ops::state_type state_;
// We use a shared pointer as a cancellation token here to work around the
// broken Windows support for cancellation. MSDN says that when you call
// closesocket any outstanding WSARecv or WSASend operations will complete
// with the error ERROR_OPERATION_ABORTED. In practice they complete with
// ERROR_NETNAME_DELETED, which means you can't tell the difference between
// a local cancellation and the socket being hard-closed by the peer.
socket_ops::shared_cancel_token_type cancel_token_;
// Per-descriptor data used by the reactor.
select_reactor::per_descriptor_data reactor_data_;
#if defined(ASIO_ENABLE_CANCELIO)
// The ID of the thread from which it is safe to cancel asynchronous
// operations. 0 means no asynchronous operations have been started yet.
// ~0 means asynchronous operations have been started from more than one
// thread, and cancellation is not supported for the socket.
DWORD safe_cancellation_thread_id_;
#endif // defined(ASIO_ENABLE_CANCELIO)
// Pointers to adjacent socket implementations in linked list.
base_implementation_type* next_;
base_implementation_type* prev_;
};
// Constructor.
ASIO_DECL win_iocp_socket_service_base(execution_context& context);
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void base_shutdown();
// Construct a new socket implementation.
ASIO_DECL void construct(base_implementation_type& impl);
// Move-construct a new socket implementation.
ASIO_DECL void base_move_construct(base_implementation_type& impl,
base_implementation_type& other_impl) noexcept;
// Move-assign from another socket implementation.
ASIO_DECL void base_move_assign(base_implementation_type& impl,
win_iocp_socket_service_base& other_service,
base_implementation_type& other_impl);
// Destroy a socket implementation.
ASIO_DECL void destroy(base_implementation_type& impl);
// Determine whether the socket is open.
bool is_open(const base_implementation_type& impl) const
{
return impl.socket_ != invalid_socket;
}
// Destroy a socket implementation.
ASIO_DECL asio::error_code close(
base_implementation_type& impl, asio::error_code& ec);
// Release ownership of the socket.
ASIO_DECL socket_type release(
base_implementation_type& impl, asio::error_code& ec);
// Cancel all operations associated with the socket.
ASIO_DECL asio::error_code cancel(
base_implementation_type& impl, asio::error_code& ec);
// Determine whether the socket is at the out-of-band data mark.
bool at_mark(const base_implementation_type& impl,
asio::error_code& ec) const
{
return socket_ops::sockatmark(impl.socket_, ec);
}
// Determine the number of bytes available for reading.
std::size_t available(const base_implementation_type& impl,
asio::error_code& ec) const
{
return socket_ops::available(impl.socket_, ec);
}
// Place the socket into the state where it will listen for new connections.
asio::error_code listen(base_implementation_type& impl,
int backlog, asio::error_code& ec)
{
socket_ops::listen(impl.socket_, backlog, ec);
return ec;
}
// Perform an IO control command on the socket.
template <typename IO_Control_Command>
asio::error_code io_control(base_implementation_type& impl,
IO_Control_Command& command, asio::error_code& ec)
{
socket_ops::ioctl(impl.socket_, impl.state_, command.name(),
static_cast<ioctl_arg_type*>(command.data()), ec);
return ec;
}
// Gets the non-blocking mode of the socket.
bool non_blocking(const base_implementation_type& impl) const
{
return (impl.state_ & socket_ops::user_set_non_blocking) != 0;
}
// Sets the non-blocking mode of the socket.
asio::error_code non_blocking(base_implementation_type& impl,
bool mode, asio::error_code& ec)
{
socket_ops::set_user_non_blocking(impl.socket_, impl.state_, mode, ec);
return ec;
}
// Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking(const base_implementation_type& impl) const
{
return (impl.state_ & socket_ops::internal_non_blocking) != 0;
}
// Sets the non-blocking mode of the native socket implementation.
asio::error_code native_non_blocking(base_implementation_type& impl,
bool mode, asio::error_code& ec)
{
socket_ops::set_internal_non_blocking(impl.socket_, impl.state_, mode, ec);
return ec;
}
// Wait for the socket to become ready to read, ready to write, or to have
// pending error conditions.
asio::error_code wait(base_implementation_type& impl,
socket_base::wait_type w, asio::error_code& ec)
{
switch (w)
{
case socket_base::wait_read:
socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
break;
case socket_base::wait_write:
socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
break;
case socket_base::wait_error:
socket_ops::poll_error(impl.socket_, impl.state_, -1, ec);
break;
default:
ec = asio::error::invalid_argument;
break;
}
return ec;
}
// Asynchronously wait for the socket to become ready to read, ready to
// write, or to have pending error conditions.
template <typename Handler, typename IoExecutor>
void async_wait(base_implementation_type& impl,
socket_base::wait_type w, Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_wait_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(impl.cancel_token_, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_wait"));
// Optionally register for per-operation cancellation.
operation* iocp_op = p.p;
if (slot.is_connected())
{
p.p->cancellation_key_ = iocp_op =
&slot.template emplace<reactor_op_cancellation>(
impl.socket_, iocp_op);
}
int op_type = -1;
switch (w)
{
case socket_base::wait_read:
op_type = start_null_buffers_receive_op(impl, 0, p.p, iocp_op);
break;
case socket_base::wait_write:
op_type = select_reactor::write_op;
start_reactor_op(impl, select_reactor::write_op, p.p);
break;
case socket_base::wait_error:
op_type = select_reactor::read_op;
start_reactor_op(impl, select_reactor::except_op, p.p);
break;
default:
p.p->ec_ = asio::error::invalid_argument;
iocp_service_.post_immediate_completion(p.p, is_continuation);
break;
}
p.v = p.p = 0;
// Update cancellation method if the reactor was used.
if (slot.is_connected() && op_type != -1)
{
static_cast<reactor_op_cancellation*>(iocp_op)->use_reactor(
&get_reactor(), &impl.reactor_data_, op_type);
}
}
// Send the given data to the peer. Returns the number of bytes sent.
template <typename ConstBufferSequence>
size_t send(base_implementation_type& impl,
const ConstBufferSequence& buffers,
socket_base::message_flags flags, asio::error_code& ec)
{
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs(buffers);
return socket_ops::sync_send(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
}
// Wait until data can be sent without blocking.
size_t send(base_implementation_type& impl, const null_buffers&,
socket_base::message_flags, asio::error_code& ec)
{
// Wait for socket to become ready.
socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
return 0;
}
// Start an asynchronous send. The data being sent must be valid for the
// lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_send(base_implementation_type& impl,
const ConstBufferSequence& buffers, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_socket_send_op<
ConstBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(
impl.cancel_token_, buffers, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_send"));
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs(buffers);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.socket_, o);
start_send_op(impl, bufs.buffers(), bufs.count(), flags,
(impl.state_ & socket_ops::stream_oriented) != 0 && bufs.all_empty(),
o);
p.v = p.p = 0;
}
// Start an asynchronous wait until data can be sent without blocking.
template <typename Handler, typename IoExecutor>
void async_send(base_implementation_type& impl, const null_buffers&,
socket_base::message_flags, Handler& handler, const IoExecutor& io_ex)
{
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(impl.cancel_token_, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_send(null_buffers)"));
start_reactor_op(impl, select_reactor::write_op, p.p);
p.v = p.p = 0;
}
// Receive some data from the peer. Returns the number of bytes received.
template <typename MutableBufferSequence>
size_t receive(base_implementation_type& impl,
const MutableBufferSequence& buffers,
socket_base::message_flags flags, asio::error_code& ec)
{
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(buffers);
return socket_ops::sync_recv(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
}
// Wait until data can be received without blocking.
size_t receive(base_implementation_type& impl, const null_buffers&,
socket_base::message_flags, asio::error_code& ec)
{
// Wait for socket to become ready.
socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
return 0;
}
// Start an asynchronous receive. The buffer for the data being received
// must be valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_receive(base_implementation_type& impl,
const MutableBufferSequence& buffers, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_socket_recv_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(impl.state_,
impl.cancel_token_, buffers, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_receive"));
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(buffers);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.socket_, o);
start_receive_op(impl, bufs.buffers(), bufs.count(), flags,
(impl.state_ & socket_ops::stream_oriented) != 0 && bufs.all_empty(),
o);
p.v = p.p = 0;
}
// Wait until data can be received without blocking.
template <typename Handler, typename IoExecutor>
void async_receive(base_implementation_type& impl,
const null_buffers&, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(impl.cancel_token_, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_receive(null_buffers)"));
// Optionally register for per-operation cancellation.
operation* iocp_op = p.p;
if (slot.is_connected())
{
p.p->cancellation_key_ = iocp_op =
&slot.template emplace<reactor_op_cancellation>(
impl.socket_, iocp_op);
}
int op_type = start_null_buffers_receive_op(impl, flags, p.p, iocp_op);
p.v = p.p = 0;
// Update cancellation method if the reactor was used.
if (slot.is_connected() && op_type != -1)
{
static_cast<reactor_op_cancellation*>(iocp_op)->use_reactor(
&get_reactor(), &impl.reactor_data_, op_type);
}
}
// Receive some data with associated flags. Returns the number of bytes
// received.
template <typename MutableBufferSequence>
size_t receive_with_flags(base_implementation_type& impl,
const MutableBufferSequence& buffers,
socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, asio::error_code& ec)
{
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(buffers);
return socket_ops::sync_recvmsg(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), in_flags, out_flags, ec);
}
// Wait until data can be received without blocking.
size_t receive_with_flags(base_implementation_type& impl,
const null_buffers&, socket_base::message_flags,
socket_base::message_flags& out_flags, asio::error_code& ec)
{
// Wait for socket to become ready.
socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
// Clear out_flags, since we cannot give it any other sensible value when
// performing a null_buffers operation.
out_flags = 0;
return 0;
}
// Start an asynchronous receive. The buffer for the data being received
// must be valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_receive_with_flags(base_implementation_type& impl,
const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, Handler& handler,
const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_socket_recvmsg_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(impl.cancel_token_,
buffers, out_flags, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_receive_with_flags"));
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(buffers);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.socket_, o);
start_receive_op(impl, bufs.buffers(), bufs.count(), in_flags, false, o);
p.v = p.p = 0;
}
// Wait until data can be received without blocking.
template <typename Handler, typename IoExecutor>
void async_receive_with_flags(base_implementation_type& impl,
const null_buffers&, socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, Handler& handler,
const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(impl.cancel_token_, handler, io_ex);
ASIO_HANDLER_CREATION((context_, *p.p, "socket",
&impl, impl.socket_, "async_receive_with_flags(null_buffers)"));
// Reset out_flags since it can be given no sensible value at this time.
out_flags = 0;
// Optionally register for per-operation cancellation.
operation* iocp_op = p.p;
if (slot.is_connected())
{
p.p->cancellation_key_ = iocp_op =
&slot.template emplace<reactor_op_cancellation>(
impl.socket_, iocp_op);
}
int op_type = start_null_buffers_receive_op(impl, in_flags, p.p, iocp_op);
p.v = p.p = 0;
// Update cancellation method if the reactor was used.
if (slot.is_connected() && op_type != -1)
{
static_cast<reactor_op_cancellation*>(iocp_op)->use_reactor(
&get_reactor(), &impl.reactor_data_, op_type);
}
}
// Helper function to restart an asynchronous accept operation.
ASIO_DECL void restart_accept_op(socket_type s,
socket_holder& new_socket, int family, int type,
int protocol, void* output_buffer, DWORD address_length,
long* cancel_requested, operation* op);
protected:
// Open a new socket implementation.
ASIO_DECL asio::error_code do_open(
base_implementation_type& impl, int family, int type,
int protocol, asio::error_code& ec);
// Assign a native socket to a socket implementation.
ASIO_DECL asio::error_code do_assign(
base_implementation_type& impl, int type,
socket_type native_socket, asio::error_code& ec);
// Helper function to start an asynchronous send operation.
ASIO_DECL void start_send_op(base_implementation_type& impl,
WSABUF* buffers, std::size_t buffer_count,
socket_base::message_flags flags, bool noop, operation* op);
// Helper function to start an asynchronous send_to operation.
ASIO_DECL void start_send_to_op(base_implementation_type& impl,
WSABUF* buffers, std::size_t buffer_count, const void* addr,
int addrlen, socket_base::message_flags flags, operation* op);
// Helper function to start an asynchronous receive operation.
ASIO_DECL void start_receive_op(base_implementation_type& impl,
WSABUF* buffers, std::size_t buffer_count,
socket_base::message_flags flags, bool noop, operation* op);
// Helper function to start an asynchronous null_buffers receive operation.
ASIO_DECL int start_null_buffers_receive_op(
base_implementation_type& impl, socket_base::message_flags flags,
reactor_op* op, operation* iocp_op);
// Helper function to start an asynchronous receive_from operation.
ASIO_DECL void start_receive_from_op(base_implementation_type& impl,
WSABUF* buffers, std::size_t buffer_count, void* addr,
socket_base::message_flags flags, int* addrlen, operation* op);
// Helper function to start an asynchronous accept operation.
ASIO_DECL void start_accept_op(base_implementation_type& impl,
bool peer_is_open, socket_holder& new_socket, int family, int type,
int protocol, void* output_buffer, DWORD address_length, operation* op);
// Start an asynchronous read or write operation using the reactor.
ASIO_DECL void start_reactor_op(base_implementation_type& impl,
int op_type, reactor_op* op);
// Start the asynchronous connect operation using the reactor.
ASIO_DECL int start_connect_op(base_implementation_type& impl,
int family, int type, const void* remote_addr, std::size_t remote_addrlen,
win_iocp_socket_connect_op_base* op, operation* iocp_op);
// Helper function to close a socket when the associated object is being
// destroyed.
ASIO_DECL void close_for_destruction(base_implementation_type& impl);
// Update the ID of the thread from which cancellation is safe.
ASIO_DECL void update_cancellation_thread_id(
base_implementation_type& impl);
// Helper function to get the reactor. If no reactor has been created yet, a
// new one is obtained from the execution context and a pointer to it is
// cached in this service.
ASIO_DECL select_reactor& get_reactor();
// The type of a ConnectEx function pointer, as old SDKs may not provide it.
typedef BOOL (PASCAL *connect_ex_fn)(SOCKET,
const socket_addr_type*, int, void*, DWORD, DWORD*, OVERLAPPED*);
// Helper function to get the ConnectEx pointer. If no ConnectEx pointer has
// been obtained yet, one is obtained using WSAIoctl and the pointer is
// cached. Returns a null pointer if ConnectEx is not available.
ASIO_DECL connect_ex_fn get_connect_ex(
base_implementation_type& impl, int type);
// The type of a NtSetInformationFile function pointer.
typedef LONG (NTAPI *nt_set_info_fn)(HANDLE, ULONG_PTR*, void*, ULONG, ULONG);
// Helper function to get the NtSetInformationFile function pointer. If no
// NtSetInformationFile pointer has been obtained yet, one is obtained using
// GetProcAddress and the pointer is cached. Returns a null pointer if
// NtSetInformationFile is not available.
ASIO_DECL nt_set_info_fn get_nt_set_info();
// Helper function to emulate InterlockedCompareExchangePointer functionality
// for:
// - very old Platform SDKs; and
// - platform SDKs where MSVC's /Wp64 option causes spurious warnings.
ASIO_DECL void* interlocked_compare_exchange_pointer(
void** dest, void* exch, void* cmp);
// Helper function to emulate InterlockedExchangePointer functionality for:
// - very old Platform SDKs; and
// - platform SDKs where MSVC's /Wp64 option causes spurious warnings.
ASIO_DECL void* interlocked_exchange_pointer(void** dest, void* val);
// Helper class used to implement per operation cancellation.
class iocp_op_cancellation : public operation
{
public:
iocp_op_cancellation(SOCKET s, operation* target)
: operation(&iocp_op_cancellation::do_complete),
socket_(s),
target_(target)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
iocp_op_cancellation* o = static_cast<iocp_op_cancellation*>(base);
o->target_->complete(owner, result_ec, bytes_transferred);
}
void operator()(cancellation_type_t type)
{
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
HANDLE sock_as_handle = reinterpret_cast<HANDLE>(socket_);
::CancelIoEx(sock_as_handle, this);
}
#else // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
(void)type;
#endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
}
private:
SOCKET socket_;
operation* target_;
};
// Helper class used to implement per operation cancellation.
class accept_op_cancellation : public operation
{
public:
accept_op_cancellation(SOCKET s, operation* target)
: operation(&iocp_op_cancellation::do_complete),
socket_(s),
target_(target),
cancel_requested_(0)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
accept_op_cancellation* o = static_cast<accept_op_cancellation*>(base);
o->target_->complete(owner, result_ec, bytes_transferred);
}
long* get_cancel_requested()
{
return &cancel_requested_;
}
void operator()(cancellation_type_t type)
{
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
HANDLE sock_as_handle = reinterpret_cast<HANDLE>(socket_);
::CancelIoEx(sock_as_handle, this);
}
#else // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
(void)type;
#endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
}
private:
SOCKET socket_;
operation* target_;
long cancel_requested_;
};
// Helper class used to implement per operation cancellation.
class reactor_op_cancellation : public operation
{
public:
reactor_op_cancellation(SOCKET s, operation* base)
: operation(&reactor_op_cancellation::do_complete),
socket_(s),
target_(base),
reactor_(0),
reactor_data_(0),
op_type_(-1)
{
}
void use_reactor(select_reactor* r,
select_reactor::per_descriptor_data* p, int o)
{
reactor_ = r;
reactor_data_ = p;
op_type_ = o;
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
reactor_op_cancellation* o = static_cast<reactor_op_cancellation*>(base);
o->target_->complete(owner, result_ec, bytes_transferred);
}
void operator()(cancellation_type_t type)
{
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
if (reactor_)
{
reactor_->cancel_ops_by_key(socket_,
*reactor_data_, op_type_, this);
}
else
{
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
HANDLE sock_as_handle = reinterpret_cast<HANDLE>(socket_);
::CancelIoEx(sock_as_handle, this);
#endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
}
}
}
private:
SOCKET socket_;
operation* target_;
select_reactor* reactor_;
select_reactor::per_descriptor_data* reactor_data_;
int op_type_;
};
// The execution context used to obtain the reactor, if required.
execution_context& context_;
// The IOCP service used for running asynchronous operations and dispatching
// handlers.
win_iocp_io_context& iocp_service_;
// The reactor used for performing connect operations. This object is created
// only if needed.
select_reactor* reactor_;
// Pointer to ConnectEx implementation.
void* connect_ex_;
// Pointer to NtSetInformationFile implementation.
void* nt_set_info_;
// Mutex to protect access to the linked list of implementations.
asio::detail::mutex mutex_;
// The head of a linked list of all implementations.
base_implementation_type* impl_list_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_iocp_socket_service_base.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_BASE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_recvfrom_op.hpp | //
// detail/io_uring_socket_recvfrom_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_RECVFROM_OP_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_RECVFROM_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename MutableBufferSequence, typename Endpoint>
class io_uring_socket_recvfrom_op_base : public io_uring_operation
{
public:
io_uring_socket_recvfrom_op_base(const asio::error_code& success_ec,
socket_type socket, socket_ops::state_type state,
const MutableBufferSequence& buffers, Endpoint& endpoint,
socket_base::message_flags flags, func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_socket_recvfrom_op_base::do_prepare,
&io_uring_socket_recvfrom_op_base::do_perform, complete_func),
socket_(socket),
state_(state),
buffers_(buffers),
sender_endpoint_(endpoint),
flags_(flags),
bufs_(buffers),
msghdr_()
{
msghdr_.msg_iov = bufs_.buffers();
msghdr_.msg_iovlen = static_cast<int>(bufs_.count());
msghdr_.msg_name = static_cast<sockaddr*>(
static_cast<void*>(sender_endpoint_.data()));
msghdr_.msg_namelen = sender_endpoint_.capacity();
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_socket_recvfrom_op_base* o(
static_cast<io_uring_socket_recvfrom_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0;
::io_uring_prep_poll_add(sqe, o->socket_, except_op ? POLLPRI : POLLIN);
}
else
{
::io_uring_prep_recvmsg(sqe, o->socket_, &o->msghdr_, o->flags_);
}
}
static bool do_perform(io_uring_operation* base, bool after_completion)
{
ASIO_ASSUME(base != 0);
io_uring_socket_recvfrom_op_base* o(
static_cast<io_uring_socket_recvfrom_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0;
if (after_completion || !except_op)
{
std::size_t addr_len = o->sender_endpoint_.capacity();
bool result;
if (o->bufs_.is_single_buffer)
{
result = socket_ops::non_blocking_recvfrom1(o->socket_,
o->bufs_.first(o->buffers_).data(),
o->bufs_.first(o->buffers_).size(), o->flags_,
o->sender_endpoint_.data(), &addr_len,
o->ec_, o->bytes_transferred_);
}
else
{
result = socket_ops::non_blocking_recvfrom(o->socket_,
o->bufs_.buffers(), o->bufs_.count(), o->flags_,
o->sender_endpoint_.data(), &addr_len,
o->ec_, o->bytes_transferred_);
}
if (result && !o->ec_)
o->sender_endpoint_.resize(addr_len);
}
}
else if (after_completion && !o->ec_)
o->sender_endpoint_.resize(o->msghdr_.msg_namelen);
if (o->ec_ && o->ec_ == asio::error::would_block)
{
o->state_ |= socket_ops::internal_non_blocking;
return false;
}
return after_completion;
}
private:
socket_type socket_;
socket_ops::state_type state_;
MutableBufferSequence buffers_;
Endpoint& sender_endpoint_;
socket_base::message_flags flags_;
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs_;
msghdr msghdr_;
};
template <typename MutableBufferSequence, typename Endpoint,
typename Handler, typename IoExecutor>
class io_uring_socket_recvfrom_op
: public io_uring_socket_recvfrom_op_base<MutableBufferSequence, Endpoint>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_recvfrom_op);
io_uring_socket_recvfrom_op(const asio::error_code& success_ec,
int socket, socket_ops::state_type state,
const MutableBufferSequence& buffers, Endpoint& endpoint,
socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
: io_uring_socket_recvfrom_op_base<MutableBufferSequence, Endpoint>(
success_ec, socket, state, buffers, endpoint, flags,
&io_uring_socket_recvfrom_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_recvfrom_op* o
(static_cast<io_uring_socket_recvfrom_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_RECVFROM_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/composed_work.hpp | //
// detail/composed_work.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_COMPOSED_WORK_HPP
#define ASIO_DETAIL_COMPOSED_WORK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/execution/executor.hpp"
#include "asio/execution/outstanding_work.hpp"
#include "asio/executor_work_guard.hpp"
#include "asio/is_executor.hpp"
#include "asio/system_executor.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Executor, typename = void>
class composed_work_guard
{
public:
typedef decay_t<
prefer_result_t<Executor, execution::outstanding_work_t::tracked_t>
> executor_type;
composed_work_guard(const Executor& ex)
: executor_(asio::prefer(ex, execution::outstanding_work.tracked))
{
}
void reset()
{
}
executor_type get_executor() const noexcept
{
return executor_;
}
private:
executor_type executor_;
};
template <>
struct composed_work_guard<system_executor>
{
public:
typedef system_executor executor_type;
composed_work_guard(const system_executor&)
{
}
void reset()
{
}
executor_type get_executor() const noexcept
{
return system_executor();
}
};
#if !defined(ASIO_NO_TS_EXECUTORS)
template <typename Executor>
struct composed_work_guard<Executor,
enable_if_t<
!execution::is_executor<Executor>::value
>
> : executor_work_guard<Executor>
{
composed_work_guard(const Executor& ex)
: executor_work_guard<Executor>(ex)
{
}
};
#endif // !defined(ASIO_NO_TS_EXECUTORS)
template <typename>
struct composed_io_executors;
template <>
struct composed_io_executors<void()>
{
composed_io_executors() noexcept
: head_(system_executor())
{
}
typedef system_executor head_type;
system_executor head_;
};
inline composed_io_executors<void()> make_composed_io_executors()
{
return composed_io_executors<void()>();
}
template <typename Head>
struct composed_io_executors<void(Head)>
{
explicit composed_io_executors(const Head& ex) noexcept
: head_(ex)
{
}
typedef Head head_type;
Head head_;
};
template <typename Head>
inline composed_io_executors<void(Head)>
make_composed_io_executors(const Head& head)
{
return composed_io_executors<void(Head)>(head);
}
template <typename Head, typename... Tail>
struct composed_io_executors<void(Head, Tail...)>
{
explicit composed_io_executors(const Head& head,
const Tail&... tail) noexcept
: head_(head),
tail_(tail...)
{
}
void reset()
{
head_.reset();
tail_.reset();
}
typedef Head head_type;
Head head_;
composed_io_executors<void(Tail...)> tail_;
};
template <typename Head, typename... Tail>
inline composed_io_executors<void(Head, Tail...)>
make_composed_io_executors(const Head& head, const Tail&... tail)
{
return composed_io_executors<void(Head, Tail...)>(head, tail...);
}
template <typename>
struct composed_work;
template <>
struct composed_work<void()>
{
typedef composed_io_executors<void()> executors_type;
composed_work(const executors_type&) noexcept
: head_(system_executor())
{
}
void reset()
{
head_.reset();
}
typedef system_executor head_type;
composed_work_guard<system_executor> head_;
};
template <typename Head>
struct composed_work<void(Head)>
{
typedef composed_io_executors<void(Head)> executors_type;
explicit composed_work(const executors_type& ex) noexcept
: head_(ex.head_)
{
}
void reset()
{
head_.reset();
}
typedef Head head_type;
composed_work_guard<Head> head_;
};
template <typename Head, typename... Tail>
struct composed_work<void(Head, Tail...)>
{
typedef composed_io_executors<void(Head, Tail...)> executors_type;
explicit composed_work(const executors_type& ex) noexcept
: head_(ex.head_),
tail_(ex.tail_)
{
}
void reset()
{
head_.reset();
tail_.reset();
}
typedef Head head_type;
composed_work_guard<Head> head_;
composed_work<void(Tail...)> tail_;
};
template <typename IoObject>
inline typename IoObject::executor_type
get_composed_io_executor(IoObject& io_object,
enable_if_t<
!is_executor<IoObject>::value
>* = 0,
enable_if_t<
!execution::is_executor<IoObject>::value
>* = 0)
{
return io_object.get_executor();
}
template <typename Executor>
inline const Executor& get_composed_io_executor(const Executor& ex,
enable_if_t<
is_executor<Executor>::value
|| execution::is_executor<Executor>::value
>* = 0)
{
return ex;
}
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_COMPOSED_WORK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_io_context.hpp | //
// detail/win_iocp_io_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_IO_CONTEXT_HPP
#define ASIO_DETAIL_WIN_IOCP_IO_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/limits.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/scoped_ptr.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/thread.hpp"
#include "asio/detail/thread_context.hpp"
#include "asio/detail/timer_queue_base.hpp"
#include "asio/detail/timer_queue_set.hpp"
#include "asio/detail/wait_op.hpp"
#include "asio/detail/win_iocp_operation.hpp"
#include "asio/detail/win_iocp_thread_info.hpp"
#include "asio/execution_context.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class wait_op;
class win_iocp_io_context
: public execution_context_service_base<win_iocp_io_context>,
public thread_context
{
public:
// Constructor. Specifies a concurrency hint that is passed through to the
// underlying I/O completion port.
ASIO_DECL win_iocp_io_context(asio::execution_context& ctx,
int concurrency_hint = -1, bool own_thread = true);
// Destructor.
ASIO_DECL ~win_iocp_io_context();
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Initialise the task. Nothing to do here.
void init_task()
{
}
// Register a handle with the IO completion port.
ASIO_DECL asio::error_code register_handle(
HANDLE handle, asio::error_code& ec);
// Run the event loop until stopped or no more work.
ASIO_DECL size_t run(asio::error_code& ec);
// Run until stopped or one operation is performed.
ASIO_DECL size_t run_one(asio::error_code& ec);
// Run until timeout, interrupted, or one operation is performed.
ASIO_DECL size_t wait_one(long usec, asio::error_code& ec);
// Poll for operations without blocking.
ASIO_DECL size_t poll(asio::error_code& ec);
// Poll for one operation without blocking.
ASIO_DECL size_t poll_one(asio::error_code& ec);
// Stop the event processing loop.
ASIO_DECL void stop();
// Determine whether the io_context is stopped.
bool stopped() const
{
return ::InterlockedExchangeAdd(&stopped_, 0) != 0;
}
// Restart in preparation for a subsequent run invocation.
void restart()
{
::InterlockedExchange(&stopped_, 0);
}
// Notify that some work has started.
void work_started()
{
::InterlockedIncrement(&outstanding_work_);
}
// Notify that some work has finished.
void work_finished()
{
if (::InterlockedDecrement(&outstanding_work_) == 0)
stop();
}
// Return whether a handler can be dispatched immediately.
ASIO_DECL bool can_dispatch();
/// Capture the current exception so it can be rethrown from a run function.
ASIO_DECL void capture_current_exception();
// Request invocation of the given operation and return immediately. Assumes
// that work_started() has not yet been called for the operation.
void post_immediate_completion(win_iocp_operation* op, bool)
{
work_started();
post_deferred_completion(op);
}
// Request invocation of the given operation and return immediately. Assumes
// that work_started() was previously called for the operation.
ASIO_DECL void post_deferred_completion(win_iocp_operation* op);
// Request invocation of the given operation and return immediately. Assumes
// that work_started() was previously called for the operations.
ASIO_DECL void post_deferred_completions(
op_queue<win_iocp_operation>& ops);
// Request invocation of the given operation using the thread-private queue
// and return immediately. Assumes that work_started() has not yet been
// called for the operation.
void post_private_immediate_completion(win_iocp_operation* op)
{
post_immediate_completion(op, false);
}
// Request invocation of the given operation using the thread-private queue
// and return immediately. Assumes that work_started() was previously called
// for the operation.
void post_private_deferred_completion(win_iocp_operation* op)
{
post_deferred_completion(op);
}
// Enqueue the given operation following a failed attempt to dispatch the
// operation for immediate invocation.
void do_dispatch(operation* op)
{
post_immediate_completion(op, false);
}
// Process unfinished operations as part of a shutdown operation. Assumes
// that work_started() was previously called for the operations.
ASIO_DECL void abandon_operations(op_queue<operation>& ops);
// Called after starting an overlapped I/O operation that did not complete
// immediately. The caller must have already called work_started() prior to
// starting the operation.
ASIO_DECL void on_pending(win_iocp_operation* op);
// Called after starting an overlapped I/O operation that completed
// immediately. The caller must have already called work_started() prior to
// starting the operation.
ASIO_DECL void on_completion(win_iocp_operation* op,
DWORD last_error = 0, DWORD bytes_transferred = 0);
// Called after starting an overlapped I/O operation that completed
// immediately. The caller must have already called work_started() prior to
// starting the operation.
ASIO_DECL void on_completion(win_iocp_operation* op,
const asio::error_code& ec, DWORD bytes_transferred = 0);
// Add a new timer queue to the service.
template <typename Time_Traits>
void add_timer_queue(timer_queue<Time_Traits>& timer_queue);
// Remove a timer queue from the service.
template <typename Time_Traits>
void remove_timer_queue(timer_queue<Time_Traits>& timer_queue);
// Schedule a new operation in the given timer queue to expire at the
// specified absolute time.
template <typename Time_Traits>
void schedule_timer(timer_queue<Time_Traits>& queue,
const typename Time_Traits::time_type& time,
typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
// Cancel the timer associated with the given token. Returns the number of
// handlers that have been posted or dispatched.
template <typename Time_Traits>
std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& timer,
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
// Cancel the timer operations associated with the given key.
template <typename Time_Traits>
void cancel_timer_by_key(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data* timer,
void* cancellation_key);
// Move the timer operations associated with the given timer.
template <typename Time_Traits>
void move_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& to,
typename timer_queue<Time_Traits>::per_timer_data& from);
// Get the concurrency hint that was used to initialise the io_context.
int concurrency_hint() const
{
return concurrency_hint_;
}
private:
#if defined(WINVER) && (WINVER < 0x0500)
typedef DWORD dword_ptr_t;
typedef ULONG ulong_ptr_t;
#else // defined(WINVER) && (WINVER < 0x0500)
typedef DWORD_PTR dword_ptr_t;
typedef ULONG_PTR ulong_ptr_t;
#endif // defined(WINVER) && (WINVER < 0x0500)
// Dequeues at most one operation from the I/O completion port, and then
// executes it. Returns the number of operations that were dequeued (i.e.
// either 0 or 1).
ASIO_DECL size_t do_one(DWORD msec,
win_iocp_thread_info& this_thread, asio::error_code& ec);
// Helper to calculate the GetQueuedCompletionStatus timeout.
ASIO_DECL static DWORD get_gqcs_timeout();
// Helper function to add a new timer queue.
ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
// Helper function to remove a timer queue.
ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
// Called to recalculate and update the timeout.
ASIO_DECL void update_timeout();
// Helper class to call work_finished() on block exit.
struct work_finished_on_block_exit;
// Helper class for managing a HANDLE.
struct auto_handle
{
HANDLE handle;
auto_handle() : handle(0) {}
~auto_handle() { if (handle) ::CloseHandle(handle); }
};
// The IO completion port used for queueing operations.
auto_handle iocp_;
// The count of unfinished work.
long outstanding_work_;
// Flag to indicate whether the event loop has been stopped.
mutable long stopped_;
// Flag to indicate whether there is an in-flight stop event. Every event
// posted using PostQueuedCompletionStatus consumes non-paged pool, so to
// avoid exhausting this resouce we limit the number of outstanding events.
long stop_event_posted_;
// Flag to indicate whether the service has been shut down.
long shutdown_;
enum
{
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600)
// Timeout to use with GetQueuedCompletionStatus on older versions of
// Windows. Some versions of windows have a "bug" where a call to
// GetQueuedCompletionStatus can appear stuck even though there are events
// waiting on the queue. Using a timeout helps to work around the issue.
default_gqcs_timeout = 500,
#endif // !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600)
// Maximum waitable timer timeout, in milliseconds.
max_timeout_msec = 5 * 60 * 1000,
// Maximum waitable timer timeout, in microseconds.
max_timeout_usec = max_timeout_msec * 1000,
// Completion key value used to wake up a thread to dispatch timers or
// completed operations.
wake_for_dispatch = 1,
// Completion key value to indicate that an operation has posted with the
// original last_error and bytes_transferred values stored in the fields of
// the OVERLAPPED structure.
overlapped_contains_result = 2
};
// Timeout to use with GetQueuedCompletionStatus.
const DWORD gqcs_timeout_;
// Helper class to run the scheduler in its own thread.
struct thread_function;
friend struct thread_function;
// Function object for processing timeouts in a background thread.
struct timer_thread_function;
friend struct timer_thread_function;
// Background thread used for processing timeouts.
scoped_ptr<thread> timer_thread_;
// A waitable timer object used for waiting for timeouts.
auto_handle waitable_timer_;
// Non-zero if timers or completed operations need to be dispatched.
long dispatch_required_;
// Mutex for protecting access to the timer queues and completed operations.
mutex dispatch_mutex_;
// The timer queues.
timer_queue_set timer_queues_;
// The operations that are ready to dispatch.
op_queue<win_iocp_operation> completed_ops_;
// The concurrency hint used to initialise the io_context.
const int concurrency_hint_;
// The thread that is running the io_context.
scoped_ptr<thread> thread_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#include "asio/detail/impl/win_iocp_io_context.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_iocp_io_context.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_IO_CONTEXT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/winrt_timer_scheduler.hpp | //
// detail/winrt_timer_scheduler.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
#define ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
#include <cstddef>
#include "asio/detail/event.hpp"
#include "asio/detail/limits.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/thread.hpp"
#include "asio/detail/timer_queue_base.hpp"
#include "asio/detail/timer_queue_set.hpp"
#include "asio/detail/wait_op.hpp"
#include "asio/execution_context.hpp"
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/win_iocp_io_context.hpp"
#else // defined(ASIO_HAS_IOCP)
# include "asio/detail/scheduler.hpp"
#endif // defined(ASIO_HAS_IOCP)
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/thread.hpp"
#endif // defined(ASIO_HAS_IOCP)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class winrt_timer_scheduler
: public execution_context_service_base<winrt_timer_scheduler>
{
public:
// Constructor.
ASIO_DECL winrt_timer_scheduler(execution_context& context);
// Destructor.
ASIO_DECL ~winrt_timer_scheduler();
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Recreate internal descriptors following a fork.
ASIO_DECL void notify_fork(execution_context::fork_event fork_ev);
// Initialise the task. No effect as this class uses its own thread.
ASIO_DECL void init_task();
// Add a new timer queue to the reactor.
template <typename Time_Traits>
void add_timer_queue(timer_queue<Time_Traits>& queue);
// Remove a timer queue from the reactor.
template <typename Time_Traits>
void remove_timer_queue(timer_queue<Time_Traits>& queue);
// Schedule a new operation in the given timer queue to expire at the
// specified absolute time.
template <typename Time_Traits>
void schedule_timer(timer_queue<Time_Traits>& queue,
const typename Time_Traits::time_type& time,
typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
// Cancel the timer operations associated with the given token. Returns the
// number of operations that have been posted or dispatched.
template <typename Time_Traits>
std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& timer,
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
// Move the timer operations associated with the given timer.
template <typename Time_Traits>
void move_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& to,
typename timer_queue<Time_Traits>::per_timer_data& from);
private:
// Run the select loop in the thread.
ASIO_DECL void run_thread();
// Entry point for the select loop thread.
ASIO_DECL static void call_run_thread(winrt_timer_scheduler* reactor);
// Helper function to add a new timer queue.
ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
// Helper function to remove a timer queue.
ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
// The scheduler implementation used to post completions.
#if defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context scheduler_impl;
#else
typedef class scheduler scheduler_impl;
#endif
scheduler_impl& scheduler_;
// Mutex used to protect internal variables.
asio::detail::mutex mutex_;
// Event used to wake up background thread.
asio::detail::event event_;
// The timer queues.
timer_queue_set timer_queues_;
// The background thread that is waiting for timers to expire.
asio::detail::thread* thread_;
// Does the background thread need to stop.
bool stop_thread_;
// Whether the service has been shut down.
bool shutdown_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#include "asio/detail/impl/winrt_timer_scheduler.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/winrt_timer_scheduler.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_service_base.hpp | //
// detail/io_uring_socket_service_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_SERVICE_BASE_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_SERVICE_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/associated_cancellation_slot.hpp"
#include "asio/buffer.hpp"
#include "asio/cancellation_type.hpp"
#include "asio/error.hpp"
#include "asio/execution_context.hpp"
#include "asio/socket_base.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/io_uring_null_buffers_op.hpp"
#include "asio/detail/io_uring_service.hpp"
#include "asio/detail/io_uring_socket_recv_op.hpp"
#include "asio/detail/io_uring_socket_recvmsg_op.hpp"
#include "asio/detail/io_uring_socket_send_op.hpp"
#include "asio/detail/io_uring_wait_op.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class io_uring_socket_service_base
{
public:
// The native type of a socket.
typedef socket_type native_handle_type;
// The implementation type of the socket.
struct base_implementation_type
{
// The native socket representation.
socket_type socket_;
// The current state of the socket.
socket_ops::state_type state_;
// Per I/O object data used by the io_uring_service.
io_uring_service::per_io_object_data io_object_data_;
};
// Constructor.
ASIO_DECL io_uring_socket_service_base(execution_context& context);
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void base_shutdown();
// Construct a new socket implementation.
ASIO_DECL void construct(base_implementation_type& impl);
// Move-construct a new socket implementation.
ASIO_DECL void base_move_construct(base_implementation_type& impl,
base_implementation_type& other_impl) noexcept;
// Move-assign from another socket implementation.
ASIO_DECL void base_move_assign(base_implementation_type& impl,
io_uring_socket_service_base& other_service,
base_implementation_type& other_impl);
// Destroy a socket implementation.
ASIO_DECL void destroy(base_implementation_type& impl);
// Determine whether the socket is open.
bool is_open(const base_implementation_type& impl) const
{
return impl.socket_ != invalid_socket;
}
// Destroy a socket implementation.
ASIO_DECL asio::error_code close(
base_implementation_type& impl, asio::error_code& ec);
// Release ownership of the socket.
ASIO_DECL socket_type release(
base_implementation_type& impl, asio::error_code& ec);
// Get the native socket representation.
native_handle_type native_handle(base_implementation_type& impl)
{
return impl.socket_;
}
// Cancel all operations associated with the socket.
ASIO_DECL asio::error_code cancel(
base_implementation_type& impl, asio::error_code& ec);
// Determine whether the socket is at the out-of-band data mark.
bool at_mark(const base_implementation_type& impl,
asio::error_code& ec) const
{
return socket_ops::sockatmark(impl.socket_, ec);
}
// Determine the number of bytes available for reading.
std::size_t available(const base_implementation_type& impl,
asio::error_code& ec) const
{
return socket_ops::available(impl.socket_, ec);
}
// Place the socket into the state where it will listen for new connections.
asio::error_code listen(base_implementation_type& impl,
int backlog, asio::error_code& ec)
{
socket_ops::listen(impl.socket_, backlog, ec);
return ec;
}
// Perform an IO control command on the socket.
template <typename IO_Control_Command>
asio::error_code io_control(base_implementation_type& impl,
IO_Control_Command& command, asio::error_code& ec)
{
socket_ops::ioctl(impl.socket_, impl.state_, command.name(),
static_cast<ioctl_arg_type*>(command.data()), ec);
return ec;
}
// Gets the non-blocking mode of the socket.
bool non_blocking(const base_implementation_type& impl) const
{
return (impl.state_ & socket_ops::user_set_non_blocking) != 0;
}
// Sets the non-blocking mode of the socket.
asio::error_code non_blocking(base_implementation_type& impl,
bool mode, asio::error_code& ec)
{
socket_ops::set_user_non_blocking(impl.socket_, impl.state_, mode, ec);
return ec;
}
// Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking(const base_implementation_type& impl) const
{
return (impl.state_ & socket_ops::internal_non_blocking) != 0;
}
// Sets the non-blocking mode of the native socket implementation.
asio::error_code native_non_blocking(base_implementation_type& impl,
bool mode, asio::error_code& ec)
{
socket_ops::set_internal_non_blocking(impl.socket_, impl.state_, mode, ec);
return ec;
}
// Wait for the socket to become ready to read, ready to write, or to have
// pending error conditions.
asio::error_code wait(base_implementation_type& impl,
socket_base::wait_type w, asio::error_code& ec)
{
switch (w)
{
case socket_base::wait_read:
socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
break;
case socket_base::wait_write:
socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
break;
case socket_base::wait_error:
socket_ops::poll_error(impl.socket_, impl.state_, -1, ec);
break;
default:
ec = asio::error::invalid_argument;
break;
}
return ec;
}
// Asynchronously wait for the socket to become ready to read, ready to
// write, or to have pending error conditions.
template <typename Handler, typename IoExecutor>
void async_wait(base_implementation_type& impl,
socket_base::wait_type w, Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
int op_type;
int poll_flags;
switch (w)
{
case socket_base::wait_read:
op_type = io_uring_service::read_op;
poll_flags = POLLIN;
break;
case socket_base::wait_write:
op_type = io_uring_service::write_op;
poll_flags = POLLOUT;
break;
case socket_base::wait_error:
op_type = io_uring_service::except_op;
poll_flags = POLLPRI | POLLERR | POLLHUP;
break;
default:
op_type = -1;
poll_flags = -1;
return;
}
// Allocate and construct an operation to wrap the handler.
typedef io_uring_wait_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_,
poll_flags, handler, io_ex);
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"socket", &impl, impl.socket_, "async_wait"));
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(
&io_uring_service_, &impl.io_object_data_, op_type);
}
start_op(impl, op_type, p.p, is_continuation, op_type == -1);
p.v = p.p = 0;
}
// Send the given data to the peer.
template <typename ConstBufferSequence>
size_t send(base_implementation_type& impl,
const ConstBufferSequence& buffers,
socket_base::message_flags flags, asio::error_code& ec)
{
typedef buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs_type;
if (bufs_type::is_single_buffer)
{
return socket_ops::sync_send1(impl.socket_,
impl.state_, bufs_type::first(buffers).data(),
bufs_type::first(buffers).size(), flags, ec);
}
else
{
bufs_type bufs(buffers);
return socket_ops::sync_send(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
}
}
// Wait until data can be sent without blocking.
size_t send(base_implementation_type& impl, const null_buffers&,
socket_base::message_flags, asio::error_code& ec)
{
// Wait for socket to become ready.
socket_ops::poll_write(impl.socket_, impl.state_, -1, ec);
return 0;
}
// Start an asynchronous send. The data being sent must be valid for the
// lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_send(base_implementation_type& impl,
const ConstBufferSequence& buffers, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_socket_send_op<
ConstBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_,
impl.state_, buffers, flags, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::write_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"socket", &impl, impl.socket_, "async_send"));
start_op(impl, io_uring_service::write_op, p.p, is_continuation,
((impl.state_ & socket_ops::stream_oriented)
&& buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence>::all_empty(buffers)));
p.v = p.p = 0;
}
// Start an asynchronous wait until data can be sent without blocking.
template <typename Handler, typename IoExecutor>
void async_send(base_implementation_type& impl, const null_buffers&,
socket_base::message_flags, Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_, POLLOUT, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::write_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"socket", &impl, impl.socket_, "async_send(null_buffers)"));
start_op(impl, io_uring_service::write_op, p.p, is_continuation, false);
p.v = p.p = 0;
}
// Receive some data from the peer. Returns the number of bytes received.
template <typename MutableBufferSequence>
size_t receive(base_implementation_type& impl,
const MutableBufferSequence& buffers,
socket_base::message_flags flags, asio::error_code& ec)
{
typedef buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs_type;
if (bufs_type::is_single_buffer)
{
return socket_ops::sync_recv1(impl.socket_,
impl.state_, bufs_type::first(buffers).data(),
bufs_type::first(buffers).size(), flags, ec);
}
else
{
bufs_type bufs(buffers);
return socket_ops::sync_recv(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), flags, bufs.all_empty(), ec);
}
}
// Wait until data can be received without blocking.
size_t receive(base_implementation_type& impl, const null_buffers&,
socket_base::message_flags, asio::error_code& ec)
{
// Wait for socket to become ready.
socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
return 0;
}
// Start an asynchronous receive. The buffer for the data being received
// must be valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_receive(base_implementation_type& impl,
const MutableBufferSequence& buffers, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
int op_type = (flags & socket_base::message_out_of_band)
? io_uring_service::except_op : io_uring_service::read_op;
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_socket_recv_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_,
impl.state_, buffers, flags, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(
&io_uring_service_, &impl.io_object_data_, op_type);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"socket", &impl, impl.socket_, "async_receive"));
start_op(impl, op_type, p.p, is_continuation,
((impl.state_ & socket_ops::stream_oriented)
&& buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::all_empty(buffers)));
p.v = p.p = 0;
}
// Wait until data can be received without blocking.
template <typename Handler, typename IoExecutor>
void async_receive(base_implementation_type& impl,
const null_buffers&, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
int op_type;
int poll_flags;
if ((flags & socket_base::message_out_of_band) != 0)
{
op_type = io_uring_service::except_op;
poll_flags = POLLPRI;
}
else
{
op_type = io_uring_service::read_op;
poll_flags = POLLIN;
}
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_, poll_flags, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(
&io_uring_service_, &impl.io_object_data_, op_type);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"socket", &impl, impl.socket_, "async_receive(null_buffers)"));
start_op(impl, op_type, p.p, is_continuation, false);
p.v = p.p = 0;
}
// Receive some data with associated flags. Returns the number of bytes
// received.
template <typename MutableBufferSequence>
size_t receive_with_flags(base_implementation_type& impl,
const MutableBufferSequence& buffers,
socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, asio::error_code& ec)
{
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(buffers);
return socket_ops::sync_recvmsg(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), in_flags, out_flags, ec);
}
// Wait until data can be received without blocking.
size_t receive_with_flags(base_implementation_type& impl,
const null_buffers&, socket_base::message_flags,
socket_base::message_flags& out_flags, asio::error_code& ec)
{
// Wait for socket to become ready.
socket_ops::poll_read(impl.socket_, impl.state_, -1, ec);
// Clear out_flags, since we cannot give it any other sensible value when
// performing a null_buffers operation.
out_flags = 0;
return 0;
}
// Start an asynchronous receive. The buffer for the data being received
// must be valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_receive_with_flags(base_implementation_type& impl,
const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, Handler& handler,
const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
int op_type = (in_flags & socket_base::message_out_of_band)
? io_uring_service::except_op : io_uring_service::read_op;
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_socket_recvmsg_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_, impl.state_,
buffers, in_flags, out_flags, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(
&io_uring_service_, &impl.io_object_data_, op_type);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"socket", &impl, impl.socket_, "async_receive_with_flags"));
start_op(impl, op_type, p.p, is_continuation, false);
p.v = p.p = 0;
}
// Wait until data can be received without blocking.
template <typename Handler, typename IoExecutor>
void async_receive_with_flags(base_implementation_type& impl,
const null_buffers&, socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, Handler& handler,
const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
int op_type;
int poll_flags;
if ((in_flags & socket_base::message_out_of_band) != 0)
{
op_type = io_uring_service::except_op;
poll_flags = POLLPRI;
}
else
{
op_type = io_uring_service::read_op;
poll_flags = POLLIN;
}
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.socket_, poll_flags, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(
&io_uring_service_, &impl.io_object_data_, op_type);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "socket",
&impl, impl.socket_, "async_receive_with_flags(null_buffers)"));
// Clear out_flags, since we cannot give it any other sensible value when
// performing a null_buffers operation.
out_flags = 0;
start_op(impl, op_type, p.p, is_continuation, false);
p.v = p.p = 0;
}
protected:
// Open a new socket implementation.
ASIO_DECL asio::error_code do_open(
base_implementation_type& impl, int af,
int type, int protocol, asio::error_code& ec);
// Assign a native socket to a socket implementation.
ASIO_DECL asio::error_code do_assign(
base_implementation_type& impl, int type,
const native_handle_type& native_socket, asio::error_code& ec);
// Start the asynchronous read or write operation.
ASIO_DECL void start_op(base_implementation_type& impl, int op_type,
io_uring_operation* op, bool is_continuation, bool noop);
// Start the asynchronous accept operation.
ASIO_DECL void start_accept_op(base_implementation_type& impl,
io_uring_operation* op, bool is_continuation, bool peer_is_open);
// Helper class used to implement per-operation cancellation
class io_uring_op_cancellation
{
public:
io_uring_op_cancellation(io_uring_service* s,
io_uring_service::per_io_object_data* p, int o)
: io_uring_service_(s),
io_object_data_(p),
op_type_(o)
{
}
void operator()(cancellation_type_t type)
{
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
io_uring_service_->cancel_ops_by_key(*io_object_data_, op_type_, this);
}
}
private:
io_uring_service* io_uring_service_;
io_uring_service::per_io_object_data* io_object_data_;
int op_type_;
};
// The io_uring_service that performs event demultiplexing for the service.
io_uring_service& io_uring_service_;
// Cached success value to avoid accessing category singleton.
const asio::error_code success_ec_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/io_uring_socket_service_base.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_SERVICE_BASE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_operation.hpp | //
// detail/io_uring_operation.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_OPERATION_HPP
#define ASIO_DETAIL_IO_URING_OPERATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include <liburing.h>
#include "asio/detail/cstdint.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class io_uring_operation
: public operation
{
public:
// The error code to be passed to the completion handler.
asio::error_code ec_;
// The number of bytes transferred, to be passed to the completion handler.
std::size_t bytes_transferred_;
// The operation key used for targeted cancellation.
void* cancellation_key_;
// Prepare the operation.
void prepare(::io_uring_sqe* sqe)
{
return prepare_func_(this, sqe);
}
// Perform actions associated with the operation. Returns true when complete.
bool perform(bool after_completion)
{
return perform_func_(this, after_completion);
}
protected:
typedef void (*prepare_func_type)(io_uring_operation*, ::io_uring_sqe*);
typedef bool (*perform_func_type)(io_uring_operation*, bool);
io_uring_operation(const asio::error_code& success_ec,
prepare_func_type prepare_func, perform_func_type perform_func,
func_type complete_func)
: operation(complete_func),
ec_(success_ec),
bytes_transferred_(0),
cancellation_key_(0),
prepare_func_(prepare_func),
perform_func_(perform_func)
{
}
private:
prepare_func_type prepare_func_;
perform_func_type perform_func_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_OPERATION_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_event.hpp | //
// detail/win_event.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_EVENT_HPP
#define ASIO_DETAIL_WIN_EVENT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS)
#include <cstddef>
#include "asio/detail/assert.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class win_event
: private noncopyable
{
public:
// Constructor.
ASIO_DECL win_event();
// Destructor.
ASIO_DECL ~win_event();
// Signal the event. (Retained for backward compatibility.)
template <typename Lock>
void signal(Lock& lock)
{
this->signal_all(lock);
}
// Signal all waiters.
template <typename Lock>
void signal_all(Lock& lock)
{
ASIO_ASSERT(lock.locked());
(void)lock;
state_ |= 1;
::SetEvent(events_[0]);
}
// Unlock the mutex and signal one waiter.
template <typename Lock>
void unlock_and_signal_one(Lock& lock)
{
ASIO_ASSERT(lock.locked());
state_ |= 1;
bool have_waiters = (state_ > 1);
lock.unlock();
if (have_waiters)
::SetEvent(events_[1]);
}
// Unlock the mutex and signal one waiter who may destroy us.
template <typename Lock>
void unlock_and_signal_one_for_destruction(Lock& lock)
{
ASIO_ASSERT(lock.locked());
state_ |= 1;
bool have_waiters = (state_ > 1);
if (have_waiters)
::SetEvent(events_[1]);
lock.unlock();
}
// If there's a waiter, unlock the mutex and signal it.
template <typename Lock>
bool maybe_unlock_and_signal_one(Lock& lock)
{
ASIO_ASSERT(lock.locked());
state_ |= 1;
if (state_ > 1)
{
lock.unlock();
::SetEvent(events_[1]);
return true;
}
return false;
}
// Reset the event.
template <typename Lock>
void clear(Lock& lock)
{
ASIO_ASSERT(lock.locked());
(void)lock;
::ResetEvent(events_[0]);
state_ &= ~std::size_t(1);
}
// Wait for the event to become signalled.
template <typename Lock>
void wait(Lock& lock)
{
ASIO_ASSERT(lock.locked());
while ((state_ & 1) == 0)
{
state_ += 2;
lock.unlock();
#if defined(ASIO_WINDOWS_APP)
::WaitForMultipleObjectsEx(2, events_, false, INFINITE, false);
#else // defined(ASIO_WINDOWS_APP)
::WaitForMultipleObjects(2, events_, false, INFINITE);
#endif // defined(ASIO_WINDOWS_APP)
lock.lock();
state_ -= 2;
}
}
// Timed wait for the event to become signalled.
template <typename Lock>
bool wait_for_usec(Lock& lock, long usec)
{
ASIO_ASSERT(lock.locked());
if ((state_ & 1) == 0)
{
state_ += 2;
lock.unlock();
DWORD msec = usec > 0 ? (usec < 1000 ? 1 : usec / 1000) : 0;
#if defined(ASIO_WINDOWS_APP)
::WaitForMultipleObjectsEx(2, events_, false, msec, false);
#else // defined(ASIO_WINDOWS_APP)
::WaitForMultipleObjects(2, events_, false, msec);
#endif // defined(ASIO_WINDOWS_APP)
lock.lock();
state_ -= 2;
}
return (state_ & 1) != 0;
}
private:
HANDLE events_[2];
std::size_t state_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_event.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS)
#endif // ASIO_DETAIL_WIN_EVENT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/fenced_block.hpp | //
// detail/fenced_block.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_FENCED_BLOCK_HPP
#define ASIO_DETAIL_FENCED_BLOCK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_HAS_THREADS) \
|| defined(ASIO_DISABLE_FENCED_BLOCK)
# include "asio/detail/null_fenced_block.hpp"
#else
# include "asio/detail/std_fenced_block.hpp"
#endif
namespace asio {
namespace detail {
#if !defined(ASIO_HAS_THREADS) \
|| defined(ASIO_DISABLE_FENCED_BLOCK)
typedef null_fenced_block fenced_block;
#else
typedef std_fenced_block fenced_block;
#endif
} // namespace detail
} // namespace asio
#endif // ASIO_DETAIL_FENCED_BLOCK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/std_fenced_block.hpp | //
// detail/std_fenced_block.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_STD_FENCED_BLOCK_HPP
#define ASIO_DETAIL_STD_FENCED_BLOCK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <atomic>
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class std_fenced_block
: private noncopyable
{
public:
enum half_t { half };
enum full_t { full };
// Constructor for a half fenced block.
explicit std_fenced_block(half_t)
{
}
// Constructor for a full fenced block.
explicit std_fenced_block(full_t)
{
std::atomic_thread_fence(std::memory_order_acquire);
}
// Destructor.
~std_fenced_block()
{
std::atomic_thread_fence(std::memory_order_release);
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_STD_FENCED_BLOCK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_static_mutex.hpp | //
// detail/win_static_mutex.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
#define ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS)
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
struct win_static_mutex
{
typedef asio::detail::scoped_lock<win_static_mutex> scoped_lock;
// Initialise the mutex.
ASIO_DECL void init();
// Initialisation must be performed in a separate function to the "public"
// init() function since the compiler does not support the use of structured
// exceptions and C++ exceptions in the same function.
ASIO_DECL int do_init();
// Lock the mutex.
void lock()
{
::EnterCriticalSection(&crit_section_);
}
// Unlock the mutex.
void unlock()
{
::LeaveCriticalSection(&crit_section_);
}
bool initialised_;
::CRITICAL_SECTION crit_section_;
};
#if defined(UNDER_CE)
# define ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } }
#else // defined(UNDER_CE)
# define ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } }
#endif // defined(UNDER_CE)
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_static_mutex.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS)
#endif // ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/conditionally_enabled_event.hpp | //
// detail/conditionally_enabled_event.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_HPP
#define ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/conditionally_enabled_mutex.hpp"
#include "asio/detail/event.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/null_event.hpp"
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Mutex adapter used to conditionally enable or disable locking.
class conditionally_enabled_event
: private noncopyable
{
public:
// Constructor.
conditionally_enabled_event()
{
}
// Destructor.
~conditionally_enabled_event()
{
}
// Signal the event. (Retained for backward compatibility.)
void signal(conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
event_.signal(lock);
}
// Signal all waiters.
void signal_all(conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
event_.signal_all(lock);
}
// Unlock the mutex and signal one waiter.
void unlock_and_signal_one(
conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
event_.unlock_and_signal_one(lock);
}
// Unlock the mutex and signal one waiter who may destroy us.
void unlock_and_signal_one_for_destruction(
conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
event_.unlock_and_signal_one(lock);
}
// If there's a waiter, unlock the mutex and signal it.
bool maybe_unlock_and_signal_one(
conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
return event_.maybe_unlock_and_signal_one(lock);
else
return false;
}
// Reset the event.
void clear(conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
event_.clear(lock);
}
// Wait for the event to become signalled.
void wait(conditionally_enabled_mutex::scoped_lock& lock)
{
if (lock.mutex_.enabled_)
event_.wait(lock);
else
null_event().wait(lock);
}
// Timed wait for the event to become signalled.
bool wait_for_usec(
conditionally_enabled_mutex::scoped_lock& lock, long usec)
{
if (lock.mutex_.enabled_)
return event_.wait_for_usec(lock, usec);
else
return null_event().wait_for_usec(lock, usec);
}
private:
asio::detail::event event_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/thread_context.hpp | //
// detail/thread_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_THREAD_CONTEXT_HPP
#define ASIO_DETAIL_THREAD_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <climits>
#include <cstddef>
#include "asio/detail/call_stack.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class thread_info_base;
// Base class for things that manage threads (scheduler, win_iocp_io_context).
class thread_context
{
public:
// Obtain a pointer to the top of the thread call stack. Returns null when
// not running inside a thread context.
ASIO_DECL static thread_info_base* top_of_thread_call_stack();
protected:
// Per-thread call stack to track the state of each thread in the context.
typedef call_stack<thread_context, thread_info_base> thread_call_stack;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/thread_context.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // ASIO_DETAIL_THREAD_CONTEXT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/posix_signal_blocker.hpp | //
// detail/posix_signal_blocker.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
#define ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_PTHREADS)
#include <csignal>
#include <pthread.h>
#include <signal.h>
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class posix_signal_blocker
: private noncopyable
{
public:
// Constructor blocks all signals for the calling thread.
posix_signal_blocker()
: blocked_(false)
{
sigset_t new_mask;
sigfillset(&new_mask);
blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
}
// Destructor restores the previous signal mask.
~posix_signal_blocker()
{
if (blocked_)
pthread_sigmask(SIG_SETMASK, &old_mask_, 0);
}
// Block all signals for the calling thread.
void block()
{
if (!blocked_)
{
sigset_t new_mask;
sigfillset(&new_mask);
blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
}
}
// Restore the previous signal mask.
void unblock()
{
if (blocked_)
blocked_ = (pthread_sigmask(SIG_SETMASK, &old_mask_, 0) != 0);
}
private:
// Have signals been blocked.
bool blocked_;
// The previous signal mask.
sigset_t old_mask_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_PTHREADS)
#endif // ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/timed_cancel_op.hpp | //
// detail/timed_cancel_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_TIMED_CANCEL_OP_HPP
#define ASIO_DETAIL_TIMED_CANCEL_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/associated_cancellation_slot.hpp"
#include "asio/associator.hpp"
#include "asio/basic_waitable_timer.hpp"
#include "asio/cancellation_signal.hpp"
#include "asio/detail/atomic_count.hpp"
#include "asio/detail/completion_payload.hpp"
#include "asio/detail/completion_payload_handler.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Op, typename... Signatures>
class timed_cancel_op_handler;
template <typename Op>
class timed_cancel_timer_handler;
template <typename Handler, typename Timer, typename... Signatures>
class timed_cancel_op
{
public:
using handler_type = Handler;
ASIO_DEFINE_TAGGED_HANDLER_PTR(
thread_info_base::timed_cancel_tag, timed_cancel_op);
timed_cancel_op(Handler& handler, Timer timer,
cancellation_type_t cancel_type)
: ref_count_(2),
handler_(static_cast<Handler&&>(handler)),
timer_(static_cast<Timer&&>(timer)),
cancellation_type_(cancel_type),
cancel_proxy_(nullptr),
has_payload_(false),
has_pending_timer_wait_(true)
{
}
~timed_cancel_op()
{
if (has_payload_)
payload_storage_.payload_.~payload_type();
}
cancellation_slot get_cancellation_slot() noexcept
{
return cancellation_signal_.slot();
}
template <typename Initiation, typename... Args>
void start(Initiation&& initiation, Args&&... args)
{
using op_handler_type =
timed_cancel_op_handler<timed_cancel_op, Signatures...>;
op_handler_type op_handler(this);
using timer_handler_type =
timed_cancel_timer_handler<timed_cancel_op>;
timer_handler_type timer_handler(this);
associated_cancellation_slot_t<Handler> slot
= (get_associated_cancellation_slot)(handler_);
if (slot.is_connected())
cancel_proxy_ = &slot.template emplace<cancel_proxy>(this);
timer_.async_wait(static_cast<timer_handler_type&&>(timer_handler));
async_initiate<op_handler_type, Signatures...>(
static_cast<Initiation&&>(initiation),
static_cast<op_handler_type&>(op_handler),
static_cast<Args&&>(args)...);
}
template <typename Message>
void handle_op(Message&& message)
{
if (cancel_proxy_)
cancel_proxy_->op_ = nullptr;
new (&payload_storage_.payload_) payload_type(
static_cast<Message&&>(message));
has_payload_ = true;
if (has_pending_timer_wait_)
{
timer_.cancel();
release();
}
else
{
complete();
}
}
void handle_timer()
{
has_pending_timer_wait_ = false;
if (has_payload_)
{
complete();
}
else
{
cancellation_signal_.emit(cancellation_type_);
release();
}
}
void release()
{
if (--ref_count_ == 0)
{
ptr p = { asio::detail::addressof(handler_), this, this };
Handler handler(static_cast<Handler&&>(handler_));
p.h = asio::detail::addressof(handler);
p.reset();
}
}
void complete()
{
if (--ref_count_ == 0)
{
ptr p = { asio::detail::addressof(handler_), this, this };
completion_payload_handler<payload_type, Handler> handler(
static_cast<payload_type&&>(payload_storage_.payload_), handler_);
p.h = asio::detail::addressof(handler.handler());
p.reset();
handler();
}
}
//private:
typedef completion_payload<Signatures...> payload_type;
struct cancel_proxy
{
cancel_proxy(timed_cancel_op* op)
: op_(op)
{
}
void operator()(cancellation_type_t type)
{
if (op_)
op_->cancellation_signal_.emit(type);
}
timed_cancel_op* op_;
};
// The number of handlers that share a reference to the state.
atomic_count ref_count_;
// The handler to be called when the operation completes.
Handler handler_;
// The timer used to determine when to cancel the pending operation.
Timer timer_;
// The cancellation signal and type used to cancel the pending operation.
cancellation_signal cancellation_signal_;
cancellation_type_t cancellation_type_;
// A proxy cancel handler used to allow cancellation of the timed operation.
cancel_proxy* cancel_proxy_;
// Arguments to be passed to the completion handler.
union payload_storage
{
payload_storage() {}
~payload_storage() {}
char dummy_;
payload_type payload_;
} payload_storage_;
// Whether the payload storage contains a valid payload.
bool has_payload_;
// Whether the asynchronous wait on the timer is still pending
bool has_pending_timer_wait_;
};
template <typename Op, typename R, typename... Args>
class timed_cancel_op_handler<Op, R(Args...)>
{
public:
using cancellation_slot_type = cancellation_slot;
explicit timed_cancel_op_handler(Op* op)
: op_(op)
{
}
timed_cancel_op_handler(timed_cancel_op_handler&& other) noexcept
: op_(other.op_)
{
other.op_ = nullptr;
}
~timed_cancel_op_handler()
{
if (op_)
op_->release();
}
cancellation_slot_type get_cancellation_slot() const noexcept
{
return op_->get_cancellation_slot();
}
template <typename... Args2>
enable_if_t<
is_constructible<completion_message<R(Args...)>, int, Args2...>::value
> operator()(Args2&&... args)
{
Op* op = op_;
op_ = nullptr;
typedef completion_message<R(Args...)> message_type;
op->handle_op(message_type(0, static_cast<Args2&&>(args)...));
}
//protected:
Op* op_;
};
template <typename Op, typename R, typename... Args, typename... Signatures>
class timed_cancel_op_handler<Op, R(Args...), Signatures...> :
public timed_cancel_op_handler<Op, Signatures...>
{
public:
using timed_cancel_op_handler<Op, Signatures...>::timed_cancel_op_handler;
using timed_cancel_op_handler<Op, Signatures...>::operator();
template <typename... Args2>
enable_if_t<
is_constructible<completion_message<R(Args...)>, int, Args2...>::value
> operator()(Args2&&... args)
{
Op* op = this->op_;
this->op_ = nullptr;
typedef completion_message<R(Args...)> message_type;
op->handle_op(message_type(0, static_cast<Args2&&>(args)...));
}
};
template <typename Op>
class timed_cancel_timer_handler
{
public:
using cancellation_slot_type = cancellation_slot;
explicit timed_cancel_timer_handler(Op* op)
: op_(op)
{
}
timed_cancel_timer_handler(timed_cancel_timer_handler&& other) noexcept
: op_(other.op_)
{
other.op_ = nullptr;
}
~timed_cancel_timer_handler()
{
if (op_)
op_->release();
}
cancellation_slot_type get_cancellation_slot() const noexcept
{
return cancellation_slot_type();
}
void operator()(const asio::error_code&)
{
Op* op = op_;
op_ = nullptr;
op->handle_timer();
}
//private:
Op* op_;
};
} // namespace detail
template <template <typename, typename> class Associator,
typename Op, typename... Signatures, typename DefaultCandidate>
struct associator<Associator,
detail::timed_cancel_op_handler<Op, Signatures...>, DefaultCandidate>
: Associator<typename Op::handler_type, DefaultCandidate>
{
static typename Associator<typename Op::handler_type, DefaultCandidate>::type
get(const detail::timed_cancel_op_handler<Op, Signatures...>& h) noexcept
{
return Associator<typename Op::handler_type, DefaultCandidate>::get(
h.op_->handler_);
}
static auto get(const detail::timed_cancel_op_handler<Op, Signatures...>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<typename Op::handler_type, DefaultCandidate>::get(
h.op_->handler_, c))
{
return Associator<typename Op::handler_type, DefaultCandidate>::get(
h.op_->handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Op, typename DefaultCandidate>
struct associator<Associator,
detail::timed_cancel_timer_handler<Op>, DefaultCandidate>
: Associator<typename Op::handler_type, DefaultCandidate>
{
static typename Associator<typename Op::handler_type, DefaultCandidate>::type
get(const detail::timed_cancel_timer_handler<Op>& h) noexcept
{
return Associator<typename Op::handler_type, DefaultCandidate>::get(
h.op_->handler_);
}
static auto get(const detail::timed_cancel_timer_handler<Op>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<typename Op::handler_type, DefaultCandidate>::get(
h.op_->handler_, c))
{
return Associator<typename Op::handler_type, DefaultCandidate>::get(
h.op_->handler_, c);
}
};
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_TIMED_CANCEL_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/std_global.hpp | //
// detail/std_global.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_STD_GLOBAL_HPP
#define ASIO_DETAIL_STD_GLOBAL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <exception>
#include <mutex>
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename T>
struct std_global_impl
{
// Helper function to perform initialisation.
static void do_init()
{
instance_.ptr_ = new T;
}
// Destructor automatically cleans up the global.
~std_global_impl()
{
delete ptr_;
}
static std::once_flag init_once_;
static std_global_impl instance_;
T* ptr_;
};
template <typename T>
std::once_flag std_global_impl<T>::init_once_;
template <typename T>
std_global_impl<T> std_global_impl<T>::instance_;
template <typename T>
T& std_global()
{
std::call_once(std_global_impl<T>::init_once_, &std_global_impl<T>::do_init);
return *std_global_impl<T>::instance_.ptr_;
}
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_STD_GLOBAL_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/epoll_reactor.hpp | //
// detail/epoll_reactor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_EPOLL_REACTOR_HPP
#define ASIO_DETAIL_EPOLL_REACTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_EPOLL)
#include "asio/detail/atomic_count.hpp"
#include "asio/detail/conditionally_enabled_mutex.hpp"
#include "asio/detail/limits.hpp"
#include "asio/detail/object_pool.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/scheduler_task.hpp"
#include "asio/detail/select_interrupter.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/timer_queue_base.hpp"
#include "asio/detail/timer_queue_set.hpp"
#include "asio/detail/wait_op.hpp"
#include "asio/execution_context.hpp"
#if defined(ASIO_HAS_TIMERFD)
# include <sys/timerfd.h>
#endif // defined(ASIO_HAS_TIMERFD)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class epoll_reactor
: public execution_context_service_base<epoll_reactor>,
public scheduler_task
{
private:
// The mutex type used by this reactor.
typedef conditionally_enabled_mutex mutex;
public:
enum op_types { read_op = 0, write_op = 1,
connect_op = 1, except_op = 2, max_ops = 3 };
// Per-descriptor queues.
class descriptor_state : operation
{
friend class epoll_reactor;
friend class object_pool_access;
descriptor_state* next_;
descriptor_state* prev_;
mutex mutex_;
epoll_reactor* reactor_;
int descriptor_;
uint32_t registered_events_;
op_queue<reactor_op> op_queue_[max_ops];
bool try_speculative_[max_ops];
bool shutdown_;
ASIO_DECL descriptor_state(bool locking);
void set_ready_events(uint32_t events) { task_result_ = events; }
void add_ready_events(uint32_t events) { task_result_ |= events; }
ASIO_DECL operation* perform_io(uint32_t events);
ASIO_DECL static void do_complete(
void* owner, operation* base,
const asio::error_code& ec, std::size_t bytes_transferred);
};
// Per-descriptor data.
typedef descriptor_state* per_descriptor_data;
// Constructor.
ASIO_DECL epoll_reactor(asio::execution_context& ctx);
// Destructor.
ASIO_DECL ~epoll_reactor();
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Recreate internal descriptors following a fork.
ASIO_DECL void notify_fork(
asio::execution_context::fork_event fork_ev);
// Initialise the task.
ASIO_DECL void init_task();
// Register a socket with the reactor. Returns 0 on success, system error
// code on failure.
ASIO_DECL int register_descriptor(socket_type descriptor,
per_descriptor_data& descriptor_data);
// Register a descriptor with an associated single operation. Returns 0 on
// success, system error code on failure.
ASIO_DECL int register_internal_descriptor(
int op_type, socket_type descriptor,
per_descriptor_data& descriptor_data, reactor_op* op);
// Move descriptor registration from one descriptor_data object to another.
ASIO_DECL void move_descriptor(socket_type descriptor,
per_descriptor_data& target_descriptor_data,
per_descriptor_data& source_descriptor_data);
// Post a reactor operation for immediate completion.
void post_immediate_completion(operation* op, bool is_continuation) const;
// Post a reactor operation for immediate completion.
ASIO_DECL static void call_post_immediate_completion(
operation* op, bool is_continuation, const void* self);
// Start a new operation. The reactor operation will be performed when the
// given descriptor is flagged as ready, or an error has occurred.
ASIO_DECL void start_op(int op_type, socket_type descriptor,
per_descriptor_data& descriptor_data, reactor_op* op,
bool is_continuation, bool allow_speculative,
void (*on_immediate)(operation*, bool, const void*),
const void* immediate_arg);
// Start a new operation. The reactor operation will be performed when the
// given descriptor is flagged as ready, or an error has occurred.
void start_op(int op_type, socket_type descriptor,
per_descriptor_data& descriptor_data, reactor_op* op,
bool is_continuation, bool allow_speculative)
{
start_op(op_type, descriptor, descriptor_data,
op, is_continuation, allow_speculative,
&epoll_reactor::call_post_immediate_completion, this);
}
// Cancel all operations associated with the given descriptor. The
// handlers associated with the descriptor will be invoked with the
// operation_aborted error.
ASIO_DECL void cancel_ops(socket_type descriptor,
per_descriptor_data& descriptor_data);
// Cancel all operations associated with the given descriptor and key. The
// handlers associated with the descriptor will be invoked with the
// operation_aborted error.
ASIO_DECL void cancel_ops_by_key(socket_type descriptor,
per_descriptor_data& descriptor_data,
int op_type, void* cancellation_key);
// Cancel any operations that are running against the descriptor and remove
// its registration from the reactor. The reactor resources associated with
// the descriptor must be released by calling cleanup_descriptor_data.
ASIO_DECL void deregister_descriptor(socket_type descriptor,
per_descriptor_data& descriptor_data, bool closing);
// Remove the descriptor's registration from the reactor. The reactor
// resources associated with the descriptor must be released by calling
// cleanup_descriptor_data.
ASIO_DECL void deregister_internal_descriptor(
socket_type descriptor, per_descriptor_data& descriptor_data);
// Perform any post-deregistration cleanup tasks associated with the
// descriptor data.
ASIO_DECL void cleanup_descriptor_data(
per_descriptor_data& descriptor_data);
// Add a new timer queue to the reactor.
template <typename Time_Traits>
void add_timer_queue(timer_queue<Time_Traits>& timer_queue);
// Remove a timer queue from the reactor.
template <typename Time_Traits>
void remove_timer_queue(timer_queue<Time_Traits>& timer_queue);
// Schedule a new operation in the given timer queue to expire at the
// specified absolute time.
template <typename Time_Traits>
void schedule_timer(timer_queue<Time_Traits>& queue,
const typename Time_Traits::time_type& time,
typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
// Cancel the timer operations associated with the given token. Returns the
// number of operations that have been posted or dispatched.
template <typename Time_Traits>
std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& timer,
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
// Cancel the timer operations associated with the given key.
template <typename Time_Traits>
void cancel_timer_by_key(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data* timer,
void* cancellation_key);
// Move the timer operations associated with the given timer.
template <typename Time_Traits>
void move_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& target,
typename timer_queue<Time_Traits>::per_timer_data& source);
// Run epoll once until interrupted or events are ready to be dispatched.
ASIO_DECL void run(long usec, op_queue<operation>& ops);
// Interrupt the select loop.
ASIO_DECL void interrupt();
private:
// The hint to pass to epoll_create to size its data structures.
enum { epoll_size = 20000 };
// Create the epoll file descriptor. Throws an exception if the descriptor
// cannot be created.
ASIO_DECL static int do_epoll_create();
// Create the timerfd file descriptor. Does not throw.
ASIO_DECL static int do_timerfd_create();
// Allocate a new descriptor state object.
ASIO_DECL descriptor_state* allocate_descriptor_state();
// Free an existing descriptor state object.
ASIO_DECL void free_descriptor_state(descriptor_state* s);
// Helper function to add a new timer queue.
ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
// Helper function to remove a timer queue.
ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
// Called to recalculate and update the timeout.
ASIO_DECL void update_timeout();
// Get the timeout value for the epoll_wait call. The timeout value is
// returned as a number of milliseconds. A return value of -1 indicates
// that epoll_wait should block indefinitely.
ASIO_DECL int get_timeout(int msec);
#if defined(ASIO_HAS_TIMERFD)
// Get the timeout value for the timer descriptor. The return value is the
// flag argument to be used when calling timerfd_settime.
ASIO_DECL int get_timeout(itimerspec& ts);
#endif // defined(ASIO_HAS_TIMERFD)
// The scheduler implementation used to post completions.
scheduler& scheduler_;
// Mutex to protect access to internal data.
mutex mutex_;
// The interrupter is used to break a blocking epoll_wait call.
select_interrupter interrupter_;
// The epoll file descriptor.
int epoll_fd_;
// The timer file descriptor.
int timer_fd_;
// The timer queues.
timer_queue_set timer_queues_;
// Whether the service has been shut down.
bool shutdown_;
// Mutex to protect access to the registered descriptors.
mutex registered_descriptors_mutex_;
// Keep track of all registered descriptors.
object_pool<descriptor_state> registered_descriptors_;
// Helper class to do post-perform_io cleanup.
struct perform_io_cleanup_on_block_exit;
friend struct perform_io_cleanup_on_block_exit;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#include "asio/detail/impl/epoll_reactor.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/epoll_reactor.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_EPOLL)
#endif // ASIO_DETAIL_EPOLL_REACTOR_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_socket_connect_op.hpp | //
// detail/win_iocp_socket_connect_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_SOCKET_CONNECT_OP_HPP
#define ASIO_DETAIL_WIN_IOCP_SOCKET_CONNECT_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class win_iocp_socket_connect_op_base : public reactor_op
{
public:
win_iocp_socket_connect_op_base(socket_type socket, func_type complete_func)
: reactor_op(asio::error_code(),
&win_iocp_socket_connect_op_base::do_perform, complete_func),
socket_(socket),
connect_ex_(false)
{
}
static status do_perform(reactor_op* base)
{
ASIO_ASSUME(base != 0);
win_iocp_socket_connect_op_base* o(
static_cast<win_iocp_socket_connect_op_base*>(base));
return socket_ops::non_blocking_connect(
o->socket_, o->ec_) ? done : not_done;
}
socket_type socket_;
bool connect_ex_;
};
template <typename Handler, typename IoExecutor>
class win_iocp_socket_connect_op : public win_iocp_socket_connect_op_base
{
public:
ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_connect_op);
win_iocp_socket_connect_op(socket_type socket,
Handler& handler, const IoExecutor& io_ex)
: win_iocp_socket_connect_op_base(socket,
&win_iocp_socket_connect_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t /*bytes_transferred*/)
{
asio::error_code ec(result_ec);
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
win_iocp_socket_connect_op* o(
static_cast<win_iocp_socket_connect_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
if (owner)
{
if (o->connect_ex_)
socket_ops::complete_iocp_connect(o->socket_, ec);
else
ec = o->ec_;
}
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(ec);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder1<Handler, asio::error_code>
handler(o->handler_, ec);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_SOCKET_CONNECT_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/winrt_resolver_service.hpp | //
// detail/winrt_resolver_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP
#define ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
#include "asio/ip/basic_resolver_query.hpp"
#include "asio/ip/basic_resolver_results.hpp"
#include "asio/post.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/winrt_async_manager.hpp"
#include "asio/detail/winrt_resolve_op.hpp"
#include "asio/detail/winrt_utils.hpp"
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/win_iocp_io_context.hpp"
#else // defined(ASIO_HAS_IOCP)
# include "asio/detail/scheduler.hpp"
#endif // defined(ASIO_HAS_IOCP)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Protocol>
class winrt_resolver_service :
public execution_context_service_base<winrt_resolver_service<Protocol>>
{
public:
// The implementation type of the resolver. A cancellation token is used to
// indicate to the asynchronous operation that the operation has been
// cancelled.
typedef socket_ops::shared_cancel_token_type implementation_type;
// The endpoint type.
typedef typename Protocol::endpoint endpoint_type;
// The query type.
typedef asio::ip::basic_resolver_query<Protocol> query_type;
// The results type.
typedef asio::ip::basic_resolver_results<Protocol> results_type;
// Constructor.
winrt_resolver_service(execution_context& context)
: execution_context_service_base<
winrt_resolver_service<Protocol>>(context),
scheduler_(use_service<scheduler_impl>(context)),
async_manager_(use_service<winrt_async_manager>(context))
{
}
// Destructor.
~winrt_resolver_service()
{
}
// Destroy all user-defined handler objects owned by the service.
void shutdown()
{
}
// Perform any fork-related housekeeping.
void notify_fork(execution_context::fork_event)
{
}
// Construct a new resolver implementation.
void construct(implementation_type&)
{
}
// Move-construct a new resolver implementation.
void move_construct(implementation_type&,
implementation_type&)
{
}
// Move-assign from another resolver implementation.
void move_assign(implementation_type&,
winrt_resolver_service&, implementation_type&)
{
}
// Destroy a resolver implementation.
void destroy(implementation_type&)
{
}
// Cancel pending asynchronous operations.
void cancel(implementation_type&)
{
}
// Resolve a query to a list of entries.
results_type resolve(implementation_type&,
const query_type& query, asio::error_code& ec)
{
try
{
using namespace Windows::Networking::Sockets;
auto endpoint_pairs = async_manager_.sync(
DatagramSocket::GetEndpointPairsAsync(
winrt_utils::host_name(query.host_name()),
winrt_utils::string(query.service_name())), ec);
if (ec)
return results_type();
return results_type::create(
endpoint_pairs, query.hints(),
query.host_name(), query.service_name());
}
catch (Platform::Exception^ e)
{
ec = asio::error_code(e->HResult,
asio::system_category());
return results_type();
}
}
// Asynchronously resolve a query to a list of entries.
template <typename Handler, typename IoExecutor>
void async_resolve(implementation_type& impl, const query_type& query,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
// Allocate and construct an operation to wrap the handler.
typedef winrt_resolve_op<Protocol, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(query, handler, io_ex);
ASIO_HANDLER_CREATION((scheduler_.context(),
*p.p, "resolver", &impl, 0, "async_resolve"));
(void)impl;
try
{
using namespace Windows::Networking::Sockets;
async_manager_.async(DatagramSocket::GetEndpointPairsAsync(
winrt_utils::host_name(query.host_name()),
winrt_utils::string(query.service_name())), p.p);
p.v = p.p = 0;
}
catch (Platform::Exception^ e)
{
p.p->ec_ = asio::error_code(
e->HResult, asio::system_category());
scheduler_.post_immediate_completion(p.p, is_continuation);
p.v = p.p = 0;
}
}
// Resolve an endpoint to a list of entries.
results_type resolve(implementation_type&,
const endpoint_type&, asio::error_code& ec)
{
ec = asio::error::operation_not_supported;
return results_type();
}
// Asynchronously resolve an endpoint to a list of entries.
template <typename Handler, typename IoExecutor>
void async_resolve(implementation_type&, const endpoint_type&,
Handler& handler, const IoExecutor& io_ex)
{
asio::error_code ec = asio::error::operation_not_supported;
const results_type results;
asio::post(io_ex, detail::bind_handler(handler, ec, results));
}
private:
// The scheduler implementation used for delivering completions.
#if defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context scheduler_impl;
#else
typedef class scheduler scheduler_impl;
#endif
scheduler_impl& scheduler_;
winrt_async_manager& async_manager_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_socket_recvmsg_op.hpp | //
// detail/win_iocp_socket_recvmsg_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_OP_HPP
#define ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/error.hpp"
#include "asio/socket_base.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename MutableBufferSequence, typename Handler, typename IoExecutor>
class win_iocp_socket_recvmsg_op : public operation
{
public:
ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recvmsg_op);
win_iocp_socket_recvmsg_op(
socket_ops::weak_cancel_token_type cancel_token,
const MutableBufferSequence& buffers,
socket_base::message_flags& out_flags,
Handler& handler, const IoExecutor& io_ex)
: operation(&win_iocp_socket_recvmsg_op::do_complete),
cancel_token_(cancel_token),
buffers_(buffers),
out_flags_(out_flags),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
asio::error_code ec(result_ec);
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
win_iocp_socket_recvmsg_op* o(
static_cast<win_iocp_socket_recvmsg_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
// Check whether buffers are still valid.
if (owner)
{
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::validate(o->buffers_);
}
#endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
socket_ops::complete_iocp_recvmsg(o->cancel_token_, ec);
o->out_flags_ = 0;
ASIO_ERROR_LOCATION(ec);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, ec, bytes_transferred);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
socket_ops::weak_cancel_token_type cancel_token_;
MutableBufferSequence buffers_;
socket_base::message_flags& out_flags_;
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/socket_types.hpp | //
// detail/socket_types.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SOCKET_TYPES_HPP
#define ASIO_DETAIL_SOCKET_TYPES_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
// Empty.
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
# if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
# error WinSock.h has already been included
# endif // defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
# if defined(__BORLANDC__)
# include <stdlib.h> // Needed for __errno
# if !defined(_WSPIAPI_H_)
# define _WSPIAPI_H_
# define ASIO_WSPIAPI_H_DEFINED
# endif // !defined(_WSPIAPI_H_)
# endif // defined(__BORLANDC__)
# include <winsock2.h>
# include <ws2tcpip.h>
# if defined(WINAPI_FAMILY)
# if ((WINAPI_FAMILY & WINAPI_PARTITION_DESKTOP) != 0)
# include <windows.h>
# endif // ((WINAPI_FAMILY & WINAPI_PARTITION_DESKTOP) != 0)
# endif // defined(WINAPI_FAMILY)
# if !defined(ASIO_WINDOWS_APP)
# include <mswsock.h>
# endif // !defined(ASIO_WINDOWS_APP)
# if defined(ASIO_WSPIAPI_H_DEFINED)
# undef _WSPIAPI_H_
# undef ASIO_WSPIAPI_H_DEFINED
# endif // defined(ASIO_WSPIAPI_H_DEFINED)
# if !defined(ASIO_NO_DEFAULT_LINKED_LIBS)
# if defined(UNDER_CE)
# pragma comment(lib, "ws2.lib")
# elif defined(_MSC_VER) || defined(__BORLANDC__)
# pragma comment(lib, "ws2_32.lib")
# if !defined(ASIO_WINDOWS_APP)
# pragma comment(lib, "mswsock.lib")
# endif // !defined(ASIO_WINDOWS_APP)
# endif // defined(_MSC_VER) || defined(__BORLANDC__)
# endif // !defined(ASIO_NO_DEFAULT_LINKED_LIBS)
# include "asio/detail/old_win_sdk_compat.hpp"
#else
# include <sys/ioctl.h>
# if (defined(__MACH__) && defined(__APPLE__)) \
|| defined(__FreeBSD__) || defined(__NetBSD__) \
|| defined(__OpenBSD__) || defined(__linux__) \
|| defined(__EMSCRIPTEN__)
# include <poll.h>
# elif !defined(__SYMBIAN32__)
# include <sys/poll.h>
# endif
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# if defined(__hpux)
# include <sys/time.h>
# endif
# if !defined(__hpux) || defined(__SELECT)
# include <sys/select.h>
# endif
# include <sys/socket.h>
# include <sys/uio.h>
# include <sys/un.h>
# include <netinet/in.h>
# if !defined(__SYMBIAN32__)
# include <netinet/tcp.h>
# endif
# include <arpa/inet.h>
# include <netdb.h>
# include <net/if.h>
# include <limits.h>
# if defined(__sun)
# include <sys/filio.h>
# include <sys/sockio.h>
# endif
# include <signal.h>
#endif
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
#if defined(ASIO_WINDOWS_RUNTIME)
const int max_addr_v4_str_len = 256;
const int max_addr_v6_str_len = 256;
typedef unsigned __int32 u_long_type;
typedef unsigned __int16 u_short_type;
struct in4_addr_type { u_long_type s_addr; };
struct in4_mreq_type { in4_addr_type imr_multiaddr, imr_interface; };
struct in6_addr_type { unsigned char s6_addr[16]; };
struct in6_mreq_type { in6_addr_type ipv6mr_multiaddr;
unsigned long ipv6mr_interface; };
struct socket_addr_type { int sa_family; };
struct sockaddr_in4_type { int sin_family;
in4_addr_type sin_addr; u_short_type sin_port; };
struct sockaddr_in6_type { int sin6_family;
in6_addr_type sin6_addr; u_short_type sin6_port;
u_long_type sin6_flowinfo; u_long_type sin6_scope_id; };
struct sockaddr_storage_type { int ss_family;
unsigned char ss_bytes[128 - sizeof(int)]; };
struct addrinfo_type { int ai_flags;
int ai_family, ai_socktype, ai_protocol;
int ai_addrlen; const void* ai_addr;
const char* ai_canonname; addrinfo_type* ai_next; };
struct linger_type { u_short_type l_onoff, l_linger; };
typedef u_long_type ioctl_arg_type;
typedef int signed_size_type;
# define ASIO_OS_DEF(c) ASIO_OS_DEF_##c
# define ASIO_OS_DEF_AF_UNSPEC 0
# define ASIO_OS_DEF_AF_INET 2
# define ASIO_OS_DEF_AF_INET6 23
# define ASIO_OS_DEF_SOCK_STREAM 1
# define ASIO_OS_DEF_SOCK_DGRAM 2
# define ASIO_OS_DEF_SOCK_RAW 3
# define ASIO_OS_DEF_SOCK_SEQPACKET 5
# define ASIO_OS_DEF_IPPROTO_IP 0
# define ASIO_OS_DEF_IPPROTO_IPV6 41
# define ASIO_OS_DEF_IPPROTO_TCP 6
# define ASIO_OS_DEF_IPPROTO_UDP 17
# define ASIO_OS_DEF_IPPROTO_ICMP 1
# define ASIO_OS_DEF_IPPROTO_ICMPV6 58
# define ASIO_OS_DEF_FIONBIO 1
# define ASIO_OS_DEF_FIONREAD 2
# define ASIO_OS_DEF_INADDR_ANY 0
# define ASIO_OS_DEF_MSG_OOB 0x1
# define ASIO_OS_DEF_MSG_PEEK 0x2
# define ASIO_OS_DEF_MSG_DONTROUTE 0x4
# define ASIO_OS_DEF_MSG_EOR 0 // Not supported.
# define ASIO_OS_DEF_SHUT_RD 0x0
# define ASIO_OS_DEF_SHUT_WR 0x1
# define ASIO_OS_DEF_SHUT_RDWR 0x2
# define ASIO_OS_DEF_SOMAXCONN 0x7fffffff
# define ASIO_OS_DEF_SOL_SOCKET 0xffff
# define ASIO_OS_DEF_SO_BROADCAST 0x20
# define ASIO_OS_DEF_SO_DEBUG 0x1
# define ASIO_OS_DEF_SO_DONTROUTE 0x10
# define ASIO_OS_DEF_SO_KEEPALIVE 0x8
# define ASIO_OS_DEF_SO_LINGER 0x80
# define ASIO_OS_DEF_SO_OOBINLINE 0x100
# define ASIO_OS_DEF_SO_SNDBUF 0x1001
# define ASIO_OS_DEF_SO_RCVBUF 0x1002
# define ASIO_OS_DEF_SO_SNDLOWAT 0x1003
# define ASIO_OS_DEF_SO_RCVLOWAT 0x1004
# define ASIO_OS_DEF_SO_REUSEADDR 0x4
# define ASIO_OS_DEF_TCP_NODELAY 0x1
# define ASIO_OS_DEF_IP_MULTICAST_IF 2
# define ASIO_OS_DEF_IP_MULTICAST_TTL 3
# define ASIO_OS_DEF_IP_MULTICAST_LOOP 4
# define ASIO_OS_DEF_IP_ADD_MEMBERSHIP 5
# define ASIO_OS_DEF_IP_DROP_MEMBERSHIP 6
# define ASIO_OS_DEF_IP_TTL 7
# define ASIO_OS_DEF_IPV6_UNICAST_HOPS 4
# define ASIO_OS_DEF_IPV6_MULTICAST_IF 9
# define ASIO_OS_DEF_IPV6_MULTICAST_HOPS 10
# define ASIO_OS_DEF_IPV6_MULTICAST_LOOP 11
# define ASIO_OS_DEF_IPV6_JOIN_GROUP 12
# define ASIO_OS_DEF_IPV6_LEAVE_GROUP 13
# define ASIO_OS_DEF_AI_CANONNAME 0x2
# define ASIO_OS_DEF_AI_PASSIVE 0x1
# define ASIO_OS_DEF_AI_NUMERICHOST 0x4
# define ASIO_OS_DEF_AI_NUMERICSERV 0x8
# define ASIO_OS_DEF_AI_V4MAPPED 0x800
# define ASIO_OS_DEF_AI_ALL 0x100
# define ASIO_OS_DEF_AI_ADDRCONFIG 0x400
# define ASIO_OS_DEF_SA_RESTART 0x1
# define ASIO_OS_DEF_SA_NOCLDSTOP 0x2
# define ASIO_OS_DEF_SA_NOCLDWAIT 0x4
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
typedef SOCKET socket_type;
const SOCKET invalid_socket = INVALID_SOCKET;
const int socket_error_retval = SOCKET_ERROR;
const int max_addr_v4_str_len = 256;
const int max_addr_v6_str_len = 256;
typedef sockaddr socket_addr_type;
typedef in_addr in4_addr_type;
typedef ip_mreq in4_mreq_type;
typedef sockaddr_in sockaddr_in4_type;
# if defined(ASIO_HAS_OLD_WIN_SDK)
typedef in6_addr_emulation in6_addr_type;
typedef ipv6_mreq_emulation in6_mreq_type;
typedef sockaddr_in6_emulation sockaddr_in6_type;
typedef sockaddr_storage_emulation sockaddr_storage_type;
typedef addrinfo_emulation addrinfo_type;
# else
typedef in6_addr in6_addr_type;
typedef ipv6_mreq in6_mreq_type;
typedef sockaddr_in6 sockaddr_in6_type;
typedef sockaddr_storage sockaddr_storage_type;
typedef addrinfo addrinfo_type;
# endif
typedef ::linger linger_type;
typedef unsigned long ioctl_arg_type;
typedef u_long u_long_type;
typedef u_short u_short_type;
typedef int signed_size_type;
struct sockaddr_un_type { u_short sun_family; char sun_path[108]; };
# define ASIO_OS_DEF(c) ASIO_OS_DEF_##c
# define ASIO_OS_DEF_AF_UNSPEC AF_UNSPEC
# define ASIO_OS_DEF_AF_INET AF_INET
# define ASIO_OS_DEF_AF_INET6 AF_INET6
# define ASIO_OS_DEF_SOCK_STREAM SOCK_STREAM
# define ASIO_OS_DEF_SOCK_DGRAM SOCK_DGRAM
# define ASIO_OS_DEF_SOCK_RAW SOCK_RAW
# define ASIO_OS_DEF_SOCK_SEQPACKET SOCK_SEQPACKET
# define ASIO_OS_DEF_IPPROTO_IP IPPROTO_IP
# define ASIO_OS_DEF_IPPROTO_IPV6 IPPROTO_IPV6
# define ASIO_OS_DEF_IPPROTO_TCP IPPROTO_TCP
# define ASIO_OS_DEF_IPPROTO_UDP IPPROTO_UDP
# define ASIO_OS_DEF_IPPROTO_ICMP IPPROTO_ICMP
# define ASIO_OS_DEF_IPPROTO_ICMPV6 IPPROTO_ICMPV6
# define ASIO_OS_DEF_FIONBIO FIONBIO
# define ASIO_OS_DEF_FIONREAD FIONREAD
# define ASIO_OS_DEF_INADDR_ANY INADDR_ANY
# define ASIO_OS_DEF_MSG_OOB MSG_OOB
# define ASIO_OS_DEF_MSG_PEEK MSG_PEEK
# define ASIO_OS_DEF_MSG_DONTROUTE MSG_DONTROUTE
# define ASIO_OS_DEF_MSG_EOR 0 // Not supported on Windows.
# define ASIO_OS_DEF_SHUT_RD SD_RECEIVE
# define ASIO_OS_DEF_SHUT_WR SD_SEND
# define ASIO_OS_DEF_SHUT_RDWR SD_BOTH
# define ASIO_OS_DEF_SOMAXCONN SOMAXCONN
# define ASIO_OS_DEF_SOL_SOCKET SOL_SOCKET
# define ASIO_OS_DEF_SO_BROADCAST SO_BROADCAST
# define ASIO_OS_DEF_SO_DEBUG SO_DEBUG
# define ASIO_OS_DEF_SO_DONTROUTE SO_DONTROUTE
# define ASIO_OS_DEF_SO_KEEPALIVE SO_KEEPALIVE
# define ASIO_OS_DEF_SO_LINGER SO_LINGER
# define ASIO_OS_DEF_SO_OOBINLINE SO_OOBINLINE
# define ASIO_OS_DEF_SO_SNDBUF SO_SNDBUF
# define ASIO_OS_DEF_SO_RCVBUF SO_RCVBUF
# define ASIO_OS_DEF_SO_SNDLOWAT SO_SNDLOWAT
# define ASIO_OS_DEF_SO_RCVLOWAT SO_RCVLOWAT
# define ASIO_OS_DEF_SO_REUSEADDR SO_REUSEADDR
# define ASIO_OS_DEF_TCP_NODELAY TCP_NODELAY
# define ASIO_OS_DEF_IP_MULTICAST_IF IP_MULTICAST_IF
# define ASIO_OS_DEF_IP_MULTICAST_TTL IP_MULTICAST_TTL
# define ASIO_OS_DEF_IP_MULTICAST_LOOP IP_MULTICAST_LOOP
# define ASIO_OS_DEF_IP_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
# define ASIO_OS_DEF_IP_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP
# define ASIO_OS_DEF_IP_TTL IP_TTL
# define ASIO_OS_DEF_IPV6_UNICAST_HOPS IPV6_UNICAST_HOPS
# define ASIO_OS_DEF_IPV6_MULTICAST_IF IPV6_MULTICAST_IF
# define ASIO_OS_DEF_IPV6_MULTICAST_HOPS IPV6_MULTICAST_HOPS
# define ASIO_OS_DEF_IPV6_MULTICAST_LOOP IPV6_MULTICAST_LOOP
# define ASIO_OS_DEF_IPV6_JOIN_GROUP IPV6_JOIN_GROUP
# define ASIO_OS_DEF_IPV6_LEAVE_GROUP IPV6_LEAVE_GROUP
# define ASIO_OS_DEF_AI_CANONNAME AI_CANONNAME
# define ASIO_OS_DEF_AI_PASSIVE AI_PASSIVE
# define ASIO_OS_DEF_AI_NUMERICHOST AI_NUMERICHOST
# if defined(AI_NUMERICSERV)
# define ASIO_OS_DEF_AI_NUMERICSERV AI_NUMERICSERV
# else
# define ASIO_OS_DEF_AI_NUMERICSERV 0
# endif
# if defined(AI_V4MAPPED)
# define ASIO_OS_DEF_AI_V4MAPPED AI_V4MAPPED
# else
# define ASIO_OS_DEF_AI_V4MAPPED 0
# endif
# if defined(AI_ALL)
# define ASIO_OS_DEF_AI_ALL AI_ALL
# else
# define ASIO_OS_DEF_AI_ALL 0
# endif
# if defined(AI_ADDRCONFIG)
# define ASIO_OS_DEF_AI_ADDRCONFIG AI_ADDRCONFIG
# else
# define ASIO_OS_DEF_AI_ADDRCONFIG 0
# endif
# if defined (_WIN32_WINNT)
const int max_iov_len = 64;
# else
const int max_iov_len = 16;
# endif
# define ASIO_OS_DEF_SA_RESTART 0x1
# define ASIO_OS_DEF_SA_NOCLDSTOP 0x2
# define ASIO_OS_DEF_SA_NOCLDWAIT 0x4
#else
typedef int socket_type;
const int invalid_socket = -1;
const int socket_error_retval = -1;
const int max_addr_v4_str_len = INET_ADDRSTRLEN;
#if defined(INET6_ADDRSTRLEN)
const int max_addr_v6_str_len = INET6_ADDRSTRLEN + 1 + IF_NAMESIZE;
#else // defined(INET6_ADDRSTRLEN)
const int max_addr_v6_str_len = 256;
#endif // defined(INET6_ADDRSTRLEN)
typedef sockaddr socket_addr_type;
typedef in_addr in4_addr_type;
# if defined(__hpux)
// HP-UX doesn't provide ip_mreq when _XOPEN_SOURCE_EXTENDED is defined.
struct in4_mreq_type
{
struct in_addr imr_multiaddr;
struct in_addr imr_interface;
};
# else
typedef ip_mreq in4_mreq_type;
# endif
typedef sockaddr_in sockaddr_in4_type;
typedef in6_addr in6_addr_type;
typedef ipv6_mreq in6_mreq_type;
typedef sockaddr_in6 sockaddr_in6_type;
typedef sockaddr_storage sockaddr_storage_type;
typedef sockaddr_un sockaddr_un_type;
typedef addrinfo addrinfo_type;
typedef ::linger linger_type;
typedef int ioctl_arg_type;
typedef uint32_t u_long_type;
typedef uint16_t u_short_type;
#if defined(ASIO_HAS_SSIZE_T)
typedef ssize_t signed_size_type;
#else // defined(ASIO_HAS_SSIZE_T)
typedef int signed_size_type;
#endif // defined(ASIO_HAS_SSIZE_T)
# define ASIO_OS_DEF(c) ASIO_OS_DEF_##c
# define ASIO_OS_DEF_AF_UNSPEC AF_UNSPEC
# define ASIO_OS_DEF_AF_INET AF_INET
# define ASIO_OS_DEF_AF_INET6 AF_INET6
# define ASIO_OS_DEF_SOCK_STREAM SOCK_STREAM
# define ASIO_OS_DEF_SOCK_DGRAM SOCK_DGRAM
# define ASIO_OS_DEF_SOCK_RAW SOCK_RAW
# define ASIO_OS_DEF_SOCK_SEQPACKET SOCK_SEQPACKET
# define ASIO_OS_DEF_IPPROTO_IP IPPROTO_IP
# define ASIO_OS_DEF_IPPROTO_IPV6 IPPROTO_IPV6
# define ASIO_OS_DEF_IPPROTO_TCP IPPROTO_TCP
# define ASIO_OS_DEF_IPPROTO_UDP IPPROTO_UDP
# define ASIO_OS_DEF_IPPROTO_ICMP IPPROTO_ICMP
# define ASIO_OS_DEF_IPPROTO_ICMPV6 IPPROTO_ICMPV6
# define ASIO_OS_DEF_FIONBIO FIONBIO
# define ASIO_OS_DEF_FIONREAD FIONREAD
# define ASIO_OS_DEF_INADDR_ANY INADDR_ANY
# define ASIO_OS_DEF_MSG_OOB MSG_OOB
# define ASIO_OS_DEF_MSG_PEEK MSG_PEEK
# define ASIO_OS_DEF_MSG_DONTROUTE MSG_DONTROUTE
# define ASIO_OS_DEF_MSG_EOR MSG_EOR
# define ASIO_OS_DEF_SHUT_RD SHUT_RD
# define ASIO_OS_DEF_SHUT_WR SHUT_WR
# define ASIO_OS_DEF_SHUT_RDWR SHUT_RDWR
# define ASIO_OS_DEF_SOMAXCONN SOMAXCONN
# define ASIO_OS_DEF_SOL_SOCKET SOL_SOCKET
# define ASIO_OS_DEF_SO_BROADCAST SO_BROADCAST
# define ASIO_OS_DEF_SO_DEBUG SO_DEBUG
# define ASIO_OS_DEF_SO_DONTROUTE SO_DONTROUTE
# define ASIO_OS_DEF_SO_KEEPALIVE SO_KEEPALIVE
# define ASIO_OS_DEF_SO_LINGER SO_LINGER
# define ASIO_OS_DEF_SO_OOBINLINE SO_OOBINLINE
# define ASIO_OS_DEF_SO_SNDBUF SO_SNDBUF
# define ASIO_OS_DEF_SO_RCVBUF SO_RCVBUF
# define ASIO_OS_DEF_SO_SNDLOWAT SO_SNDLOWAT
# define ASIO_OS_DEF_SO_RCVLOWAT SO_RCVLOWAT
# define ASIO_OS_DEF_SO_REUSEADDR SO_REUSEADDR
# define ASIO_OS_DEF_TCP_NODELAY TCP_NODELAY
# define ASIO_OS_DEF_IP_MULTICAST_IF IP_MULTICAST_IF
# define ASIO_OS_DEF_IP_MULTICAST_TTL IP_MULTICAST_TTL
# define ASIO_OS_DEF_IP_MULTICAST_LOOP IP_MULTICAST_LOOP
# define ASIO_OS_DEF_IP_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
# define ASIO_OS_DEF_IP_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP
# define ASIO_OS_DEF_IP_TTL IP_TTL
# define ASIO_OS_DEF_IPV6_UNICAST_HOPS IPV6_UNICAST_HOPS
# define ASIO_OS_DEF_IPV6_MULTICAST_IF IPV6_MULTICAST_IF
# define ASIO_OS_DEF_IPV6_MULTICAST_HOPS IPV6_MULTICAST_HOPS
# define ASIO_OS_DEF_IPV6_MULTICAST_LOOP IPV6_MULTICAST_LOOP
# define ASIO_OS_DEF_IPV6_JOIN_GROUP IPV6_JOIN_GROUP
# define ASIO_OS_DEF_IPV6_LEAVE_GROUP IPV6_LEAVE_GROUP
# define ASIO_OS_DEF_AI_CANONNAME AI_CANONNAME
# define ASIO_OS_DEF_AI_PASSIVE AI_PASSIVE
# define ASIO_OS_DEF_AI_NUMERICHOST AI_NUMERICHOST
# if defined(AI_NUMERICSERV)
# define ASIO_OS_DEF_AI_NUMERICSERV AI_NUMERICSERV
# else
# define ASIO_OS_DEF_AI_NUMERICSERV 0
# endif
// Note: QNX Neutrino 6.3 defines AI_V4MAPPED, AI_ALL and AI_ADDRCONFIG but
// does not implement them. Therefore they are specifically excluded here.
# if defined(AI_V4MAPPED) && !defined(__QNXNTO__)
# define ASIO_OS_DEF_AI_V4MAPPED AI_V4MAPPED
# else
# define ASIO_OS_DEF_AI_V4MAPPED 0
# endif
# if defined(AI_ALL) && !defined(__QNXNTO__)
# define ASIO_OS_DEF_AI_ALL AI_ALL
# else
# define ASIO_OS_DEF_AI_ALL 0
# endif
# if defined(AI_ADDRCONFIG) && !defined(__QNXNTO__)
# define ASIO_OS_DEF_AI_ADDRCONFIG AI_ADDRCONFIG
# else
# define ASIO_OS_DEF_AI_ADDRCONFIG 0
# endif
# if defined(IOV_MAX)
const int max_iov_len = IOV_MAX;
# else
// POSIX platforms are not required to define IOV_MAX.
const int max_iov_len = 16;
# endif
# define ASIO_OS_DEF_SA_RESTART SA_RESTART
# define ASIO_OS_DEF_SA_NOCLDSTOP SA_NOCLDSTOP
# define ASIO_OS_DEF_SA_NOCLDWAIT SA_NOCLDWAIT
#endif
const int custom_socket_option_level = 0xA5100000;
const int enable_connection_aborted_option = 1;
const int always_fail_option = 2;
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_SOCKET_TYPES_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/wince_thread.hpp | //
// detail/wince_thread.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WINCE_THREAD_HPP
#define ASIO_DETAIL_WINCE_THREAD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS) && defined(UNDER_CE)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/scoped_ptr.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
DWORD WINAPI wince_thread_function(LPVOID arg);
class wince_thread
: private noncopyable
{
public:
// Constructor.
template <typename Function>
wince_thread(Function f, unsigned int = 0)
{
scoped_ptr<func_base> arg(new func<Function>(f));
DWORD thread_id = 0;
thread_ = ::CreateThread(0, 0, wince_thread_function,
arg.get(), 0, &thread_id);
if (!thread_)
{
DWORD last_error = ::GetLastError();
asio::error_code ec(last_error,
asio::error::get_system_category());
asio::detail::throw_error(ec, "thread");
}
arg.release();
}
// Destructor.
~wince_thread()
{
::CloseHandle(thread_);
}
// Wait for the thread to exit.
void join()
{
::WaitForSingleObject(thread_, INFINITE);
}
// Get number of CPUs.
static std::size_t hardware_concurrency()
{
SYSTEM_INFO system_info;
::GetSystemInfo(&system_info);
return system_info.dwNumberOfProcessors;
}
private:
friend DWORD WINAPI wince_thread_function(LPVOID arg);
class func_base
{
public:
virtual ~func_base() {}
virtual void run() = 0;
};
template <typename Function>
class func
: public func_base
{
public:
func(Function f)
: f_(f)
{
}
virtual void run()
{
f_();
}
private:
Function f_;
};
::HANDLE thread_;
};
inline DWORD WINAPI wince_thread_function(LPVOID arg)
{
scoped_ptr<wince_thread::func_base> func(
static_cast<wince_thread::func_base*>(arg));
func->run();
return 0;
}
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_WINDOWS) && defined(UNDER_CE)
#endif // ASIO_DETAIL_WINCE_THREAD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_descriptor_write_op.hpp | //
// detail/io_uring_descriptor_write_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_DESCRIPTOR_WRITE_OP_HPP
#define ASIO_DETAIL_IO_URING_DESCRIPTOR_WRITE_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/descriptor_ops.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename ConstBufferSequence>
class io_uring_descriptor_write_op_base : public io_uring_operation
{
public:
io_uring_descriptor_write_op_base(const asio::error_code& success_ec,
int descriptor, descriptor_ops::state_type state,
const ConstBufferSequence& buffers, func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_descriptor_write_op_base::do_prepare,
&io_uring_descriptor_write_op_base::do_perform, complete_func),
descriptor_(descriptor),
state_(state),
buffers_(buffers),
bufs_(buffers)
{
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_descriptor_write_op_base* o(
static_cast<io_uring_descriptor_write_op_base*>(base));
if ((o->state_ & descriptor_ops::internal_non_blocking) != 0)
{
::io_uring_prep_poll_add(sqe, o->descriptor_, POLLOUT);
}
else if (o->bufs_.is_single_buffer && o->bufs_.is_registered_buffer)
{
::io_uring_prep_write_fixed(sqe, o->descriptor_,
o->bufs_.buffers()->iov_base, o->bufs_.buffers()->iov_len,
0, o->bufs_.registered_id().native_handle());
}
else
{
::io_uring_prep_writev(sqe, o->descriptor_,
o->bufs_.buffers(), o->bufs_.count(), -1);
}
}
static bool do_perform(io_uring_operation* base, bool after_completion)
{
ASIO_ASSUME(base != 0);
io_uring_descriptor_write_op_base* o(
static_cast<io_uring_descriptor_write_op_base*>(base));
if ((o->state_ & descriptor_ops::internal_non_blocking) != 0)
{
if (o->bufs_.is_single_buffer)
{
return descriptor_ops::non_blocking_write1(
o->descriptor_, o->bufs_.first(o->buffers_).data(),
o->bufs_.first(o->buffers_).size(), o->ec_,
o->bytes_transferred_);
}
else
{
return descriptor_ops::non_blocking_write(
o->descriptor_, o->bufs_.buffers(), o->bufs_.count(),
o->ec_, o->bytes_transferred_);
}
}
if (o->ec_ && o->ec_ == asio::error::would_block)
{
o->state_ |= descriptor_ops::internal_non_blocking;
return false;
}
return after_completion;
}
private:
int descriptor_;
descriptor_ops::state_type state_;
ConstBufferSequence buffers_;
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs_;
};
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
class io_uring_descriptor_write_op
: public io_uring_descriptor_write_op_base<ConstBufferSequence>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_descriptor_write_op);
io_uring_descriptor_write_op(const asio::error_code& success_ec,
int descriptor, descriptor_ops::state_type state,
const ConstBufferSequence& buffers, Handler& handler,
const IoExecutor& io_ex)
: io_uring_descriptor_write_op_base<ConstBufferSequence>(success_ec,
descriptor, state, buffers, &io_uring_descriptor_write_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_descriptor_write_op* o
(static_cast<io_uring_descriptor_write_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_DESCRIPTOR_WRITE_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/select_reactor.hpp | //
// detail/select_reactor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SELECT_REACTOR_HPP
#define ASIO_DETAIL_SELECT_REACTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP) \
|| (!defined(ASIO_HAS_DEV_POLL) \
&& !defined(ASIO_HAS_EPOLL) \
&& !defined(ASIO_HAS_KQUEUE) \
&& !defined(ASIO_WINDOWS_RUNTIME))
#include <cstddef>
#include "asio/detail/fd_set_adapter.hpp"
#include "asio/detail/limits.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/reactor_op_queue.hpp"
#include "asio/detail/scheduler_task.hpp"
#include "asio/detail/select_interrupter.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/timer_queue_base.hpp"
#include "asio/detail/timer_queue_set.hpp"
#include "asio/detail/wait_op.hpp"
#include "asio/execution_context.hpp"
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/thread.hpp"
#endif // defined(ASIO_HAS_IOCP)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class select_reactor
: public execution_context_service_base<select_reactor>
#if !defined(ASIO_HAS_IOCP)
, public scheduler_task
#endif // !defined(ASIO_HAS_IOCP)
{
public:
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
enum op_types { read_op = 0, write_op = 1, except_op = 2,
max_select_ops = 3, connect_op = 3, max_ops = 4 };
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
enum op_types { read_op = 0, write_op = 1, except_op = 2,
max_select_ops = 3, connect_op = 1, max_ops = 3 };
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
// Per-descriptor data.
struct per_descriptor_data
{
};
// Constructor.
ASIO_DECL select_reactor(asio::execution_context& ctx);
// Destructor.
ASIO_DECL ~select_reactor();
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Recreate internal descriptors following a fork.
ASIO_DECL void notify_fork(
asio::execution_context::fork_event fork_ev);
// Initialise the task, but only if the reactor is not in its own thread.
ASIO_DECL void init_task();
// Register a socket with the reactor. Returns 0 on success, system error
// code on failure.
ASIO_DECL int register_descriptor(socket_type, per_descriptor_data&);
// Register a descriptor with an associated single operation. Returns 0 on
// success, system error code on failure.
ASIO_DECL int register_internal_descriptor(
int op_type, socket_type descriptor,
per_descriptor_data& descriptor_data, reactor_op* op);
// Post a reactor operation for immediate completion.
void post_immediate_completion(operation* op, bool is_continuation) const;
// Post a reactor operation for immediate completion.
ASIO_DECL static void call_post_immediate_completion(
operation* op, bool is_continuation, const void* self);
// Start a new operation. The reactor operation will be performed when the
// given descriptor is flagged as ready, or an error has occurred.
ASIO_DECL void start_op(int op_type, socket_type descriptor,
per_descriptor_data&, reactor_op* op, bool is_continuation, bool,
void (*on_immediate)(operation*, bool, const void*),
const void* immediate_arg);
// Start a new operation. The reactor operation will be performed when the
// given descriptor is flagged as ready, or an error has occurred.
void start_op(int op_type, socket_type descriptor,
per_descriptor_data& descriptor_data, reactor_op* op,
bool is_continuation, bool allow_speculative)
{
start_op(op_type, descriptor, descriptor_data,
op, is_continuation, allow_speculative,
&select_reactor::call_post_immediate_completion, this);
}
// Cancel all operations associated with the given descriptor. The
// handlers associated with the descriptor will be invoked with the
// operation_aborted error.
ASIO_DECL void cancel_ops(socket_type descriptor, per_descriptor_data&);
// Cancel all operations associated with the given descriptor and key. The
// handlers associated with the descriptor will be invoked with the
// operation_aborted error.
ASIO_DECL void cancel_ops_by_key(socket_type descriptor,
per_descriptor_data& descriptor_data,
int op_type, void* cancellation_key);
// Cancel any operations that are running against the descriptor and remove
// its registration from the reactor. The reactor resources associated with
// the descriptor must be released by calling cleanup_descriptor_data.
ASIO_DECL void deregister_descriptor(socket_type descriptor,
per_descriptor_data&, bool closing);
// Remove the descriptor's registration from the reactor. The reactor
// resources associated with the descriptor must be released by calling
// cleanup_descriptor_data.
ASIO_DECL void deregister_internal_descriptor(
socket_type descriptor, per_descriptor_data&);
// Perform any post-deregistration cleanup tasks associated with the
// descriptor data.
ASIO_DECL void cleanup_descriptor_data(per_descriptor_data&);
// Move descriptor registration from one descriptor_data object to another.
ASIO_DECL void move_descriptor(socket_type descriptor,
per_descriptor_data& target_descriptor_data,
per_descriptor_data& source_descriptor_data);
// Add a new timer queue to the reactor.
template <typename Time_Traits>
void add_timer_queue(timer_queue<Time_Traits>& queue);
// Remove a timer queue from the reactor.
template <typename Time_Traits>
void remove_timer_queue(timer_queue<Time_Traits>& queue);
// Schedule a new operation in the given timer queue to expire at the
// specified absolute time.
template <typename Time_Traits>
void schedule_timer(timer_queue<Time_Traits>& queue,
const typename Time_Traits::time_type& time,
typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
// Cancel the timer operations associated with the given token. Returns the
// number of operations that have been posted or dispatched.
template <typename Time_Traits>
std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& timer,
std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
// Cancel the timer operations associated with the given key.
template <typename Time_Traits>
void cancel_timer_by_key(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data* timer,
void* cancellation_key);
// Move the timer operations associated with the given timer.
template <typename Time_Traits>
void move_timer(timer_queue<Time_Traits>& queue,
typename timer_queue<Time_Traits>::per_timer_data& target,
typename timer_queue<Time_Traits>::per_timer_data& source);
// Run select once until interrupted or events are ready to be dispatched.
ASIO_DECL void run(long usec, op_queue<operation>& ops);
// Interrupt the select loop.
ASIO_DECL void interrupt();
private:
#if defined(ASIO_HAS_IOCP)
// Run the select loop in the thread.
ASIO_DECL void run_thread();
#endif // defined(ASIO_HAS_IOCP)
// Helper function to add a new timer queue.
ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
// Helper function to remove a timer queue.
ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
// Get the timeout value for the select call.
ASIO_DECL timeval* get_timeout(long usec, timeval& tv);
// Cancel all operations associated with the given descriptor. This function
// does not acquire the select_reactor's mutex.
ASIO_DECL void cancel_ops_unlocked(socket_type descriptor,
const asio::error_code& ec);
// The scheduler implementation used to post completions.
# if defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context scheduler_type;
# else // defined(ASIO_HAS_IOCP)
typedef class scheduler scheduler_type;
# endif // defined(ASIO_HAS_IOCP)
scheduler_type& scheduler_;
// Mutex to protect access to internal data.
asio::detail::mutex mutex_;
// The interrupter is used to break a blocking select call.
select_interrupter interrupter_;
// The queues of read, write and except operations.
reactor_op_queue<socket_type> op_queue_[max_ops];
// The file descriptor sets to be passed to the select system call.
fd_set_adapter fd_sets_[max_select_ops];
// The timer queues.
timer_queue_set timer_queues_;
#if defined(ASIO_HAS_IOCP)
// Helper class to run the reactor loop in a thread.
class thread_function;
friend class thread_function;
// Does the reactor loop thread need to stop.
bool stop_thread_;
// The thread that is running the reactor loop.
asio::detail::thread* thread_;
// Helper class to join and restart the reactor thread.
class restart_reactor : public operation
{
public:
restart_reactor(select_reactor* r)
: operation(&restart_reactor::do_complete),
reactor_(r)
{
}
ASIO_DECL static void do_complete(void* owner, operation* base,
const asio::error_code& ec, std::size_t bytes_transferred);
private:
select_reactor* reactor_;
};
friend class restart_reactor;
// Operation used to join and restart the reactor thread.
restart_reactor restart_reactor_;
#endif // defined(ASIO_HAS_IOCP)
// Whether the service has been shut down.
bool shutdown_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#include "asio/detail/impl/select_reactor.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/select_reactor.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_IOCP)
// || (!defined(ASIO_HAS_DEV_POLL)
// && !defined(ASIO_HAS_EPOLL)
// && !defined(ASIO_HAS_KQUEUE)
// && !defined(ASIO_WINDOWS_RUNTIME))
#endif // ASIO_DETAIL_SELECT_REACTOR_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/null_mutex.hpp | //
// detail/null_mutex.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_NULL_MUTEX_HPP
#define ASIO_DETAIL_NULL_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class null_mutex
: private noncopyable
{
public:
typedef asio::detail::scoped_lock<null_mutex> scoped_lock;
// Constructor.
null_mutex()
{
}
// Destructor.
~null_mutex()
{
}
// Lock the mutex.
void lock()
{
}
// Unlock the mutex.
void unlock()
{
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_NULL_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_mutex.hpp | //
// detail/win_mutex.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_MUTEX_HPP
#define ASIO_DETAIL_WIN_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class win_mutex
: private noncopyable
{
public:
typedef asio::detail::scoped_lock<win_mutex> scoped_lock;
// Constructor.
ASIO_DECL win_mutex();
// Destructor.
~win_mutex()
{
::DeleteCriticalSection(&crit_section_);
}
// Lock the mutex.
void lock()
{
::EnterCriticalSection(&crit_section_);
}
// Unlock the mutex.
void unlock()
{
::LeaveCriticalSection(&crit_section_);
}
private:
// Initialisation must be performed in a separate function to the constructor
// since the compiler does not support the use of structured exceptions and
// C++ exceptions in the same function.
ASIO_DECL int do_init();
::CRITICAL_SECTION crit_section_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_mutex.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS)
#endif // ASIO_DETAIL_WIN_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/call_stack.hpp | //
// detail/call_stack.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_CALL_STACK_HPP
#define ASIO_DETAIL_CALL_STACK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/tss_ptr.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Helper class to determine whether or not the current thread is inside an
// invocation of io_context::run() for a specified io_context object.
template <typename Key, typename Value = unsigned char>
class call_stack
{
public:
// Context class automatically pushes the key/value pair on to the stack.
class context
: private noncopyable
{
public:
// Push the key on to the stack.
explicit context(Key* k)
: key_(k),
next_(call_stack<Key, Value>::top_)
{
value_ = reinterpret_cast<unsigned char*>(this);
call_stack<Key, Value>::top_ = this;
}
// Push the key/value pair on to the stack.
context(Key* k, Value& v)
: key_(k),
value_(&v),
next_(call_stack<Key, Value>::top_)
{
call_stack<Key, Value>::top_ = this;
}
// Pop the key/value pair from the stack.
~context()
{
call_stack<Key, Value>::top_ = next_;
}
// Find the next context with the same key.
Value* next_by_key() const
{
context* elem = next_;
while (elem)
{
if (elem->key_ == key_)
return elem->value_;
elem = elem->next_;
}
return 0;
}
private:
friend class call_stack<Key, Value>;
// The key associated with the context.
Key* key_;
// The value associated with the context.
Value* value_;
// The next element in the stack.
context* next_;
};
friend class context;
// Determine whether the specified owner is on the stack. Returns address of
// key if present, 0 otherwise.
static Value* contains(Key* k)
{
context* elem = top_;
while (elem)
{
if (elem->key_ == k)
return elem->value_;
elem = elem->next_;
}
return 0;
}
// Obtain the value at the top of the stack.
static Value* top()
{
context* elem = top_;
return elem ? elem->value_ : 0;
}
private:
// The top of the stack of calls for the current thread.
static tss_ptr<context> top_;
};
template <typename Key, typename Value>
tss_ptr<typename call_stack<Key, Value>::context>
call_stack<Key, Value>::top_;
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_CALL_STACK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/deadline_timer_service.hpp | //
// detail/deadline_timer_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
#define ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <cstddef>
#include "asio/associated_cancellation_slot.hpp"
#include "asio/cancellation_type.hpp"
#include "asio/error.hpp"
#include "asio/execution_context.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/timer_queue.hpp"
#include "asio/detail/timer_queue_ptime.hpp"
#include "asio/detail/timer_scheduler.hpp"
#include "asio/detail/wait_handler.hpp"
#include "asio/detail/wait_op.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
# include <chrono>
# include <thread>
#endif // defined(ASIO_WINDOWS_RUNTIME)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Time_Traits>
class deadline_timer_service
: public execution_context_service_base<deadline_timer_service<Time_Traits>>
{
public:
// The time type.
typedef typename Time_Traits::time_type time_type;
// The duration type.
typedef typename Time_Traits::duration_type duration_type;
// The implementation type of the timer. This type is dependent on the
// underlying implementation of the timer service.
struct implementation_type
: private asio::detail::noncopyable
{
time_type expiry;
bool might_have_pending_waits;
typename timer_queue<Time_Traits>::per_timer_data timer_data;
};
// Constructor.
deadline_timer_service(execution_context& context)
: execution_context_service_base<
deadline_timer_service<Time_Traits>>(context),
scheduler_(asio::use_service<timer_scheduler>(context))
{
scheduler_.init_task();
scheduler_.add_timer_queue(timer_queue_);
}
// Destructor.
~deadline_timer_service()
{
scheduler_.remove_timer_queue(timer_queue_);
}
// Destroy all user-defined handler objects owned by the service.
void shutdown()
{
}
// Construct a new timer implementation.
void construct(implementation_type& impl)
{
impl.expiry = time_type();
impl.might_have_pending_waits = false;
}
// Destroy a timer implementation.
void destroy(implementation_type& impl)
{
asio::error_code ec;
cancel(impl, ec);
}
// Move-construct a new timer implementation.
void move_construct(implementation_type& impl,
implementation_type& other_impl)
{
if (other_impl.might_have_pending_waits)
{
scheduler_.move_timer(timer_queue_,
impl.timer_data, other_impl.timer_data);
}
impl.expiry = other_impl.expiry;
other_impl.expiry = time_type();
impl.might_have_pending_waits = other_impl.might_have_pending_waits;
other_impl.might_have_pending_waits = false;
}
// Move-assign from another timer implementation.
void move_assign(implementation_type& impl,
deadline_timer_service& other_service,
implementation_type& other_impl)
{
if (this != &other_service)
if (impl.might_have_pending_waits)
scheduler_.cancel_timer(timer_queue_, impl.timer_data);
other_service.scheduler_.move_timer(other_service.timer_queue_,
impl.timer_data, other_impl.timer_data);
impl.expiry = other_impl.expiry;
other_impl.expiry = time_type();
impl.might_have_pending_waits = other_impl.might_have_pending_waits;
other_impl.might_have_pending_waits = false;
}
// Move-construct a new timer implementation.
void converting_move_construct(implementation_type& impl,
deadline_timer_service&, implementation_type& other_impl)
{
move_construct(impl, other_impl);
}
// Move-assign from another timer implementation.
void converting_move_assign(implementation_type& impl,
deadline_timer_service& other_service,
implementation_type& other_impl)
{
move_assign(impl, other_service, other_impl);
}
// Cancel any asynchronous wait operations associated with the timer.
std::size_t cancel(implementation_type& impl, asio::error_code& ec)
{
if (!impl.might_have_pending_waits)
{
ec = asio::error_code();
return 0;
}
ASIO_HANDLER_OPERATION((scheduler_.context(),
"deadline_timer", &impl, 0, "cancel"));
std::size_t count = scheduler_.cancel_timer(timer_queue_, impl.timer_data);
impl.might_have_pending_waits = false;
ec = asio::error_code();
return count;
}
// Cancels one asynchronous wait operation associated with the timer.
std::size_t cancel_one(implementation_type& impl,
asio::error_code& ec)
{
if (!impl.might_have_pending_waits)
{
ec = asio::error_code();
return 0;
}
ASIO_HANDLER_OPERATION((scheduler_.context(),
"deadline_timer", &impl, 0, "cancel_one"));
std::size_t count = scheduler_.cancel_timer(
timer_queue_, impl.timer_data, 1);
if (count == 0)
impl.might_have_pending_waits = false;
ec = asio::error_code();
return count;
}
// Get the expiry time for the timer as an absolute time.
time_type expiry(const implementation_type& impl) const
{
return impl.expiry;
}
// Get the expiry time for the timer as an absolute time.
time_type expires_at(const implementation_type& impl) const
{
return impl.expiry;
}
// Get the expiry time for the timer relative to now.
duration_type expires_from_now(const implementation_type& impl) const
{
return Time_Traits::subtract(this->expiry(impl), Time_Traits::now());
}
// Set the expiry time for the timer as an absolute time.
std::size_t expires_at(implementation_type& impl,
const time_type& expiry_time, asio::error_code& ec)
{
std::size_t count = cancel(impl, ec);
impl.expiry = expiry_time;
ec = asio::error_code();
return count;
}
// Set the expiry time for the timer relative to now.
std::size_t expires_after(implementation_type& impl,
const duration_type& expiry_time, asio::error_code& ec)
{
return expires_at(impl,
Time_Traits::add(Time_Traits::now(), expiry_time), ec);
}
// Set the expiry time for the timer relative to now.
std::size_t expires_from_now(implementation_type& impl,
const duration_type& expiry_time, asio::error_code& ec)
{
return expires_at(impl,
Time_Traits::add(Time_Traits::now(), expiry_time), ec);
}
// Perform a blocking wait on the timer.
void wait(implementation_type& impl, asio::error_code& ec)
{
time_type now = Time_Traits::now();
ec = asio::error_code();
while (Time_Traits::less_than(now, impl.expiry) && !ec)
{
this->do_wait(Time_Traits::to_posix_duration(
Time_Traits::subtract(impl.expiry, now)), ec);
now = Time_Traits::now();
}
}
// Start an asynchronous wait on the timer.
template <typename Handler, typename IoExecutor>
void async_wait(implementation_type& impl,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef wait_handler<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<op_cancellation>(this, &impl.timer_data);
}
impl.might_have_pending_waits = true;
ASIO_HANDLER_CREATION((scheduler_.context(),
*p.p, "deadline_timer", &impl, 0, "async_wait"));
scheduler_.schedule_timer(timer_queue_, impl.expiry, impl.timer_data, p.p);
p.v = p.p = 0;
}
private:
// Helper function to wait given a duration type. The duration type should
// either be of type boost::posix_time::time_duration, or implement the
// required subset of its interface.
template <typename Duration>
void do_wait(const Duration& timeout, asio::error_code& ec)
{
#if defined(ASIO_WINDOWS_RUNTIME)
std::this_thread::sleep_for(
std::chrono::seconds(timeout.total_seconds())
+ std::chrono::microseconds(timeout.total_microseconds()));
ec = asio::error_code();
#else // defined(ASIO_WINDOWS_RUNTIME)
::timeval tv;
tv.tv_sec = timeout.total_seconds();
tv.tv_usec = timeout.total_microseconds() % 1000000;
socket_ops::select(0, 0, 0, 0, &tv, ec);
#endif // defined(ASIO_WINDOWS_RUNTIME)
}
// Helper class used to implement per-operation cancellation.
class op_cancellation
{
public:
op_cancellation(deadline_timer_service* s,
typename timer_queue<Time_Traits>::per_timer_data* p)
: service_(s),
timer_data_(p)
{
}
void operator()(cancellation_type_t type)
{
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
service_->scheduler_.cancel_timer_by_key(
service_->timer_queue_, timer_data_, this);
}
}
private:
deadline_timer_service* service_;
typename timer_queue<Time_Traits>::per_timer_data* timer_data_;
};
// The queue of timers.
timer_queue<Time_Traits> timer_queue_;
// The object that schedules and executes timers. Usually a reactor.
timer_scheduler& scheduler_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/std_mutex.hpp | //
// detail/std_mutex.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_STD_MUTEX_HPP
#define ASIO_DETAIL_STD_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <mutex>
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/scoped_lock.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class std_event;
class std_mutex
: private noncopyable
{
public:
typedef asio::detail::scoped_lock<std_mutex> scoped_lock;
// Constructor.
std_mutex()
{
}
// Destructor.
~std_mutex()
{
}
// Lock the mutex.
void lock()
{
mutex_.lock();
}
// Unlock the mutex.
void unlock()
{
mutex_.unlock();
}
private:
friend class std_event;
std::mutex mutex_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_STD_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_null_buffers_op.hpp | //
// detail/win_iocp_null_buffers_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_OP_HPP
#define ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Handler, typename IoExecutor>
class win_iocp_null_buffers_op : public reactor_op
{
public:
ASIO_DEFINE_HANDLER_PTR(win_iocp_null_buffers_op);
win_iocp_null_buffers_op(socket_ops::weak_cancel_token_type cancel_token,
Handler& handler, const IoExecutor& io_ex)
: reactor_op(asio::error_code(),
&win_iocp_null_buffers_op::do_perform,
&win_iocp_null_buffers_op::do_complete),
cancel_token_(cancel_token),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static status do_perform(reactor_op*)
{
return done;
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
asio::error_code ec(result_ec);
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
win_iocp_null_buffers_op* o(static_cast<win_iocp_null_buffers_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
// The reactor may have stored a result in the operation object.
if (o->ec_)
ec = o->ec_;
// Map non-portable errors to their portable counterparts.
if (ec.value() == ERROR_NETNAME_DELETED)
{
if (o->cancel_token_.expired())
ec = asio::error::operation_aborted;
else
ec = asio::error::connection_reset;
}
else if (ec.value() == ERROR_PORT_UNREACHABLE)
{
ec = asio::error::connection_refused;
}
ASIO_ERROR_LOCATION(ec);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, ec, bytes_transferred);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
socket_ops::weak_cancel_token_type cancel_token_;
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/type_traits.hpp | //
// detail/type_traits.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_TYPE_TRAITS_HPP
#define ASIO_DETAIL_TYPE_TRAITS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <type_traits>
namespace asio {
using std::add_const;
template <typename T>
using add_const_t = typename std::add_const<T>::type;
using std::add_lvalue_reference;
template <typename T>
using add_lvalue_reference_t = typename std::add_lvalue_reference<T>::type;
template <std::size_t N, std::size_t A>
struct aligned_storage
{
struct type
{
alignas(A) unsigned char data[N];
};
};
template <std::size_t N, std::size_t A>
using aligned_storage_t = typename aligned_storage<N, A>::type;
using std::alignment_of;
using std::conditional;
template <bool C, typename T, typename U>
using conditional_t = typename std::conditional<C, T, U>::type;
using std::decay;
template <typename T>
using decay_t = typename std::decay<T>::type;
using std::declval;
using std::enable_if;
template <bool C, typename T = void>
using enable_if_t = typename std::enable_if<C, T>::type;
using std::false_type;
using std::integral_constant;
using std::is_base_of;
using std::is_class;
using std::is_const;
using std::is_constructible;
using std::is_convertible;
using std::is_copy_constructible;
using std::is_destructible;
using std::is_function;
using std::is_move_constructible;
using std::is_nothrow_copy_constructible;
using std::is_nothrow_destructible;
using std::is_object;
using std::is_pointer;
using std::is_reference;
using std::is_same;
using std::is_scalar;
using std::remove_cv;
template <typename T>
using remove_cv_t = typename std::remove_cv<T>::type;
template <typename T>
struct remove_cvref :
std::remove_cv<typename std::remove_reference<T>::type> {};
template <typename T>
using remove_cvref_t = typename remove_cvref<T>::type;
using std::remove_pointer;
template <typename T>
using remove_pointer_t = typename std::remove_pointer<T>::type;
using std::remove_reference;
template <typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
#if defined(ASIO_HAS_STD_INVOKE_RESULT)
template <typename> struct result_of;
template <typename F, typename... Args>
struct result_of<F(Args...)> : std::invoke_result<F, Args...> {};
template <typename T>
using result_of_t = typename result_of<T>::type;
#else // defined(ASIO_HAS_STD_INVOKE_RESULT)
using std::result_of;
template <typename T>
using result_of_t = typename std::result_of<T>::type;
#endif // defined(ASIO_HAS_STD_INVOKE_RESULT)
using std::true_type;
template <typename> struct void_type
{
typedef void type;
};
template <typename T>
using void_t = typename void_type<T>::type;
template <typename...> struct conjunction : true_type {};
template <typename T> struct conjunction<T> : T {};
template <typename Head, typename... Tail>
struct conjunction<Head, Tail...> :
conditional_t<Head::value, conjunction<Tail...>, Head> {};
struct defaulted_constraint
{
constexpr defaulted_constraint() {}
};
template <bool Condition, typename Type = int>
struct constraint : std::enable_if<Condition, Type> {};
template <bool Condition, typename Type = int>
using constraint_t = typename constraint<Condition, Type>::type;
template <typename T>
struct type_identity { typedef T type; };
template <typename T>
using type_identity_t = typename type_identity<T>::type;
} // namespace asio
#endif // ASIO_DETAIL_TYPE_TRAITS_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/push_options.hpp | //
// detail/push_options.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// No header guard
#if defined(__COMO__)
// Comeau C++
#elif defined(__DMC__)
// Digital Mars C++
#elif defined(__INTEL_COMPILER) || defined(__ICL) \
|| defined(__ICC) || defined(__ECC)
// Intel C++
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
# if !defined(ASIO_DISABLE_VISIBILITY)
# pragma GCC visibility push (default)
# endif // !defined(ASIO_DISABLE_VISIBILITY)
# endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
# pragma push_macro ("emit")
# undef emit
# pragma push_macro ("signal")
# undef signal
# pragma push_macro ("slot")
# undef slot
#elif defined(__clang__)
// Clang
# if defined(__OBJC__)
# if !defined(__APPLE_CC__) || (__APPLE_CC__ <= 1)
# if !defined(ASIO_DISABLE_OBJC_WORKAROUND)
# if !defined(Protocol) && !defined(id)
# define Protocol cpp_Protocol
# define id cpp_id
# define ASIO_OBJC_WORKAROUND
# endif
# endif
# endif
# endif
# if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
# if !defined(ASIO_DISABLE_VISIBILITY)
# pragma GCC visibility push (default)
# endif // !defined(ASIO_DISABLE_VISIBILITY)
# endif // !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
# if (__clang_major__ >= 6)
# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
# endif // (__clang_major__ >= 6)
# pragma push_macro ("emit")
# undef emit
# pragma push_macro ("signal")
# undef signal
# pragma push_macro ("slot")
# undef slot
#elif defined(__GNUC__)
// GNU C++
# if defined(__MINGW32__) || defined(__CYGWIN__)
# pragma pack (push, 8)
# endif
# if defined(__OBJC__)
# if !defined(__APPLE_CC__) || (__APPLE_CC__ <= 1)
# if !defined(ASIO_DISABLE_OBJC_WORKAROUND)
# if !defined(Protocol) && !defined(id)
# define Protocol cpp_Protocol
# define id cpp_id
# define ASIO_OBJC_WORKAROUND
# endif
# endif
# endif
# endif
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
# if !defined(ASIO_DISABLE_VISIBILITY)
# pragma GCC visibility push (default)
# endif // !defined(ASIO_DISABLE_VISIBILITY)
# endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || (__GNUC__ > 4)
# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
# endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || (__GNUC__ > 4)
# if (__GNUC__ >= 7)
# pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
# endif // (__GNUC__ >= 7)
# pragma push_macro ("emit")
# undef emit
# pragma push_macro ("signal")
# undef signal
# pragma push_macro ("slot")
# undef slot
#elif defined(__KCC)
// Kai C++
#elif defined(__sgi)
// SGI MIPSpro C++
#elif defined(__DECCXX)
// Compaq Tru64 Unix cxx
#elif defined(__ghs)
// Greenhills C++
#elif defined(__BORLANDC__) && !defined(__clang__)
// Borland C++
# pragma option push -a8 -b -Ve- -Vx- -w-inl -vi-
# pragma nopushoptwarn
# pragma nopackwarning
# if !defined(__MT__)
# error Multithreaded RTL must be selected.
# endif // !defined(__MT__)
#elif defined(__MWERKS__)
// Metrowerks CodeWarrior
#elif defined(__SUNPRO_CC)
// Sun Workshop Compiler C++
#elif defined(__HP_aCC)
// HP aCC
#elif defined(__MRC__) || defined(__SC__)
// MPW MrCpp or SCpp
#elif defined(__IBMCPP__)
// IBM Visual Age
#elif defined(_MSC_VER)
// Microsoft Visual C++
//
// Must remain the last #elif since some other vendors (Metrowerks, for example)
// also #define _MSC_VER
# pragma warning (disable:4103)
# pragma warning (push)
# pragma warning (disable:4619) // suppress 'there is no warning number XXXX'
# pragma warning (disable:4127)
# pragma warning (disable:4180)
# pragma warning (disable:4244)
# pragma warning (disable:4265)
# pragma warning (disable:4355)
# pragma warning (disable:4510)
# pragma warning (disable:4512)
# pragma warning (disable:4610)
# pragma warning (disable:4675)
# if (_MSC_VER < 1600)
// Visual Studio 2008 generates spurious warnings about unused parameters.
# pragma warning (disable:4100)
# endif // (_MSC_VER < 1600)
# if defined(_M_IX86) && defined(_Wp64)
// The /Wp64 option is broken. If you want to check 64 bit portability, use a
// 64 bit compiler!
# pragma warning (disable:4311)
# pragma warning (disable:4312)
# endif // defined(_M_IX86) && defined(_Wp64)
# pragma pack (push, 8)
// Note that if the /Og optimisation flag is enabled with MSVC6, the compiler
// has a tendency to incorrectly optimise away some calls to member template
// functions, even though those functions contain code that should not be
// optimised away! Therefore we will always disable this optimisation option
// for the MSVC6 compiler.
# if (_MSC_VER < 1300)
# pragma optimize ("g", off)
# endif
# if !defined(_MT)
# error Multithreaded RTL must be selected.
# endif // !defined(_MT)
# if defined(__cplusplus_cli) || defined(__cplusplus_winrt)
# if !defined(ASIO_DISABLE_CLR_WORKAROUND)
# if !defined(generic)
# define generic cpp_generic
# define ASIO_CLR_WORKAROUND
# endif
# endif
# endif
# pragma push_macro ("emit")
# undef emit
# pragma push_macro ("signal")
# undef signal
# pragma push_macro ("slot")
# undef slot
#endif
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/scoped_ptr.hpp | //
// detail/scoped_ptr.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SCOPED_PTR_HPP
#define ASIO_DETAIL_SCOPED_PTR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename T>
class scoped_ptr
{
public:
// Constructor.
explicit scoped_ptr(T* p = 0)
: p_(p)
{
}
// Destructor.
~scoped_ptr()
{
delete p_;
}
// Access.
T* get()
{
return p_;
}
// Access.
T* operator->()
{
return p_;
}
// Dereference.
T& operator*()
{
return *p_;
}
// Reset pointer.
void reset(T* p = 0)
{
delete p_;
p_ = p;
}
// Release ownership of the pointer.
T* release()
{
T* tmp = p_;
p_ = 0;
return tmp;
}
private:
// Disallow copying and assignment.
scoped_ptr(const scoped_ptr&);
scoped_ptr& operator=(const scoped_ptr&);
T* p_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_SCOPED_PTR_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/atomic_count.hpp | //
// detail/atomic_count.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_ATOMIC_COUNT_HPP
#define ASIO_DETAIL_ATOMIC_COUNT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_HAS_THREADS)
// Nothing to include.
#else // !defined(ASIO_HAS_THREADS)
# include <atomic>
#endif // !defined(ASIO_HAS_THREADS)
namespace asio {
namespace detail {
#if !defined(ASIO_HAS_THREADS)
typedef long atomic_count;
inline void increment(atomic_count& a, long b) { a += b; }
inline void decrement(atomic_count& a, long b) { a -= b; }
inline void ref_count_up(atomic_count& a) { ++a; }
inline bool ref_count_down(atomic_count& a) { return --a == 0; }
#else // !defined(ASIO_HAS_THREADS)
typedef std::atomic<long> atomic_count;
inline void increment(atomic_count& a, long b) { a += b; }
inline void decrement(atomic_count& a, long b) { a -= b; }
inline void ref_count_up(atomic_count& a)
{
a.fetch_add(1, std::memory_order_relaxed);
}
inline bool ref_count_down(atomic_count& a)
{
if (a.fetch_sub(1, std::memory_order_release) == 1)
{
std::atomic_thread_fence(std::memory_order_acquire);
return true;
}
return false;
}
#endif // !defined(ASIO_HAS_THREADS)
} // namespace detail
} // namespace asio
#endif // ASIO_DETAIL_ATOMIC_COUNT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_control.hpp | //
// detail/io_control.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_CONTROL_HPP
#define ASIO_DETAIL_IO_CONTROL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <cstddef>
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
namespace io_control {
// I/O control command for getting number of bytes available.
class bytes_readable
{
public:
// Default constructor.
bytes_readable()
: value_(0)
{
}
// Construct with a specific command value.
bytes_readable(std::size_t value)
: value_(static_cast<detail::ioctl_arg_type>(value))
{
}
// Get the name of the IO control command.
int name() const
{
return static_cast<int>(ASIO_OS_DEF(FIONREAD));
}
// Set the value of the I/O control command.
void set(std::size_t value)
{
value_ = static_cast<detail::ioctl_arg_type>(value);
}
// Get the current value of the I/O control command.
std::size_t get() const
{
return static_cast<std::size_t>(value_);
}
// Get the address of the command data.
detail::ioctl_arg_type* data()
{
return &value_;
}
// Get the address of the command data.
const detail::ioctl_arg_type* data() const
{
return &value_;
}
private:
detail::ioctl_arg_type value_;
};
} // namespace io_control
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_IO_CONTROL_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_operation.hpp | //
// detail/win_iocp_operation.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
#define ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/detail/handler_tracking.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/error_code.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class win_iocp_io_context;
// Base class for all operations. A function pointer is used instead of virtual
// functions to avoid the associated overhead.
class win_iocp_operation
: public OVERLAPPED
ASIO_ALSO_INHERIT_TRACKED_HANDLER
{
public:
typedef win_iocp_operation operation_type;
void complete(void* owner, const asio::error_code& ec,
std::size_t bytes_transferred)
{
func_(owner, this, ec, bytes_transferred);
}
void destroy()
{
func_(0, this, asio::error_code(), 0);
}
void reset()
{
Internal = 0;
InternalHigh = 0;
Offset = 0;
OffsetHigh = 0;
hEvent = 0;
ready_ = 0;
}
protected:
typedef void (*func_type)(
void*, win_iocp_operation*,
const asio::error_code&, std::size_t);
win_iocp_operation(func_type func)
: next_(0),
func_(func)
{
reset();
}
// Prevents deletion through this type.
~win_iocp_operation()
{
}
private:
friend class op_queue_access;
friend class win_iocp_io_context;
win_iocp_operation* next_;
func_type func_;
long ready_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/initiate_dispatch.hpp | //
// detail/initiate_dispatch.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_INITIATE_DISPATCH_HPP
#define ASIO_DETAIL_INITIATE_DISPATCH_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/associated_allocator.hpp"
#include "asio/associated_executor.hpp"
#include "asio/detail/work_dispatcher.hpp"
#include "asio/execution/allocator.hpp"
#include "asio/execution/blocking.hpp"
#include "asio/prefer.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class initiate_dispatch
{
public:
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
execution::is_executor<
associated_executor_t<decay_t<CompletionHandler>>
>::value
>* = 0) const
{
associated_executor_t<decay_t<CompletionHandler>> ex(
(get_associated_executor)(handler));
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
asio::prefer(ex, execution::allocator(alloc)).execute(
asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)));
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
!execution::is_executor<
associated_executor_t<decay_t<CompletionHandler>>
>::value
>* = 0) const
{
associated_executor_t<decay_t<CompletionHandler>> ex(
(get_associated_executor)(handler));
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
ex.dispatch(asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)), alloc);
}
};
template <typename Executor>
class initiate_dispatch_with_executor
{
public:
typedef Executor executor_type;
explicit initiate_dispatch_with_executor(const Executor& ex)
: ex_(ex)
{
}
executor_type get_executor() const noexcept
{
return ex_;
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
!detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
asio::prefer(ex_, execution::allocator(alloc)).execute(
asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)));
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
typedef decay_t<CompletionHandler> handler_t;
typedef associated_executor_t<handler_t, Executor> handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
associated_allocator_t<handler_t> alloc(
(get_associated_allocator)(handler));
asio::prefer(ex_, execution::allocator(alloc)).execute(
detail::work_dispatcher<handler_t, handler_ex_t>(
static_cast<CompletionHandler&&>(handler), handler_ex));
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
!execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
!detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
ex_.dispatch(asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)), alloc);
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
!execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
typedef decay_t<CompletionHandler> handler_t;
typedef associated_executor_t<handler_t, Executor> handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
associated_allocator_t<handler_t> alloc(
(get_associated_allocator)(handler));
ex_.dispatch(detail::work_dispatcher<handler_t, handler_ex_t>(
static_cast<CompletionHandler&&>(handler), handler_ex), alloc);
}
private:
Executor ex_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_INITIATE_DISPATCH_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_tss_ptr.hpp | //
// detail/win_tss_ptr.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_TSS_PTR_HPP
#define ASIO_DETAIL_WIN_TSS_PTR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Helper function to create thread-specific storage.
ASIO_DECL DWORD win_tss_ptr_create();
template <typename T>
class win_tss_ptr
: private noncopyable
{
public:
// Constructor.
win_tss_ptr()
: tss_key_(win_tss_ptr_create())
{
}
// Destructor.
~win_tss_ptr()
{
::TlsFree(tss_key_);
}
// Get the value.
operator T*() const
{
return static_cast<T*>(::TlsGetValue(tss_key_));
}
// Set the value.
void operator=(T* value)
{
::TlsSetValue(tss_key_, value);
}
private:
// Thread-specific storage to allow unlocked access to determine whether a
// thread is a member of the pool.
DWORD tss_key_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_tss_ptr.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS)
#endif // ASIO_DETAIL_WIN_TSS_PTR_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_recv_op.hpp | //
// detail/io_uring_socket_recv_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_RECV_OP_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_RECV_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename MutableBufferSequence>
class io_uring_socket_recv_op_base : public io_uring_operation
{
public:
io_uring_socket_recv_op_base(const asio::error_code& success_ec,
socket_type socket, socket_ops::state_type state,
const MutableBufferSequence& buffers,
socket_base::message_flags flags, func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_socket_recv_op_base::do_prepare,
&io_uring_socket_recv_op_base::do_perform, complete_func),
socket_(socket),
state_(state),
buffers_(buffers),
flags_(flags),
bufs_(buffers),
msghdr_()
{
msghdr_.msg_iov = bufs_.buffers();
msghdr_.msg_iovlen = static_cast<int>(bufs_.count());
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_socket_recv_op_base* o(
static_cast<io_uring_socket_recv_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0;
::io_uring_prep_poll_add(sqe, o->socket_, except_op ? POLLPRI : POLLIN);
}
else if (o->bufs_.is_single_buffer
&& o->bufs_.is_registered_buffer && o->flags_ == 0)
{
::io_uring_prep_read_fixed(sqe, o->socket_,
o->bufs_.buffers()->iov_base, o->bufs_.buffers()->iov_len,
0, o->bufs_.registered_id().native_handle());
}
else
{
::io_uring_prep_recvmsg(sqe, o->socket_, &o->msghdr_, o->flags_);
}
}
static bool do_perform(io_uring_operation* base, bool after_completion)
{
ASIO_ASSUME(base != 0);
io_uring_socket_recv_op_base* o(
static_cast<io_uring_socket_recv_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0;
if (after_completion || !except_op)
{
if (o->bufs_.is_single_buffer)
{
return socket_ops::non_blocking_recv1(o->socket_,
o->bufs_.first(o->buffers_).data(),
o->bufs_.first(o->buffers_).size(), o->flags_,
(o->state_ & socket_ops::stream_oriented) != 0,
o->ec_, o->bytes_transferred_);
}
else
{
return socket_ops::non_blocking_recv(o->socket_,
o->bufs_.buffers(), o->bufs_.count(), o->flags_,
(o->state_ & socket_ops::stream_oriented) != 0,
o->ec_, o->bytes_transferred_);
}
}
}
else if (after_completion)
{
if (!o->ec_ && o->bytes_transferred_ == 0)
if ((o->state_ & socket_ops::stream_oriented) != 0)
o->ec_ = asio::error::eof;
}
if (o->ec_ && o->ec_ == asio::error::would_block)
{
o->state_ |= socket_ops::internal_non_blocking;
return false;
}
return after_completion;
}
private:
socket_type socket_;
socket_ops::state_type state_;
MutableBufferSequence buffers_;
socket_base::message_flags flags_;
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs_;
msghdr msghdr_;
};
template <typename MutableBufferSequence, typename Handler, typename IoExecutor>
class io_uring_socket_recv_op
: public io_uring_socket_recv_op_base<MutableBufferSequence>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_recv_op);
io_uring_socket_recv_op(const asio::error_code& success_ec,
int socket, socket_ops::state_type state,
const MutableBufferSequence& buffers, socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
: io_uring_socket_recv_op_base<MutableBufferSequence>(success_ec,
socket, state, buffers, flags, &io_uring_socket_recv_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_recv_op* o
(static_cast<io_uring_socket_recv_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_RECV_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/posix_event.hpp | //
// detail/posix_event.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_POSIX_EVENT_HPP
#define ASIO_DETAIL_POSIX_EVENT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_PTHREADS)
#include <cstddef>
#include <pthread.h>
#include "asio/detail/assert.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class posix_event
: private noncopyable
{
public:
// Constructor.
ASIO_DECL posix_event();
// Destructor.
~posix_event()
{
::pthread_cond_destroy(&cond_);
}
// Signal the event. (Retained for backward compatibility.)
template <typename Lock>
void signal(Lock& lock)
{
this->signal_all(lock);
}
// Signal all waiters.
template <typename Lock>
void signal_all(Lock& lock)
{
ASIO_ASSERT(lock.locked());
(void)lock;
state_ |= 1;
::pthread_cond_broadcast(&cond_); // Ignore EINVAL.
}
// Unlock the mutex and signal one waiter.
template <typename Lock>
void unlock_and_signal_one(Lock& lock)
{
ASIO_ASSERT(lock.locked());
state_ |= 1;
bool have_waiters = (state_ > 1);
lock.unlock();
if (have_waiters)
::pthread_cond_signal(&cond_); // Ignore EINVAL.
}
// Unlock the mutex and signal one waiter who may destroy us.
template <typename Lock>
void unlock_and_signal_one_for_destruction(Lock& lock)
{
ASIO_ASSERT(lock.locked());
state_ |= 1;
bool have_waiters = (state_ > 1);
if (have_waiters)
::pthread_cond_signal(&cond_); // Ignore EINVAL.
lock.unlock();
}
// If there's a waiter, unlock the mutex and signal it.
template <typename Lock>
bool maybe_unlock_and_signal_one(Lock& lock)
{
ASIO_ASSERT(lock.locked());
state_ |= 1;
if (state_ > 1)
{
lock.unlock();
::pthread_cond_signal(&cond_); // Ignore EINVAL.
return true;
}
return false;
}
// Reset the event.
template <typename Lock>
void clear(Lock& lock)
{
ASIO_ASSERT(lock.locked());
(void)lock;
state_ &= ~std::size_t(1);
}
// Wait for the event to become signalled.
template <typename Lock>
void wait(Lock& lock)
{
ASIO_ASSERT(lock.locked());
while ((state_ & 1) == 0)
{
state_ += 2;
::pthread_cond_wait(&cond_, &lock.mutex().mutex_); // Ignore EINVAL.
state_ -= 2;
}
}
// Timed wait for the event to become signalled.
template <typename Lock>
bool wait_for_usec(Lock& lock, long usec)
{
ASIO_ASSERT(lock.locked());
if ((state_ & 1) == 0)
{
state_ += 2;
timespec ts;
#if (defined(__MACH__) && defined(__APPLE__)) \
|| (defined(__ANDROID__) && (__ANDROID_API__ < 21) \
&& defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE))
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
::pthread_cond_timedwait_relative_np(
&cond_, &lock.mutex().mutex_, &ts); // Ignore EINVAL.
#else // (defined(__MACH__) && defined(__APPLE__))
// || (defined(__ANDROID__) && (__ANDROID_API__ < 21)
// && defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE))
if (::clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
{
ts.tv_sec += usec / 1000000;
ts.tv_nsec += (usec % 1000000) * 1000;
ts.tv_sec += ts.tv_nsec / 1000000000;
ts.tv_nsec = ts.tv_nsec % 1000000000;
::pthread_cond_timedwait(&cond_,
&lock.mutex().mutex_, &ts); // Ignore EINVAL.
}
#endif // (defined(__MACH__) && defined(__APPLE__))
// || (defined(__ANDROID__) && (__ANDROID_API__ < 21)
// && defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE))
state_ -= 2;
}
return (state_ & 1) != 0;
}
private:
::pthread_cond_t cond_;
std::size_t state_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/posix_event.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_PTHREADS)
#endif // ASIO_DETAIL_POSIX_EVENT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/wait_handler.hpp | //
// detail/wait_handler.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WAIT_HANDLER_HPP
#define ASIO_DETAIL_WAIT_HANDLER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/wait_op.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Handler, typename IoExecutor>
class wait_handler : public wait_op
{
public:
ASIO_DEFINE_HANDLER_PTR(wait_handler);
wait_handler(Handler& h, const IoExecutor& io_ex)
: wait_op(&wait_handler::do_complete),
handler_(static_cast<Handler&&>(h)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
wait_handler* h(static_cast<wait_handler*>(base));
ptr p = { asio::detail::addressof(h->handler_), h, h };
ASIO_HANDLER_COMPLETION((*h));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
h->work_));
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder1<Handler, asio::error_code>
handler(h->handler_, h->ec_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_WAIT_HANDLER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/buffer_resize_guard.hpp | //
// detail/buffer_resize_guard.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
#define ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/limits.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Helper class to manage buffer resizing in an exception safe way.
template <typename Buffer>
class buffer_resize_guard
{
public:
// Constructor.
buffer_resize_guard(Buffer& buffer)
: buffer_(buffer),
old_size_(buffer.size())
{
}
// Destructor rolls back the buffer resize unless commit was called.
~buffer_resize_guard()
{
if (old_size_ != (std::numeric_limits<size_t>::max)())
{
buffer_.resize(old_size_);
}
}
// Commit the resize transaction.
void commit()
{
old_size_ = (std::numeric_limits<size_t>::max)();
}
private:
// The buffer being managed.
Buffer& buffer_;
// The size of the buffer at the time the guard was constructed.
size_t old_size_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/resolve_op.hpp | //
// detail/resolve_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_RESOLVE_OP_HPP
#define ASIO_DETAIL_RESOLVE_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/error.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class resolve_op : public operation
{
public:
// The error code to be passed to the completion handler.
asio::error_code ec_;
protected:
resolve_op(func_type complete_func)
: operation(complete_func)
{
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_RESOLVE_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/initiate_post.hpp | //
// detail/initiate_post.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_INITIATE_POST_HPP
#define ASIO_DETAIL_INITIATE_POST_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/associated_allocator.hpp"
#include "asio/associated_executor.hpp"
#include "asio/detail/work_dispatcher.hpp"
#include "asio/execution/allocator.hpp"
#include "asio/execution/blocking.hpp"
#include "asio/execution/relationship.hpp"
#include "asio/prefer.hpp"
#include "asio/require.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class initiate_post
{
public:
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
execution::is_executor<
associated_executor_t<decay_t<CompletionHandler>>
>::value
>* = 0) const
{
associated_executor_t<decay_t<CompletionHandler>> ex(
(get_associated_executor)(handler));
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
asio::prefer(
asio::require(ex, execution::blocking.never),
execution::relationship.fork,
execution::allocator(alloc)
).execute(
asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)));
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
!execution::is_executor<
associated_executor_t<decay_t<CompletionHandler>>
>::value
>* = 0) const
{
associated_executor_t<decay_t<CompletionHandler>> ex(
(get_associated_executor)(handler));
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
ex.post(asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)), alloc);
}
};
template <typename Executor>
class initiate_post_with_executor
{
public:
typedef Executor executor_type;
explicit initiate_post_with_executor(const Executor& ex)
: ex_(ex)
{
}
executor_type get_executor() const noexcept
{
return ex_;
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
!detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
asio::prefer(
asio::require(ex_, execution::blocking.never),
execution::relationship.fork,
execution::allocator(alloc)
).execute(
asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)));
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
typedef decay_t<CompletionHandler> handler_t;
typedef associated_executor_t<handler_t, Executor> handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
associated_allocator_t<handler_t> alloc(
(get_associated_allocator)(handler));
asio::prefer(
asio::require(ex_, execution::blocking.never),
execution::relationship.fork,
execution::allocator(alloc)
).execute(
detail::work_dispatcher<handler_t, handler_ex_t>(
static_cast<CompletionHandler&&>(handler), handler_ex));
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
!execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
!detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
associated_allocator_t<decay_t<CompletionHandler>> alloc(
(get_associated_allocator)(handler));
ex_.post(asio::detail::bind_handler(
static_cast<CompletionHandler&&>(handler)), alloc);
}
template <typename CompletionHandler>
void operator()(CompletionHandler&& handler,
enable_if_t<
!execution::is_executor<
conditional_t<true, executor_type, CompletionHandler>
>::value
>* = 0,
enable_if_t<
detail::is_work_dispatcher_required<
decay_t<CompletionHandler>,
Executor
>::value
>* = 0) const
{
typedef decay_t<CompletionHandler> handler_t;
typedef associated_executor_t<handler_t, Executor> handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
associated_allocator_t<handler_t> alloc(
(get_associated_allocator)(handler));
ex_.post(detail::work_dispatcher<handler_t, handler_ex_t>(
static_cast<CompletionHandler&&>(handler), handler_ex), alloc);
}
private:
Executor ex_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_INITIATE_POST_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/timer_scheduler.hpp | //
// detail/timer_scheduler.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_TIMER_SCHEDULER_HPP
#define ASIO_DETAIL_TIMER_SCHEDULER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/timer_scheduler_fwd.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
# include "asio/detail/winrt_timer_scheduler.hpp"
#elif defined(ASIO_HAS_IOCP)
# include "asio/detail/win_iocp_io_context.hpp"
#elif defined(ASIO_HAS_IO_URING_AS_DEFAULT)
# include "asio/detail/io_uring_service.hpp"
#elif defined(ASIO_HAS_EPOLL)
# include "asio/detail/epoll_reactor.hpp"
#elif defined(ASIO_HAS_KQUEUE)
# include "asio/detail/kqueue_reactor.hpp"
#elif defined(ASIO_HAS_DEV_POLL)
# include "asio/detail/dev_poll_reactor.hpp"
#else
# include "asio/detail/select_reactor.hpp"
#endif
#endif // ASIO_DETAIL_TIMER_SCHEDULER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/mutex.hpp | //
// detail/mutex.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_MUTEX_HPP
#define ASIO_DETAIL_MUTEX_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_HAS_THREADS)
# include "asio/detail/null_mutex.hpp"
#elif defined(ASIO_WINDOWS)
# include "asio/detail/win_mutex.hpp"
#elif defined(ASIO_HAS_PTHREADS)
# include "asio/detail/posix_mutex.hpp"
#else
# include "asio/detail/std_mutex.hpp"
#endif
namespace asio {
namespace detail {
#if !defined(ASIO_HAS_THREADS)
typedef null_mutex mutex;
#elif defined(ASIO_WINDOWS)
typedef win_mutex mutex;
#elif defined(ASIO_HAS_PTHREADS)
typedef posix_mutex mutex;
#else
typedef std_mutex mutex;
#endif
} // namespace detail
} // namespace asio
#endif // ASIO_DETAIL_MUTEX_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/std_thread.hpp | //
// detail/std_thread.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_STD_THREAD_HPP
#define ASIO_DETAIL_STD_THREAD_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <thread>
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class std_thread
: private noncopyable
{
public:
// Constructor.
template <typename Function>
std_thread(Function f, unsigned int = 0)
: thread_(f)
{
}
// Destructor.
~std_thread()
{
join();
}
// Wait for the thread to exit.
void join()
{
if (thread_.joinable())
thread_.join();
}
// Get number of CPUs.
static std::size_t hardware_concurrency()
{
return std::thread::hardware_concurrency();
}
private:
std::thread thread_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_STD_THREAD_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/resolve_query_op.hpp | //
// detail/resolve_query_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_RESOLVE_QUERY_OP_HPP
#define ASIO_DETAIL_RESOLVE_QUERY_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/resolve_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/error.hpp"
#include "asio/ip/basic_resolver_query.hpp"
#include "asio/ip/basic_resolver_results.hpp"
#if defined(ASIO_HAS_IOCP)
# include "asio/detail/win_iocp_io_context.hpp"
#else // defined(ASIO_HAS_IOCP)
# include "asio/detail/scheduler.hpp"
#endif // defined(ASIO_HAS_IOCP)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Protocol, typename Handler, typename IoExecutor>
class resolve_query_op : public resolve_op
{
public:
ASIO_DEFINE_HANDLER_PTR(resolve_query_op);
typedef asio::ip::basic_resolver_query<Protocol> query_type;
typedef asio::ip::basic_resolver_results<Protocol> results_type;
#if defined(ASIO_HAS_IOCP)
typedef class win_iocp_io_context scheduler_impl;
#else
typedef class scheduler scheduler_impl;
#endif
resolve_query_op(socket_ops::weak_cancel_token_type cancel_token,
const query_type& qry, scheduler_impl& sched,
Handler& handler, const IoExecutor& io_ex)
: resolve_op(&resolve_query_op::do_complete),
cancel_token_(cancel_token),
query_(qry),
scheduler_(sched),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex),
addrinfo_(0)
{
}
~resolve_query_op()
{
if (addrinfo_)
socket_ops::freeaddrinfo(addrinfo_);
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
resolve_query_op* o(static_cast<resolve_query_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
if (owner && owner != &o->scheduler_)
{
// The operation is being run on the worker io_context. Time to perform
// the resolver operation.
// Perform the blocking host resolution operation.
socket_ops::background_getaddrinfo(o->cancel_token_,
o->query_.host_name().c_str(), o->query_.service_name().c_str(),
o->query_.hints(), &o->addrinfo_, o->ec_);
// Pass operation back to main io_context for completion.
o->scheduler_.post_deferred_completion(o);
p.v = p.p = 0;
}
else
{
// The operation has been returned to the main io_context. The completion
// handler is ready to be delivered.
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
// Make a copy of the handler so that the memory can be deallocated
// before the upcall is made. Even if we're not about to make an upcall,
// a sub-object of the handler may be the true owner of the memory
// associated with the handler. Consequently, a local copy of the handler
// is required to ensure that any owning sub-object remains valid until
// after we have deallocated the memory here.
detail::binder2<Handler, asio::error_code, results_type>
handler(o->handler_, o->ec_, results_type());
p.h = asio::detail::addressof(handler.handler_);
if (o->addrinfo_)
{
handler.arg2_ = results_type::create(o->addrinfo_,
o->query_.host_name(), o->query_.service_name());
}
p.reset();
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "..."));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
}
private:
socket_ops::weak_cancel_token_type cancel_token_;
query_type query_;
scheduler_impl& scheduler_;
Handler handler_;
handler_work<Handler, IoExecutor> work_;
asio::detail::addrinfo_type* addrinfo_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_RESOLVE_QUERY_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_sendto_op.hpp | //
// detail/io_uring_socket_sendto_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_SENDTO_OP_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_SENDTO_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename ConstBufferSequence, typename Endpoint>
class io_uring_socket_sendto_op_base : public io_uring_operation
{
public:
io_uring_socket_sendto_op_base(const asio::error_code& success_ec,
socket_type socket, socket_ops::state_type state,
const ConstBufferSequence& buffers, const Endpoint& endpoint,
socket_base::message_flags flags, func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_socket_sendto_op_base::do_prepare,
&io_uring_socket_sendto_op_base::do_perform, complete_func),
socket_(socket),
state_(state),
buffers_(buffers),
destination_(endpoint),
flags_(flags),
bufs_(buffers),
msghdr_()
{
msghdr_.msg_iov = bufs_.buffers();
msghdr_.msg_iovlen = static_cast<int>(bufs_.count());
msghdr_.msg_name = static_cast<sockaddr*>(
static_cast<void*>(destination_.data()));
msghdr_.msg_namelen = destination_.size();
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_socket_sendto_op_base* o(
static_cast<io_uring_socket_sendto_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
::io_uring_prep_poll_add(sqe, o->socket_, POLLOUT);
}
else
{
::io_uring_prep_sendmsg(sqe, o->socket_, &o->msghdr_, o->flags_);
}
}
static bool do_perform(io_uring_operation* base, bool after_completion)
{
ASIO_ASSUME(base != 0);
io_uring_socket_sendto_op_base* o(
static_cast<io_uring_socket_sendto_op_base*>(base));
if ((o->state_ & socket_ops::internal_non_blocking) != 0)
{
if (o->bufs_.is_single_buffer)
{
return socket_ops::non_blocking_sendto1(o->socket_,
o->bufs_.first(o->buffers_).data(),
o->bufs_.first(o->buffers_).size(), o->flags_,
o->destination_.data(), o->destination_.size(),
o->ec_, o->bytes_transferred_);
}
else
{
return socket_ops::non_blocking_sendto(o->socket_,
o->bufs_.buffers(), o->bufs_.count(), o->flags_,
o->destination_.data(), o->destination_.size(),
o->ec_, o->bytes_transferred_);
}
}
if (o->ec_ && o->ec_ == asio::error::would_block)
{
o->state_ |= socket_ops::internal_non_blocking;
return false;
}
return after_completion;
}
private:
socket_type socket_;
socket_ops::state_type state_;
ConstBufferSequence buffers_;
Endpoint destination_;
socket_base::message_flags flags_;
buffer_sequence_adapter<asio::const_buffer, ConstBufferSequence> bufs_;
msghdr msghdr_;
};
template <typename ConstBufferSequence, typename Endpoint,
typename Handler, typename IoExecutor>
class io_uring_socket_sendto_op
: public io_uring_socket_sendto_op_base<ConstBufferSequence, Endpoint>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_sendto_op);
io_uring_socket_sendto_op(const asio::error_code& success_ec,
int socket, socket_ops::state_type state,
const ConstBufferSequence& buffers, const Endpoint& endpoint,
socket_base::message_flags flags,
Handler& handler, const IoExecutor& io_ex)
: io_uring_socket_sendto_op_base<ConstBufferSequence, Endpoint>(
success_ec, socket, state, buffers, endpoint, flags,
&io_uring_socket_sendto_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_sendto_op* o
(static_cast<io_uring_socket_sendto_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_SENDTO_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/strand_executor_service.hpp | //
// detail/strand_executor_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP
#define ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/atomic_count.hpp"
#include "asio/detail/executor_op.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/scheduler_operation.hpp"
#include "asio/detail/scoped_ptr.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/execution.hpp"
#include "asio/execution_context.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Default service implementation for a strand.
class strand_executor_service
: public execution_context_service_base<strand_executor_service>
{
public:
// The underlying implementation of a strand.
class strand_impl
{
public:
ASIO_DECL ~strand_impl();
private:
friend class strand_executor_service;
// Mutex to protect access to internal data.
mutex* mutex_;
// Indicates whether the strand is currently "locked" by a handler. This
// means that there is a handler upcall in progress, or that the strand
// itself has been scheduled in order to invoke some pending handlers.
bool locked_;
// Indicates that the strand has been shut down and will accept no further
// handlers.
bool shutdown_;
// The handlers that are waiting on the strand but should not be run until
// after the next time the strand is scheduled. This queue must only be
// modified while the mutex is locked.
op_queue<scheduler_operation> waiting_queue_;
// The handlers that are ready to be run. Logically speaking, these are the
// handlers that hold the strand's lock. The ready queue is only modified
// from within the strand and so may be accessed without locking the mutex.
op_queue<scheduler_operation> ready_queue_;
// Pointers to adjacent handle implementations in linked list.
strand_impl* next_;
strand_impl* prev_;
// The strand service in where the implementation is held.
strand_executor_service* service_;
};
typedef shared_ptr<strand_impl> implementation_type;
// Construct a new strand service for the specified context.
ASIO_DECL explicit strand_executor_service(execution_context& context);
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Create a new strand_executor implementation.
ASIO_DECL implementation_type create_implementation();
// Request invocation of the given function.
template <typename Executor, typename Function>
static void execute(const implementation_type& impl, Executor& ex,
Function&& function,
enable_if_t<
can_query<Executor, execution::allocator_t<void>>::value
>* = 0);
// Request invocation of the given function.
template <typename Executor, typename Function>
static void execute(const implementation_type& impl, Executor& ex,
Function&& function,
enable_if_t<
!can_query<Executor, execution::allocator_t<void>>::value
>* = 0);
// Request invocation of the given function.
template <typename Executor, typename Function, typename Allocator>
static void dispatch(const implementation_type& impl, Executor& ex,
Function&& function, const Allocator& a);
// Request invocation of the given function and return immediately.
template <typename Executor, typename Function, typename Allocator>
static void post(const implementation_type& impl, Executor& ex,
Function&& function, const Allocator& a);
// Request invocation of the given function and return immediately.
template <typename Executor, typename Function, typename Allocator>
static void defer(const implementation_type& impl, Executor& ex,
Function&& function, const Allocator& a);
// Determine whether the strand is running in the current thread.
ASIO_DECL static bool running_in_this_thread(
const implementation_type& impl);
private:
friend class strand_impl;
template <typename F, typename Allocator> class allocator_binder;
template <typename Executor, typename = void> class invoker;
// Adds a function to the strand. Returns true if it acquires the lock.
ASIO_DECL static bool enqueue(const implementation_type& impl,
scheduler_operation* op);
// Transfers waiting handlers to the ready queue. Returns true if one or more
// handlers were transferred.
ASIO_DECL static bool push_waiting_to_ready(implementation_type& impl);
// Invokes all ready-to-run handlers.
ASIO_DECL static void run_ready_handlers(implementation_type& impl);
// Helper function to request invocation of the given function.
template <typename Executor, typename Function, typename Allocator>
static void do_execute(const implementation_type& impl, Executor& ex,
Function&& function, const Allocator& a);
// Mutex to protect access to the service-wide state.
mutex mutex_;
// Number of mutexes shared between all strand objects.
enum { num_mutexes = 193 };
// Pool of mutexes.
scoped_ptr<mutex> mutexes_[num_mutexes];
// Extra value used when hashing to prevent recycled memory locations from
// getting the same mutex.
std::size_t salt_;
// The head of a linked list of all implementations.
strand_impl* impl_list_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#include "asio/detail/impl/strand_executor_service.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/strand_executor_service.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // ASIO_DETAIL_STRAND_EXECUTOR_SERVICE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/posix_fd_set_adapter.hpp | //
// detail/posix_fd_set_adapter.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
#define ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_WINDOWS) \
&& !defined(__CYGWIN__) \
&& !defined(ASIO_WINDOWS_RUNTIME)
#include <cstring>
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/reactor_op_queue.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Adapts the FD_SET type to meet the Descriptor_Set concept's requirements.
class posix_fd_set_adapter : noncopyable
{
public:
posix_fd_set_adapter()
: max_descriptor_(invalid_socket)
{
using namespace std; // Needed for memset on Solaris.
FD_ZERO(&fd_set_);
}
void reset()
{
using namespace std; // Needed for memset on Solaris.
FD_ZERO(&fd_set_);
}
bool set(socket_type descriptor)
{
if (descriptor < (socket_type)FD_SETSIZE)
{
if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_)
max_descriptor_ = descriptor;
FD_SET(descriptor, &fd_set_);
return true;
}
return false;
}
void set(reactor_op_queue<socket_type>& operations, op_queue<operation>& ops)
{
reactor_op_queue<socket_type>::iterator i = operations.begin();
while (i != operations.end())
{
reactor_op_queue<socket_type>::iterator op_iter = i++;
if (!set(op_iter->first))
{
asio::error_code ec(error::fd_set_failure);
operations.cancel_operations(op_iter, ops, ec);
}
}
}
bool is_set(socket_type descriptor) const
{
return FD_ISSET(descriptor, &fd_set_) != 0;
}
operator fd_set*()
{
return &fd_set_;
}
socket_type max_descriptor() const
{
return max_descriptor_;
}
void perform(reactor_op_queue<socket_type>& operations,
op_queue<operation>& ops) const
{
reactor_op_queue<socket_type>::iterator i = operations.begin();
while (i != operations.end())
{
reactor_op_queue<socket_type>::iterator op_iter = i++;
if (is_set(op_iter->first))
operations.perform_operations(op_iter, ops);
}
}
private:
mutable fd_set fd_set_;
socket_type max_descriptor_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // !defined(ASIO_WINDOWS)
// && !defined(__CYGWIN__)
// && !defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/fd_set_adapter.hpp | //
// detail/fd_set_adapter.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_FD_SET_ADAPTER_HPP
#define ASIO_DETAIL_FD_SET_ADAPTER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_WINDOWS_RUNTIME)
#include "asio/detail/posix_fd_set_adapter.hpp"
#include "asio/detail/win_fd_set_adapter.hpp"
namespace asio {
namespace detail {
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
typedef win_fd_set_adapter fd_set_adapter;
#else
typedef posix_fd_set_adapter fd_set_adapter;
#endif
} // namespace detail
} // namespace asio
#endif // !defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_FD_SET_ADAPTER_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_descriptor_service.hpp | //
// detail/io_uring_descriptor_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_DESCRIPTOR_SERVICE_HPP
#define ASIO_DETAIL_IO_URING_DESCRIPTOR_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/associated_cancellation_slot.hpp"
#include "asio/buffer.hpp"
#include "asio/cancellation_type.hpp"
#include "asio/execution_context.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/descriptor_ops.hpp"
#include "asio/detail/io_uring_descriptor_read_at_op.hpp"
#include "asio/detail/io_uring_descriptor_read_op.hpp"
#include "asio/detail/io_uring_descriptor_write_at_op.hpp"
#include "asio/detail/io_uring_descriptor_write_op.hpp"
#include "asio/detail/io_uring_null_buffers_op.hpp"
#include "asio/detail/io_uring_service.hpp"
#include "asio/detail/io_uring_wait_op.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/posix/descriptor_base.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class io_uring_descriptor_service :
public execution_context_service_base<io_uring_descriptor_service>
{
public:
// The native type of a descriptor.
typedef int native_handle_type;
// The implementation type of the descriptor.
class implementation_type
: private asio::detail::noncopyable
{
public:
// Default constructor.
implementation_type()
: descriptor_(-1),
state_(0)
{
}
private:
// Only this service will have access to the internal values.
friend class io_uring_descriptor_service;
// The native descriptor representation.
int descriptor_;
// The current state of the descriptor.
descriptor_ops::state_type state_;
// Per I/O object data used by the io_uring_service.
io_uring_service::per_io_object_data io_object_data_;
};
// Constructor.
ASIO_DECL io_uring_descriptor_service(execution_context& context);
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Construct a new descriptor implementation.
ASIO_DECL void construct(implementation_type& impl);
// Move-construct a new descriptor implementation.
ASIO_DECL void move_construct(implementation_type& impl,
implementation_type& other_impl) noexcept;
// Move-assign from another descriptor implementation.
ASIO_DECL void move_assign(implementation_type& impl,
io_uring_descriptor_service& other_service,
implementation_type& other_impl);
// Destroy a descriptor implementation.
ASIO_DECL void destroy(implementation_type& impl);
// Assign a native descriptor to a descriptor implementation.
ASIO_DECL asio::error_code assign(implementation_type& impl,
const native_handle_type& native_descriptor,
asio::error_code& ec);
// Determine whether the descriptor is open.
bool is_open(const implementation_type& impl) const
{
return impl.descriptor_ != -1;
}
// Destroy a descriptor implementation.
ASIO_DECL asio::error_code close(implementation_type& impl,
asio::error_code& ec);
// Get the native descriptor representation.
native_handle_type native_handle(const implementation_type& impl) const
{
return impl.descriptor_;
}
// Release ownership of the native descriptor representation.
ASIO_DECL native_handle_type release(implementation_type& impl);
// Release ownership of the native descriptor representation.
native_handle_type release(implementation_type& impl,
asio::error_code& ec)
{
ec = success_ec_;
return release(impl);
}
// Cancel all operations associated with the descriptor.
ASIO_DECL asio::error_code cancel(implementation_type& impl,
asio::error_code& ec);
// Perform an IO control command on the descriptor.
template <typename IO_Control_Command>
asio::error_code io_control(implementation_type& impl,
IO_Control_Command& command, asio::error_code& ec)
{
descriptor_ops::ioctl(impl.descriptor_, impl.state_,
command.name(), static_cast<ioctl_arg_type*>(command.data()), ec);
ASIO_ERROR_LOCATION(ec);
return ec;
}
// Gets the non-blocking mode of the descriptor.
bool non_blocking(const implementation_type& impl) const
{
return (impl.state_ & descriptor_ops::user_set_non_blocking) != 0;
}
// Sets the non-blocking mode of the descriptor.
asio::error_code non_blocking(implementation_type& impl,
bool mode, asio::error_code& ec)
{
descriptor_ops::set_user_non_blocking(
impl.descriptor_, impl.state_, mode, ec);
ASIO_ERROR_LOCATION(ec);
return ec;
}
// Gets the non-blocking mode of the native descriptor implementation.
bool native_non_blocking(const implementation_type& impl) const
{
return (impl.state_ & descriptor_ops::internal_non_blocking) != 0;
}
// Sets the non-blocking mode of the native descriptor implementation.
asio::error_code native_non_blocking(implementation_type& impl,
bool mode, asio::error_code& ec)
{
descriptor_ops::set_internal_non_blocking(
impl.descriptor_, impl.state_, mode, ec);
ASIO_ERROR_LOCATION(ec);
return ec;
}
// Wait for the descriptor to become ready to read, ready to write, or to have
// pending error conditions.
asio::error_code wait(implementation_type& impl,
posix::descriptor_base::wait_type w, asio::error_code& ec)
{
switch (w)
{
case posix::descriptor_base::wait_read:
descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec);
break;
case posix::descriptor_base::wait_write:
descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec);
break;
case posix::descriptor_base::wait_error:
descriptor_ops::poll_error(impl.descriptor_, impl.state_, ec);
break;
default:
ec = asio::error::invalid_argument;
break;
}
ASIO_ERROR_LOCATION(ec);
return ec;
}
// Asynchronously wait for the descriptor to become ready to read, ready to
// write, or to have pending error conditions.
template <typename Handler, typename IoExecutor>
void async_wait(implementation_type& impl,
posix::descriptor_base::wait_type w,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
int op_type;
int poll_flags;
switch (w)
{
case posix::descriptor_base::wait_read:
op_type = io_uring_service::read_op;
poll_flags = POLLIN;
break;
case posix::descriptor_base::wait_write:
op_type = io_uring_service::write_op;
poll_flags = POLLOUT;
break;
case posix::descriptor_base::wait_error:
op_type = io_uring_service::except_op;
poll_flags = POLLPRI | POLLERR | POLLHUP;
break;
default:
op_type = -1;
poll_flags = -1;
return;
}
// Allocate and construct an operation to wrap the handler.
typedef io_uring_wait_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_,
poll_flags, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected() && op_type != -1)
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(
&io_uring_service_, &impl.io_object_data_, op_type);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"descriptor", &impl, impl.descriptor_, "async_wait"));
start_op(impl, op_type, p.p, is_continuation, op_type == -1);
p.v = p.p = 0;
}
// Write some data to the descriptor.
template <typename ConstBufferSequence>
size_t write_some(implementation_type& impl,
const ConstBufferSequence& buffers, asio::error_code& ec)
{
typedef buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs_type;
size_t n;
if (bufs_type::is_single_buffer)
{
n = descriptor_ops::sync_write1(impl.descriptor_,
impl.state_, bufs_type::first(buffers).data(),
bufs_type::first(buffers).size(), ec);
}
else
{
bufs_type bufs(buffers);
n = descriptor_ops::sync_write(impl.descriptor_, impl.state_,
bufs.buffers(), bufs.count(), bufs.all_empty(), ec);
}
ASIO_ERROR_LOCATION(ec);
return n;
}
// Wait until data can be written without blocking.
size_t write_some(implementation_type& impl,
const null_buffers&, asio::error_code& ec)
{
// Wait for descriptor to become ready.
descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec);
ASIO_ERROR_LOCATION(ec);
return 0;
}
// Start an asynchronous write. The data being sent must be valid for the
// lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_write_some(implementation_type& impl,
const ConstBufferSequence& buffers, Handler& handler,
const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_descriptor_write_op<
ConstBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_,
impl.state_, buffers, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::write_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"descriptor", &impl, impl.descriptor_, "async_write_some"));
start_op(impl, io_uring_service::write_op, p.p, is_continuation,
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence>::all_empty(buffers));
p.v = p.p = 0;
}
// Start an asynchronous wait until data can be written without blocking.
template <typename Handler, typename IoExecutor>
void async_write_some(implementation_type& impl,
const null_buffers&, Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_, POLLOUT, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::write_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(),
*p.p, "descriptor", &impl, impl.descriptor_,
"async_write_some(null_buffers)"));
start_op(impl, io_uring_service::write_op, p.p, is_continuation, false);
p.v = p.p = 0;
}
// Write some data to the descriptor at the specified offset.
template <typename ConstBufferSequence>
size_t write_some_at(implementation_type& impl, uint64_t offset,
const ConstBufferSequence& buffers, asio::error_code& ec)
{
typedef buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs_type;
size_t n;
if (bufs_type::is_single_buffer)
{
n = descriptor_ops::sync_write_at1(impl.descriptor_,
impl.state_, offset, bufs_type::first(buffers).data(),
bufs_type::first(buffers).size(), ec);
}
else
{
bufs_type bufs(buffers);
n = descriptor_ops::sync_write_at(impl.descriptor_, impl.state_,
offset, bufs.buffers(), bufs.count(), bufs.all_empty(), ec);
}
ASIO_ERROR_LOCATION(ec);
return n;
}
// Wait until data can be written without blocking.
size_t write_some_at(implementation_type& impl, uint64_t,
const null_buffers& buffers, asio::error_code& ec)
{
return write_some(impl, buffers, ec);
}
// Start an asynchronous write at the specified offset. The data being sent
// must be valid for the lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_write_some_at(implementation_type& impl, uint64_t offset,
const ConstBufferSequence& buffers, Handler& handler,
const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_descriptor_write_at_op<
ConstBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_,
impl.state_, offset, buffers, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::write_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"descriptor", &impl, impl.descriptor_, "async_write_some"));
start_op(impl, io_uring_service::write_op, p.p, is_continuation,
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence>::all_empty(buffers));
p.v = p.p = 0;
}
// Start an asynchronous wait until data can be written without blocking.
template <typename Handler, typename IoExecutor>
void async_write_some_at(implementation_type& impl,
const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex)
{
return async_write_some(impl, buffers, handler, io_ex);
}
// Read some data from the stream. Returns the number of bytes read.
template <typename MutableBufferSequence>
size_t read_some(implementation_type& impl,
const MutableBufferSequence& buffers, asio::error_code& ec)
{
typedef buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs_type;
size_t n;
if (bufs_type::is_single_buffer)
{
n = descriptor_ops::sync_read1(impl.descriptor_,
impl.state_, bufs_type::first(buffers).data(),
bufs_type::first(buffers).size(), ec);
}
else
{
bufs_type bufs(buffers);
n = descriptor_ops::sync_read(impl.descriptor_, impl.state_,
bufs.buffers(), bufs.count(), bufs.all_empty(), ec);
}
ASIO_ERROR_LOCATION(ec);
return n;
}
// Wait until data can be read without blocking.
size_t read_some(implementation_type& impl,
const null_buffers&, asio::error_code& ec)
{
// Wait for descriptor to become ready.
descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec);
ASIO_ERROR_LOCATION(ec);
return 0;
}
// Start an asynchronous read. The buffer for the data being read must be
// valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_read_some(implementation_type& impl,
const MutableBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_descriptor_read_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_,
impl.state_, buffers, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::read_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"descriptor", &impl, impl.descriptor_, "async_read_some"));
start_op(impl, io_uring_service::read_op, p.p, is_continuation,
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::all_empty(buffers));
p.v = p.p = 0;
}
// Wait until data can be read without blocking.
template <typename Handler, typename IoExecutor>
void async_read_some(implementation_type& impl,
const null_buffers&, Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_null_buffers_op<Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_, POLLIN, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::read_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(),
*p.p, "descriptor", &impl, impl.descriptor_,
"async_read_some(null_buffers)"));
start_op(impl, io_uring_service::read_op, p.p, is_continuation, false);
p.v = p.p = 0;
}
// Read some data at the specified offset. Returns the number of bytes read.
template <typename MutableBufferSequence>
size_t read_some_at(implementation_type& impl, uint64_t offset,
const MutableBufferSequence& buffers, asio::error_code& ec)
{
typedef buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs_type;
if (bufs_type::is_single_buffer)
{
return descriptor_ops::sync_read_at1(impl.descriptor_,
impl.state_, offset, bufs_type::first(buffers).data(),
bufs_type::first(buffers).size(), ec);
}
else
{
bufs_type bufs(buffers);
return descriptor_ops::sync_read_at(impl.descriptor_, impl.state_,
offset, bufs.buffers(), bufs.count(), bufs.all_empty(), ec);
}
}
// Wait until data can be read without blocking.
size_t read_some_at(implementation_type& impl, uint64_t,
const null_buffers& buffers, asio::error_code& ec)
{
return read_some(impl, buffers, ec);
}
// Start an asynchronous read. The buffer for the data being read must be
// valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_read_some_at(implementation_type& impl,
uint64_t offset, const MutableBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
bool is_continuation =
asio_handler_cont_helpers::is_continuation(handler);
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef io_uring_descriptor_read_at_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(success_ec_, impl.descriptor_,
impl.state_, offset, buffers, handler, io_ex);
// Optionally register for per-operation cancellation.
if (slot.is_connected())
{
p.p->cancellation_key_ =
&slot.template emplace<io_uring_op_cancellation>(&io_uring_service_,
&impl.io_object_data_, io_uring_service::read_op);
}
ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p,
"descriptor", &impl, impl.descriptor_, "async_read_some"));
start_op(impl, io_uring_service::read_op, p.p, is_continuation,
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::all_empty(buffers));
p.v = p.p = 0;
}
// Wait until data can be read without blocking.
template <typename Handler, typename IoExecutor>
void async_read_some_at(implementation_type& impl, uint64_t,
const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex)
{
return async_read_some(impl, buffers, handler, io_ex);
}
private:
// Start the asynchronous operation.
ASIO_DECL void start_op(implementation_type& impl, int op_type,
io_uring_operation* op, bool is_continuation, bool noop);
// Helper class used to implement per-operation cancellation
class io_uring_op_cancellation
{
public:
io_uring_op_cancellation(io_uring_service* s,
io_uring_service::per_io_object_data* p, int o)
: io_uring_service_(s),
io_object_data_(p),
op_type_(o)
{
}
void operator()(cancellation_type_t type)
{
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
io_uring_service_->cancel_ops_by_key(*io_object_data_, op_type_, this);
}
}
private:
io_uring_service* io_uring_service_;
io_uring_service::per_io_object_data* io_object_data_;
int op_type_;
};
// The io_uring_service that performs event demultiplexing for the service.
io_uring_service& io_uring_service_;
// Cached success value to avoid accessing category singleton.
const asio::error_code success_ec_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/io_uring_descriptor_service.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_DESCRIPTOR_SERVICE_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/reactive_socket_recvfrom_op.hpp | //
// detail/reactive_socket_recvfrom_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_REACTIVE_SOCKET_RECVFROM_OP_HPP
#define ASIO_DETAIL_REACTIVE_SOCKET_RECVFROM_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename MutableBufferSequence, typename Endpoint>
class reactive_socket_recvfrom_op_base : public reactor_op
{
public:
reactive_socket_recvfrom_op_base(const asio::error_code& success_ec,
socket_type socket, int protocol_type,
const MutableBufferSequence& buffers, Endpoint& endpoint,
socket_base::message_flags flags, func_type complete_func)
: reactor_op(success_ec,
&reactive_socket_recvfrom_op_base::do_perform, complete_func),
socket_(socket),
protocol_type_(protocol_type),
buffers_(buffers),
sender_endpoint_(endpoint),
flags_(flags)
{
}
static status do_perform(reactor_op* base)
{
ASIO_ASSUME(base != 0);
reactive_socket_recvfrom_op_base* o(
static_cast<reactive_socket_recvfrom_op_base*>(base));
typedef buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs_type;
std::size_t addr_len = o->sender_endpoint_.capacity();
status result;
if (bufs_type::is_single_buffer)
{
result = socket_ops::non_blocking_recvfrom1(
o->socket_, bufs_type::first(o->buffers_).data(),
bufs_type::first(o->buffers_).size(), o->flags_,
o->sender_endpoint_.data(), &addr_len,
o->ec_, o->bytes_transferred_) ? done : not_done;
}
else
{
bufs_type bufs(o->buffers_);
result = socket_ops::non_blocking_recvfrom(o->socket_,
bufs.buffers(), bufs.count(), o->flags_,
o->sender_endpoint_.data(), &addr_len,
o->ec_, o->bytes_transferred_) ? done : not_done;
}
if (result && !o->ec_)
o->sender_endpoint_.resize(addr_len);
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recvfrom",
o->ec_, o->bytes_transferred_));
return result;
}
private:
socket_type socket_;
int protocol_type_;
MutableBufferSequence buffers_;
Endpoint& sender_endpoint_;
socket_base::message_flags flags_;
};
template <typename MutableBufferSequence, typename Endpoint,
typename Handler, typename IoExecutor>
class reactive_socket_recvfrom_op :
public reactive_socket_recvfrom_op_base<MutableBufferSequence, Endpoint>
{
public:
typedef Handler handler_type;
typedef IoExecutor io_executor_type;
ASIO_DEFINE_HANDLER_PTR(reactive_socket_recvfrom_op);
reactive_socket_recvfrom_op(const asio::error_code& success_ec,
socket_type socket, int protocol_type,
const MutableBufferSequence& buffers, Endpoint& endpoint,
socket_base::message_flags flags, Handler& handler,
const IoExecutor& io_ex)
: reactive_socket_recvfrom_op_base<MutableBufferSequence, Endpoint>(
success_ec, socket, protocol_type, buffers, endpoint, flags,
&reactive_socket_recvfrom_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
reactive_socket_recvfrom_op* o(
static_cast<reactive_socket_recvfrom_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
static void do_immediate(operation* base, bool, const void* io_ex)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
reactive_socket_recvfrom_op* o(
static_cast<reactive_socket_recvfrom_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
immediate_handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_, io_ex);
ASIO_HANDLER_INVOCATION_END;
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_REACTIVE_SOCKET_RECVFROM_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/winsock_init.hpp | //
// detail/winsock_init.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WINSOCK_INIT_HPP
#define ASIO_DETAIL_WINSOCK_INIT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class winsock_init_base
{
protected:
// Structure to track result of initialisation and number of uses. POD is used
// to ensure that the values are zero-initialised prior to any code being run.
struct data
{
long init_count_;
long result_;
};
ASIO_DECL static void startup(data& d,
unsigned char major, unsigned char minor);
ASIO_DECL static void manual_startup(data& d);
ASIO_DECL static void cleanup(data& d);
ASIO_DECL static void manual_cleanup(data& d);
ASIO_DECL static void throw_on_error(data& d);
};
template <int Major = 2, int Minor = 2>
class winsock_init : private winsock_init_base
{
public:
winsock_init(bool allow_throw = true)
{
startup(data_, Major, Minor);
if (allow_throw)
throw_on_error(data_);
}
winsock_init(const winsock_init&)
{
startup(data_, Major, Minor);
throw_on_error(data_);
}
~winsock_init()
{
cleanup(data_);
}
// This class may be used to indicate that user code will manage Winsock
// initialisation and cleanup. This may be required in the case of a DLL, for
// example, where it is not safe to initialise Winsock from global object
// constructors.
//
// To prevent asio from initialising Winsock, the object must be constructed
// before any Asio's own global objects. With MSVC, this may be accomplished
// by adding the following code to the DLL:
//
// #pragma warning(push)
// #pragma warning(disable:4073)
// #pragma init_seg(lib)
// asio::detail::winsock_init<>::manual manual_winsock_init;
// #pragma warning(pop)
class manual
{
public:
manual()
{
manual_startup(data_);
}
manual(const manual&)
{
manual_startup(data_);
}
~manual()
{
manual_cleanup(data_);
}
};
private:
friend class manual;
static data data_;
};
template <int Major, int Minor>
winsock_init_base::data winsock_init<Major, Minor>::data_;
// Static variable to ensure that winsock is initialised before main, and
// therefore before any other threads can get started.
static const winsock_init<>& winsock_init_instance = winsock_init<>(false);
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/winsock_init.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
#endif // ASIO_DETAIL_WINSOCK_INIT_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/scoped_lock.hpp | //
// detail/scoped_lock.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SCOPED_LOCK_HPP
#define ASIO_DETAIL_SCOPED_LOCK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
// Helper class to lock and unlock a mutex automatically.
template <typename Mutex>
class scoped_lock
: private noncopyable
{
public:
// Tag type used to distinguish constructors.
enum adopt_lock_t { adopt_lock };
// Constructor adopts a lock that is already held.
scoped_lock(Mutex& m, adopt_lock_t)
: mutex_(m),
locked_(true)
{
}
// Constructor acquires the lock.
explicit scoped_lock(Mutex& m)
: mutex_(m)
{
mutex_.lock();
locked_ = true;
}
// Destructor releases the lock.
~scoped_lock()
{
if (locked_)
mutex_.unlock();
}
// Explicitly acquire the lock.
void lock()
{
if (!locked_)
{
mutex_.lock();
locked_ = true;
}
}
// Explicitly release the lock.
void unlock()
{
if (locked_)
{
mutex_.unlock();
locked_ = false;
}
}
// Test whether the lock is held.
bool locked() const
{
return locked_;
}
// Get the underlying mutex.
Mutex& mutex()
{
return mutex_;
}
private:
// The underlying mutex.
Mutex& mutex_;
// Whether the mutex is currently locked or unlocked.
bool locked_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_SCOPED_LOCK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_socket_connect_op.hpp | //
// detail/io_uring_socket_connect_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP
#define ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IO_URING)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Protocol>
class io_uring_socket_connect_op_base : public io_uring_operation
{
public:
io_uring_socket_connect_op_base(const asio::error_code& success_ec,
socket_type socket, const typename Protocol::endpoint& endpoint,
func_type complete_func)
: io_uring_operation(success_ec,
&io_uring_socket_connect_op_base::do_prepare,
&io_uring_socket_connect_op_base::do_perform, complete_func),
socket_(socket),
endpoint_(endpoint)
{
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_socket_connect_op_base* o(
static_cast<io_uring_socket_connect_op_base*>(base));
::io_uring_prep_connect(sqe, o->socket_,
static_cast<sockaddr*>(o->endpoint_.data()),
static_cast<socklen_t>(o->endpoint_.size()));
}
static bool do_perform(io_uring_operation*, bool after_completion)
{
return after_completion;
}
private:
socket_type socket_;
typename Protocol::endpoint endpoint_;
};
template <typename Protocol, typename Handler, typename IoExecutor>
class io_uring_socket_connect_op :
public io_uring_socket_connect_op_base<Protocol>
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_socket_connect_op);
io_uring_socket_connect_op(const asio::error_code& success_ec,
socket_type socket, const typename Protocol::endpoint& endpoint,
Handler& handler, const IoExecutor& io_ex)
: io_uring_socket_connect_op_base<Protocol>(success_ec, socket,
endpoint, &io_uring_socket_connect_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_socket_connect_op* o
(static_cast<io_uring_socket_connect_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder1<Handler, asio::error_code>
handler(o->handler_, o->ec_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_HAS_IO_URING)
#endif // ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/array.hpp | //
// detail/array.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_ARRAY_HPP
#define ASIO_DETAIL_ARRAY_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <array>
namespace asio {
namespace detail {
using std::array;
} // namespace detail
} // namespace asio
#endif // ASIO_DETAIL_ARRAY_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/functional.hpp | //
// detail/functional.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_FUNCTIONAL_HPP
#define ASIO_DETAIL_FUNCTIONAL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include <functional>
namespace asio {
namespace detail {
using std::function;
} // namespace detail
using std::ref;
using std::reference_wrapper;
} // namespace asio
#endif // ASIO_DETAIL_FUNCTIONAL_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/winrt_socket_connect_op.hpp | //
// detail/winrt_socket_connect_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WINRT_SOCKET_CONNECT_OP_HPP
#define ASIO_DETAIL_WINRT_SOCKET_CONNECT_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_WINDOWS_RUNTIME)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/winrt_async_op.hpp"
#include "asio/error.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Handler, typename IoExecutor>
class winrt_socket_connect_op :
public winrt_async_op<void>
{
public:
ASIO_DEFINE_HANDLER_PTR(winrt_socket_connect_op);
winrt_socket_connect_op(Handler& handler, const IoExecutor& io_ex)
: winrt_async_op<void>(&winrt_socket_connect_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code&, std::size_t)
{
// Take ownership of the operation object.
ASIO_ASSUME(base != 0);
winrt_socket_connect_op* o(static_cast<winrt_socket_connect_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder1<Handler, asio::error_code>
handler(o->handler_, o->ec_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> executor_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // defined(ASIO_WINDOWS_RUNTIME)
#endif // ASIO_DETAIL_WINRT_SOCKET_CONNECT_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_global.hpp | //
// detail/win_global.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_GLOBAL_HPP
#define ASIO_DETAIL_WIN_GLOBAL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/static_mutex.hpp"
#include "asio/detail/tss_ptr.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename T>
struct win_global_impl
{
// Destructor automatically cleans up the global.
~win_global_impl()
{
delete ptr_;
}
static win_global_impl instance_;
static static_mutex mutex_;
T* ptr_;
static tss_ptr<T> tss_ptr_;
};
template <typename T>
win_global_impl<T> win_global_impl<T>::instance_ = { 0 };
template <typename T>
static_mutex win_global_impl<T>::mutex_ = ASIO_STATIC_MUTEX_INIT;
template <typename T>
tss_ptr<T> win_global_impl<T>::tss_ptr_;
template <typename T>
T& win_global()
{
if (static_cast<T*>(win_global_impl<T>::tss_ptr_) == 0)
{
win_global_impl<T>::mutex_.init();
static_mutex::scoped_lock lock(win_global_impl<T>::mutex_);
if (win_global_impl<T>::instance_.ptr_ == 0)
win_global_impl<T>::instance_.ptr_ = new T;
win_global_impl<T>::tss_ptr_ = win_global_impl<T>::instance_.ptr_;
}
return *win_global_impl<T>::tss_ptr_;
}
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_WIN_GLOBAL_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/reactive_socket_recvmsg_op.hpp | //
// detail/reactive_socket_recvmsg_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP
#define ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/socket_base.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename MutableBufferSequence>
class reactive_socket_recvmsg_op_base : public reactor_op
{
public:
reactive_socket_recvmsg_op_base(const asio::error_code& success_ec,
socket_type socket, const MutableBufferSequence& buffers,
socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, func_type complete_func)
: reactor_op(success_ec,
&reactive_socket_recvmsg_op_base::do_perform, complete_func),
socket_(socket),
buffers_(buffers),
in_flags_(in_flags),
out_flags_(out_flags)
{
}
static status do_perform(reactor_op* base)
{
ASIO_ASSUME(base != 0);
reactive_socket_recvmsg_op_base* o(
static_cast<reactive_socket_recvmsg_op_base*>(base));
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence> bufs(o->buffers_);
status result = socket_ops::non_blocking_recvmsg(o->socket_,
bufs.buffers(), bufs.count(),
o->in_flags_, o->out_flags_,
o->ec_, o->bytes_transferred_) ? done : not_done;
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recvmsg",
o->ec_, o->bytes_transferred_));
return result;
}
private:
socket_type socket_;
MutableBufferSequence buffers_;
socket_base::message_flags in_flags_;
socket_base::message_flags& out_flags_;
};
template <typename MutableBufferSequence, typename Handler, typename IoExecutor>
class reactive_socket_recvmsg_op :
public reactive_socket_recvmsg_op_base<MutableBufferSequence>
{
public:
typedef Handler handler_type;
typedef IoExecutor io_executor_type;
ASIO_DEFINE_HANDLER_PTR(reactive_socket_recvmsg_op);
reactive_socket_recvmsg_op(const asio::error_code& success_ec,
socket_type socket, const MutableBufferSequence& buffers,
socket_base::message_flags in_flags,
socket_base::message_flags& out_flags, Handler& handler,
const IoExecutor& io_ex)
: reactive_socket_recvmsg_op_base<MutableBufferSequence>(
success_ec, socket, buffers, in_flags, out_flags,
&reactive_socket_recvmsg_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
reactive_socket_recvmsg_op* o(
static_cast<reactive_socket_recvmsg_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
static void do_immediate(operation* base, bool, const void* io_ex)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
reactive_socket_recvmsg_op* o(
static_cast<reactive_socket_recvmsg_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
immediate_handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_, io_ex);
ASIO_HANDLER_INVOCATION_END;
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_object_impl.hpp | //
// detail/io_object_impl.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_OBJECT_IMPL_HPP
#define ASIO_DETAIL_IO_OBJECT_IMPL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <new>
#include "asio/detail/config.hpp"
#include "asio/detail/type_traits.hpp"
#include "asio/execution/executor.hpp"
#include "asio/execution/context.hpp"
#include "asio/io_context.hpp"
#include "asio/query.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename IoObjectService,
typename Executor = io_context::executor_type>
class io_object_impl
{
public:
// The type of the service that will be used to provide I/O operations.
typedef IoObjectService service_type;
// The underlying implementation type of I/O object.
typedef typename service_type::implementation_type implementation_type;
// The type of the executor associated with the object.
typedef Executor executor_type;
// Construct an I/O object using an executor.
explicit io_object_impl(int, const executor_type& ex)
: service_(&asio::use_service<IoObjectService>(
io_object_impl::get_context(ex))),
executor_(ex)
{
service_->construct(implementation_);
}
// Construct an I/O object using an execution context.
template <typename ExecutionContext>
explicit io_object_impl(int, int, ExecutionContext& context)
: service_(&asio::use_service<IoObjectService>(context)),
executor_(context.get_executor())
{
service_->construct(implementation_);
}
// Move-construct an I/O object.
io_object_impl(io_object_impl&& other)
: service_(&other.get_service()),
executor_(other.get_executor())
{
service_->move_construct(implementation_, other.implementation_);
}
// Perform converting move-construction of an I/O object on the same service.
template <typename Executor1>
io_object_impl(io_object_impl<IoObjectService, Executor1>&& other)
: service_(&other.get_service()),
executor_(other.get_executor())
{
service_->move_construct(implementation_, other.get_implementation());
}
// Perform converting move-construction of an I/O object on another service.
template <typename IoObjectService1, typename Executor1>
io_object_impl(io_object_impl<IoObjectService1, Executor1>&& other)
: service_(&asio::use_service<IoObjectService>(
io_object_impl::get_context(other.get_executor()))),
executor_(other.get_executor())
{
service_->converting_move_construct(implementation_,
other.get_service(), other.get_implementation());
}
// Destructor.
~io_object_impl()
{
service_->destroy(implementation_);
}
// Move-assign an I/O object.
io_object_impl& operator=(io_object_impl&& other)
{
if (this != &other)
{
service_->move_assign(implementation_,
*other.service_, other.implementation_);
executor_.~executor_type();
new (&executor_) executor_type(other.executor_);
service_ = other.service_;
}
return *this;
}
// Get the executor associated with the object.
const executor_type& get_executor() noexcept
{
return executor_;
}
// Get the service associated with the I/O object.
service_type& get_service()
{
return *service_;
}
// Get the service associated with the I/O object.
const service_type& get_service() const
{
return *service_;
}
// Get the underlying implementation of the I/O object.
implementation_type& get_implementation()
{
return implementation_;
}
// Get the underlying implementation of the I/O object.
const implementation_type& get_implementation() const
{
return implementation_;
}
private:
// Helper function to get an executor's context.
template <typename T>
static execution_context& get_context(const T& t,
enable_if_t<execution::is_executor<T>::value>* = 0)
{
return asio::query(t, execution::context);
}
// Helper function to get an executor's context.
template <typename T>
static execution_context& get_context(const T& t,
enable_if_t<!execution::is_executor<T>::value>* = 0)
{
return t.context();
}
// Disallow copying and copy assignment.
io_object_impl(const io_object_impl&);
io_object_impl& operator=(const io_object_impl&);
// The service associated with the I/O object.
service_type* service_;
// The underlying implementation of the I/O object.
implementation_type implementation_;
// The associated executor.
executor_type executor_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_IO_OBJECT_IMPL_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/io_uring_wait_op.hpp | //
// detail/io_uring_wait_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_IO_URING_WAIT_OP_HPP
#define ASIO_DETAIL_IO_URING_WAIT_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/io_uring_operation.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename Handler, typename IoExecutor>
class io_uring_wait_op : public io_uring_operation
{
public:
ASIO_DEFINE_HANDLER_PTR(io_uring_wait_op);
io_uring_wait_op(const asio::error_code& success_ec, int descriptor,
int poll_flags, Handler& handler, const IoExecutor& io_ex)
: io_uring_operation(success_ec, &io_uring_wait_op::do_prepare,
&io_uring_wait_op::do_perform, &io_uring_wait_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex),
descriptor_(descriptor),
poll_flags_(poll_flags)
{
}
static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
{
ASIO_ASSUME(base != 0);
io_uring_wait_op* o(static_cast<io_uring_wait_op*>(base));
::io_uring_prep_poll_add(sqe, o->descriptor_, o->poll_flags_);
}
static bool do_perform(io_uring_operation*, bool after_completion)
{
return after_completion;
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
io_uring_wait_op* o(static_cast<io_uring_wait_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder1<Handler, asio::error_code>
handler(o->handler_, o->ec_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
int descriptor_;
int poll_flags_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_IO_URING_WAIT_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/scheduler_task.hpp | //
// detail/scheduler_task.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SCHEDULER_TASK_HPP
#define ASIO_DETAIL_SCHEDULER_TASK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/op_queue.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class scheduler_operation;
// Base class for all tasks that may be run by a scheduler.
class scheduler_task
{
public:
// Run the task once until interrupted or events are ready to be dispatched.
virtual void run(long usec, op_queue<scheduler_operation>& ops) = 0;
// Interrupt the task.
virtual void interrupt() = 0;
protected:
// Prevent deletion through this type.
~scheduler_task()
{
}
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_SCHEDULER_TASK_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/scheduler_thread_info.hpp | //
// detail/scheduler_thread_info.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_SCHEDULER_THREAD_INFO_HPP
#define ASIO_DETAIL_SCHEDULER_THREAD_INFO_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/op_queue.hpp"
#include "asio/detail/thread_info_base.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class scheduler;
class scheduler_operation;
struct scheduler_thread_info : public thread_info_base
{
op_queue<scheduler_operation> private_op_queue;
long private_outstanding_work;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // ASIO_DETAIL_SCHEDULER_THREAD_INFO_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/descriptor_write_op.hpp | //
// detail/descriptor_write_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
#define ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/descriptor_ops.hpp"
#include "asio/detail/fenced_block.hpp"
#include "asio/detail/handler_work.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
template <typename ConstBufferSequence>
class descriptor_write_op_base : public reactor_op
{
public:
descriptor_write_op_base(const asio::error_code& success_ec,
int descriptor, const ConstBufferSequence& buffers,
func_type complete_func)
: reactor_op(success_ec,
&descriptor_write_op_base::do_perform, complete_func),
descriptor_(descriptor),
buffers_(buffers)
{
}
static status do_perform(reactor_op* base)
{
ASIO_ASSUME(base != 0);
descriptor_write_op_base* o(static_cast<descriptor_write_op_base*>(base));
typedef buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs_type;
status result;
if (bufs_type::is_single_buffer)
{
result = descriptor_ops::non_blocking_write1(o->descriptor_,
bufs_type::first(o->buffers_).data(),
bufs_type::first(o->buffers_).size(),
o->ec_, o->bytes_transferred_) ? done : not_done;
}
else
{
bufs_type bufs(o->buffers_);
result = descriptor_ops::non_blocking_write(o->descriptor_,
bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_)
? done : not_done;
}
ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_write",
o->ec_, o->bytes_transferred_));
return result;
}
private:
int descriptor_;
ConstBufferSequence buffers_;
};
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
class descriptor_write_op
: public descriptor_write_op_base<ConstBufferSequence>
{
public:
typedef Handler handler_type;
typedef IoExecutor io_executor_type;
ASIO_DEFINE_HANDLER_PTR(descriptor_write_op);
descriptor_write_op(const asio::error_code& success_ec,
int descriptor, const ConstBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
: descriptor_write_op_base<ConstBufferSequence>(success_ec,
descriptor, buffers, &descriptor_write_op::do_complete),
handler_(static_cast<Handler&&>(handler)),
work_(handler_, io_ex)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& /*ec*/,
std::size_t /*bytes_transferred*/)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
descriptor_write_op* o(static_cast<descriptor_write_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
// Make the upcall if required.
if (owner)
{
fenced_block b(fenced_block::half);
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_);
ASIO_HANDLER_INVOCATION_END;
}
}
static void do_immediate(operation* base, bool, const void* io_ex)
{
// Take ownership of the handler object.
ASIO_ASSUME(base != 0);
descriptor_write_op* o(static_cast<descriptor_write_op*>(base));
ptr p = { asio::detail::addressof(o->handler_), o, o };
ASIO_HANDLER_COMPLETION((*o));
// Take ownership of the operation's outstanding work.
immediate_handler_work<Handler, IoExecutor> w(
static_cast<handler_work<Handler, IoExecutor>&&>(
o->work_));
ASIO_ERROR_LOCATION(o->ec_);
// Make a copy of the handler so that the memory can be deallocated before
// the upcall is made. Even if we're not about to make an upcall, a
// sub-object of the handler may be the true owner of the memory associated
// with the handler. Consequently, a local copy of the handler is required
// to ensure that any owning sub-object remains valid until after we have
// deallocated the memory here.
detail::binder2<Handler, asio::error_code, std::size_t>
handler(o->handler_, o->ec_, o->bytes_transferred_);
p.h = asio::detail::addressof(handler.handler_);
p.reset();
ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
w.complete(handler, handler.handler_, io_ex);
ASIO_HANDLER_INVOCATION_END;
}
private:
Handler handler_;
handler_work<Handler, IoExecutor> work_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
#endif // ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
|
0 | repos/asio/asio/include/asio | repos/asio/asio/include/asio/detail/win_iocp_handle_service.hpp | //
// detail/win_iocp_handle_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef ASIO_DETAIL_WIN_IOCP_HANDLE_SERVICE_HPP
#define ASIO_DETAIL_WIN_IOCP_HANDLE_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
#if defined(ASIO_HAS_IOCP)
#include "asio/associated_cancellation_slot.hpp"
#include "asio/error.hpp"
#include "asio/execution_context.hpp"
#include "asio/detail/buffer_sequence_adapter.hpp"
#include "asio/detail/cstdint.hpp"
#include "asio/detail/handler_alloc_helpers.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/operation.hpp"
#include "asio/detail/win_iocp_handle_read_op.hpp"
#include "asio/detail/win_iocp_handle_write_op.hpp"
#include "asio/detail/win_iocp_io_context.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
namespace detail {
class win_iocp_handle_service :
public execution_context_service_base<win_iocp_handle_service>
{
public:
// The native type of a stream handle.
typedef HANDLE native_handle_type;
// The implementation type of the stream handle.
class implementation_type
{
public:
// Default constructor.
implementation_type()
: handle_(INVALID_HANDLE_VALUE),
safe_cancellation_thread_id_(0),
next_(0),
prev_(0)
{
}
private:
// Only this service will have access to the internal values.
friend class win_iocp_handle_service;
// The native stream handle representation.
native_handle_type handle_;
// The ID of the thread from which it is safe to cancel asynchronous
// operations. 0 means no asynchronous operations have been started yet.
// ~0 means asynchronous operations have been started from more than one
// thread, and cancellation is not supported for the handle.
DWORD safe_cancellation_thread_id_;
// Pointers to adjacent handle implementations in linked list.
implementation_type* next_;
implementation_type* prev_;
};
ASIO_DECL win_iocp_handle_service(execution_context& context);
// Destroy all user-defined handler objects owned by the service.
ASIO_DECL void shutdown();
// Construct a new handle implementation.
ASIO_DECL void construct(implementation_type& impl);
// Move-construct a new handle implementation.
ASIO_DECL void move_construct(implementation_type& impl,
implementation_type& other_impl);
// Move-assign from another handle implementation.
ASIO_DECL void move_assign(implementation_type& impl,
win_iocp_handle_service& other_service,
implementation_type& other_impl);
// Destroy a handle implementation.
ASIO_DECL void destroy(implementation_type& impl);
// Assign a native handle to a handle implementation.
ASIO_DECL asio::error_code assign(implementation_type& impl,
const native_handle_type& handle, asio::error_code& ec);
// Determine whether the handle is open.
bool is_open(const implementation_type& impl) const
{
return impl.handle_ != INVALID_HANDLE_VALUE;
}
// Destroy a handle implementation.
ASIO_DECL asio::error_code close(implementation_type& impl,
asio::error_code& ec);
// Release ownership of a handle.
ASIO_DECL native_handle_type release(implementation_type& impl,
asio::error_code& ec);
// Get the native handle representation.
native_handle_type native_handle(const implementation_type& impl) const
{
return impl.handle_;
}
// Cancel all operations associated with the handle.
ASIO_DECL asio::error_code cancel(implementation_type& impl,
asio::error_code& ec);
// Write the given data. Returns the number of bytes written.
template <typename ConstBufferSequence>
size_t write_some(implementation_type& impl,
const ConstBufferSequence& buffers, asio::error_code& ec)
{
return write_some_at(impl, 0, buffers, ec);
}
// Write the given data at the specified offset. Returns the number of bytes
// written.
template <typename ConstBufferSequence>
size_t write_some_at(implementation_type& impl, uint64_t offset,
const ConstBufferSequence& buffers, asio::error_code& ec)
{
asio::const_buffer buffer =
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence>::first(buffers);
return do_write(impl, offset, buffer, ec);
}
// Start an asynchronous write. The data being written must be valid for the
// lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_write_some(implementation_type& impl,
const ConstBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_handle_write_op<
ConstBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(buffers, handler, io_ex);
ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl,
reinterpret_cast<uintmax_t>(impl.handle_), "async_write_some"));
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o);
start_write_op(impl, 0,
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence>::first(buffers), o);
p.v = p.p = 0;
}
// Start an asynchronous write at a specified offset. The data being written
// must be valid for the lifetime of the asynchronous operation.
template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
void async_write_some_at(implementation_type& impl,
uint64_t offset, const ConstBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_handle_write_op<
ConstBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(buffers, handler, io_ex);
ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl,
reinterpret_cast<uintmax_t>(impl.handle_), "async_write_some_at"));
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o);
start_write_op(impl, offset,
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence>::first(buffers), o);
p.v = p.p = 0;
}
// Read some data. Returns the number of bytes received.
template <typename MutableBufferSequence>
size_t read_some(implementation_type& impl,
const MutableBufferSequence& buffers, asio::error_code& ec)
{
return read_some_at(impl, 0, buffers, ec);
}
// Read some data at a specified offset. Returns the number of bytes received.
template <typename MutableBufferSequence>
size_t read_some_at(implementation_type& impl, uint64_t offset,
const MutableBufferSequence& buffers, asio::error_code& ec)
{
asio::mutable_buffer buffer =
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::first(buffers);
return do_read(impl, offset, buffer, ec);
}
// Start an asynchronous read. The buffer for the data being received must be
// valid for the lifetime of the asynchronous operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_read_some(implementation_type& impl,
const MutableBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_handle_read_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(buffers, handler, io_ex);
ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl,
reinterpret_cast<uintmax_t>(impl.handle_), "async_read_some"));
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o);
start_read_op(impl, 0,
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::first(buffers), o);
p.v = p.p = 0;
}
// Start an asynchronous read at a specified offset. The buffer for the data
// being received must be valid for the lifetime of the asynchronous
// operation.
template <typename MutableBufferSequence,
typename Handler, typename IoExecutor>
void async_read_some_at(implementation_type& impl,
uint64_t offset, const MutableBufferSequence& buffers,
Handler& handler, const IoExecutor& io_ex)
{
associated_cancellation_slot_t<Handler> slot
= asio::get_associated_cancellation_slot(handler);
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_handle_read_op<
MutableBufferSequence, Handler, IoExecutor> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
operation* o = p.p = new (p.v) op(buffers, handler, io_ex);
ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl,
reinterpret_cast<uintmax_t>(impl.handle_), "async_read_some_at"));
// Optionally register for per-operation cancellation.
if (slot.is_connected())
o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o);
start_read_op(impl, offset,
buffer_sequence_adapter<asio::mutable_buffer,
MutableBufferSequence>::first(buffers), o);
p.v = p.p = 0;
}
private:
// Prevent the use of the null_buffers type with this service.
size_t write_some(implementation_type& impl,
const null_buffers& buffers, asio::error_code& ec);
size_t write_some_at(implementation_type& impl, uint64_t offset,
const null_buffers& buffers, asio::error_code& ec);
template <typename Handler, typename IoExecutor>
void async_write_some(implementation_type& impl,
const null_buffers& buffers, Handler& handler,
const IoExecutor& io_ex);
template <typename Handler, typename IoExecutor>
void async_write_some_at(implementation_type& impl, uint64_t offset,
const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex);
size_t read_some(implementation_type& impl,
const null_buffers& buffers, asio::error_code& ec);
size_t read_some_at(implementation_type& impl, uint64_t offset,
const null_buffers& buffers, asio::error_code& ec);
template <typename Handler, typename IoExecutor>
void async_read_some(implementation_type& impl,
const null_buffers& buffers, Handler& handler,
const IoExecutor& io_ex);
template <typename Handler, typename IoExecutor>
void async_read_some_at(implementation_type& impl, uint64_t offset,
const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex);
// Helper class for waiting for synchronous operations to complete.
class overlapped_wrapper;
// Helper function to perform a synchronous write operation.
ASIO_DECL size_t do_write(implementation_type& impl,
uint64_t offset, const asio::const_buffer& buffer,
asio::error_code& ec);
// Helper function to start a write operation.
ASIO_DECL void start_write_op(implementation_type& impl,
uint64_t offset, const asio::const_buffer& buffer,
operation* op);
// Helper function to perform a synchronous write operation.
ASIO_DECL size_t do_read(implementation_type& impl,
uint64_t offset, const asio::mutable_buffer& buffer,
asio::error_code& ec);
// Helper function to start a read operation.
ASIO_DECL void start_read_op(implementation_type& impl,
uint64_t offset, const asio::mutable_buffer& buffer,
operation* op);
// Update the ID of the thread from which cancellation is safe.
ASIO_DECL void update_cancellation_thread_id(implementation_type& impl);
// Helper function to close a handle when the associated object is being
// destroyed.
ASIO_DECL void close_for_destruction(implementation_type& impl);
// The type of a NtSetInformationFile function pointer.
typedef LONG (NTAPI *nt_set_info_fn)(HANDLE, ULONG_PTR*, void*, ULONG, ULONG);
// Helper function to get the NtSetInformationFile function pointer. If no
// NtSetInformationFile pointer has been obtained yet, one is obtained using
// GetProcAddress and the pointer is cached. Returns a null pointer if
// NtSetInformationFile is not available.
ASIO_DECL nt_set_info_fn get_nt_set_info();
// Helper function to emulate InterlockedCompareExchangePointer functionality
// for:
// - very old Platform SDKs; and
// - platform SDKs where MSVC's /Wp64 option causes spurious warnings.
ASIO_DECL void* interlocked_compare_exchange_pointer(
void** dest, void* exch, void* cmp);
// Helper function to emulate InterlockedExchangePointer functionality for:
// - very old Platform SDKs; and
// - platform SDKs where MSVC's /Wp64 option causes spurious warnings.
ASIO_DECL void* interlocked_exchange_pointer(void** dest, void* val);
// Helper class used to implement per operation cancellation.
class iocp_op_cancellation : public operation
{
public:
iocp_op_cancellation(HANDLE h, operation* target)
: operation(&iocp_op_cancellation::do_complete),
handle_(h),
target_(target)
{
}
static void do_complete(void* owner, operation* base,
const asio::error_code& result_ec,
std::size_t bytes_transferred)
{
iocp_op_cancellation* o = static_cast<iocp_op_cancellation*>(base);
o->target_->complete(owner, result_ec, bytes_transferred);
}
void operator()(cancellation_type_t type)
{
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
if (!!(type &
(cancellation_type::terminal
| cancellation_type::partial
| cancellation_type::total)))
{
::CancelIoEx(handle_, this);
}
#else // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
(void)type;
#endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
}
private:
HANDLE handle_;
operation* target_;
};
// The IOCP service used for running asynchronous operations and dispatching
// handlers.
win_iocp_io_context& iocp_service_;
// Pointer to NtSetInformationFile implementation.
void* nt_set_info_;
// Mutex to protect access to the linked list of implementations.
mutex mutex_;
// The head of a linked list of all implementations.
implementation_type* impl_list_;
};
} // namespace detail
} // namespace asio
#include "asio/detail/pop_options.hpp"
#if defined(ASIO_HEADER_ONLY)
# include "asio/detail/impl/win_iocp_handle_service.ipp"
#endif // defined(ASIO_HEADER_ONLY)
#endif // defined(ASIO_HAS_IOCP)
#endif // ASIO_DETAIL_WIN_IOCP_HANDLE_SERVICE_HPP
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.