repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP #define BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) #if defined(BOOST_ASIO_WINDOWS) \ || defined(__CYGWIN__) \ || defined(__SYMBIAN32__) #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class socket_select_interrupter { public: // Constructor. BOOST_ASIO_DECL socket_select_interrupter(); // Destructor. BOOST_ASIO_DECL ~socket_select_interrupter(); // Recreate the interrupter's descriptors. Used after a fork. BOOST_ASIO_DECL void recreate(); // Interrupt the select call. BOOST_ASIO_DECL void interrupt(); // Reset the select interrupter. Returns true if the reset was successful. BOOST_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. BOOST_ASIO_DECL void open_descriptors(); // Close the descriptors. BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/socket_select_interrupter.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) // || defined(__CYGWIN__) // || defined(__SYMBIAN32__) #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVFROM_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVFROM_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 boost::system::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) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_recvfrom_op_base* o( static_cast<reactive_socket_recvfrom_op_base*>(base)); typedef buffer_sequence_adapter<boost::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); BOOST_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; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_recvfrom_op); reactive_socket_recvfrom_op(const boost::system::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 boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_recvfrom_op* o( static_cast<reactive_socket_recvfrom_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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_)); BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_recvfrom_op* o( static_cast<reactive_socket_recvfrom_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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_)); BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_, io_ex); BOOST_ASIO_HANDLER_INVOCATION_END; } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVFROM_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_STD_FENCED_BLOCK_HPP #define BOOST_ASIO_DETAIL_STD_FENCED_BLOCK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <atomic> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_STD_FENCED_BLOCK_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_recvmsg_op.hpp
// // detail/io_uring_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 BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECVMSG_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECVMSG_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IO_URING) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/io_uring_operation.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence> class io_uring_socket_recvmsg_op_base : public io_uring_operation { public: io_uring_socket_recvmsg_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const MutableBufferSequence& buffers, socket_base::message_flags in_flags, socket_base::message_flags& out_flags, func_type complete_func) : io_uring_operation(success_ec, &io_uring_socket_recvmsg_op_base::do_prepare, &io_uring_socket_recvmsg_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), in_flags_(in_flags), out_flags_(out_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) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recvmsg_op_base* o( static_cast<io_uring_socket_recvmsg_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { bool except_op = (o->in_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->in_flags_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recvmsg_op_base* o( static_cast<io_uring_socket_recvmsg_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { bool except_op = (o->in_flags_ & socket_base::message_out_of_band) != 0; if (after_completion || !except_op) { return socket_ops::non_blocking_recvmsg(o->socket_, o->bufs_.buffers(), o->bufs_.count(), o->in_flags_, o->out_flags_, o->ec_, o->bytes_transferred_); } } else if (after_completion) { if (!o->ec_) o->out_flags_ = o->msghdr_.msg_flags; else o->out_flags_ = 0; } if (o->ec_ && o->ec_ == boost::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 in_flags_; socket_base::message_flags& out_flags_; buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_; msghdr msghdr_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class io_uring_socket_recvmsg_op : public io_uring_socket_recvmsg_op_base<MutableBufferSequence> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_recvmsg_op); io_uring_socket_recvmsg_op(const boost::system::error_code& success_ec, int socket, socket_ops::state_type state, const MutableBufferSequence& buffers, socket_base::message_flags in_flags, socket_base::message_flags& out_flags, Handler& handler, const IoExecutor& io_ex) : io_uring_socket_recvmsg_op_base<MutableBufferSequence>(success_ec, socket, state, buffers, in_flags, out_flags, &io_uring_socket_recvmsg_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recvmsg_op* o (static_cast<io_uring_socket_recvmsg_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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_)); BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECVMSG_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/operation.hpp
// // detail/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 BOOST_ASIO_DETAIL_OPERATION_HPP #define BOOST_ASIO_DETAIL_OPERATION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_operation.hpp> #else # include <boost/asio/detail/scheduler_operation.hpp> #endif namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_HAS_IOCP) typedef win_iocp_operation operation; #else typedef scheduler_operation operation; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_OPERATION_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_BASE_HPP #define BOOST_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 <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/socket_base.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/select_reactor.hpp> #include <boost/asio/detail/socket_holder.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/win_iocp_io_context.hpp> #include <boost/asio/detail/win_iocp_null_buffers_op.hpp> #include <boost/asio/detail/win_iocp_socket_connect_op.hpp> #include <boost/asio/detail/win_iocp_socket_send_op.hpp> #include <boost/asio/detail/win_iocp_socket_recv_op.hpp> #include <boost/asio/detail/win_iocp_socket_recvmsg_op.hpp> #include <boost/asio/detail/win_iocp_wait_op.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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(BOOST_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(BOOST_ASIO_ENABLE_CANCELIO) // Pointers to adjacent socket implementations in linked list. base_implementation_type* next_; base_implementation_type* prev_; }; // Constructor. BOOST_ASIO_DECL win_iocp_socket_service_base(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void base_shutdown(); // Construct a new socket implementation. BOOST_ASIO_DECL void construct(base_implementation_type& impl); // Move-construct a new socket implementation. BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl, base_implementation_type& other_impl) noexcept; // Move-assign from another socket implementation. BOOST_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. BOOST_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. BOOST_ASIO_DECL boost::system::error_code close( base_implementation_type& impl, boost::system::error_code& ec); // Release ownership of the socket. BOOST_ASIO_DECL socket_type release( base_implementation_type& impl, boost::system::error_code& ec); // Cancel all operations associated with the socket. BOOST_ASIO_DECL boost::system::error_code cancel( base_implementation_type& impl, boost::system::error_code& ec); // Determine whether the socket is at the out-of-band data mark. bool at_mark(const base_implementation_type& impl, boost::system::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, boost::system::error_code& ec) const { return socket_ops::available(impl.socket_, ec); } // Place the socket into the state where it will listen for new connections. boost::system::error_code listen(base_implementation_type& impl, int backlog, boost::system::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> boost::system::error_code io_control(base_implementation_type& impl, IO_Control_Command& command, boost::system::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. boost::system::error_code non_blocking(base_implementation_type& impl, bool mode, boost::system::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. boost::system::error_code native_non_blocking(base_implementation_type& impl, bool mode, boost::system::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. boost::system::error_code wait(base_implementation_type& impl, socket_base::wait_type w, boost::system::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 = boost::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 = boost::asio::get_associated_cancellation_slot(handler); bool is_continuation = boost_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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(impl.cancel_token_, handler, io_ex); BOOST_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_ = boost::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, boost::system::error_code& ec) { buffer_sequence_adapter<boost::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, boost::system::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 = boost::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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; operation* o = p.p = new (p.v) op( impl.cancel_token_, buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_send")); buffer_sequence_adapter<boost::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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(impl.cancel_token_, handler, io_ex); BOOST_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, boost::system::error_code& ec) { buffer_sequence_adapter<boost::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, boost::system::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 = boost::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 = { boost::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); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_receive")); buffer_sequence_adapter<boost::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 = boost::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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(impl.cancel_token_, handler, io_ex); BOOST_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, boost::system::error_code& ec) { buffer_sequence_adapter<boost::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, boost::system::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 = boost::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 = { boost::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); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_receive_with_flags")); buffer_sequence_adapter<boost::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 = boost::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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(impl.cancel_token_, handler, io_ex); BOOST_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. BOOST_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. BOOST_ASIO_DECL boost::system::error_code do_open( base_implementation_type& impl, int family, int type, int protocol, boost::system::error_code& ec); // Assign a native socket to a socket implementation. BOOST_ASIO_DECL boost::system::error_code do_assign( base_implementation_type& impl, int type, socket_type native_socket, boost::system::error_code& ec); // Helper function to start an asynchronous send operation. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_ASIO_DECL void start_reactor_op(base_implementation_type& impl, int op_type, reactor_op* op); // Start the asynchronous connect operation using the reactor. BOOST_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. BOOST_ASIO_DECL void close_for_destruction(base_implementation_type& impl); // Update the ID of the thread from which cancellation is safe. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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 boost::system::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 boost::system::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 boost::system::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. boost::asio::detail::mutex mutex_; // The head of a linked list of all implementations. base_implementation_type* impl_list_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_iocp_socket_service_base.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SERVICE_BASE_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_TIMER_SCHEDULER_HPP #define BOOST_ASIO_DETAIL_TIMER_SCHEDULER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/timer_scheduler_fwd.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) # include <boost/asio/detail/winrt_timer_scheduler.hpp> #elif defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_io_context.hpp> #elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # include <boost/asio/detail/io_uring_service.hpp> #elif defined(BOOST_ASIO_HAS_EPOLL) # include <boost/asio/detail/epoll_reactor.hpp> #elif defined(BOOST_ASIO_HAS_KQUEUE) # include <boost/asio/detail/kqueue_reactor.hpp> #elif defined(BOOST_ASIO_HAS_DEV_POLL) # include <boost/asio/detail/dev_poll_reactor.hpp> #else # include <boost/asio/detail/select_reactor.hpp> #endif #endif // BOOST_ASIO_DETAIL_TIMER_SCHEDULER_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_CONDITIONALLY_ENABLED_MUTEX_HPP #define BOOST_ASIO_DETAIL_CONDITIONALLY_ENABLED_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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. boost::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; boost::asio::detail::mutex mutex_; const bool enabled_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_CONDITIONALLY_ENABLED_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/chrono_time_traits.hpp
// // detail/chrono_time_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 BOOST_ASIO_DETAIL_CHRONO_TIME_TRAITS_HPP #define BOOST_ASIO_DETAIL_CHRONO_TIME_TRAITS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Helper template to compute the greatest common divisor. template <int64_t v1, int64_t v2> struct gcd { enum { value = gcd<v2, v1 % v2>::value }; }; template <int64_t v1> struct gcd<v1, 0> { enum { value = v1 }; }; // Adapts std::chrono clocks for use with a deadline timer. template <typename Clock, typename WaitTraits> struct chrono_time_traits { // The clock type. typedef Clock clock_type; // The duration type of the clock. typedef typename clock_type::duration duration_type; // The time point type of the clock. typedef typename clock_type::time_point time_type; // The period of the clock. typedef typename duration_type::period period_type; // Get the current time. static time_type now() { return clock_type::now(); } // Add a duration to a time. static time_type add(const time_type& t, const duration_type& d) { const time_type epoch; if (t >= epoch) { if ((time_type::max)() - t < d) return (time_type::max)(); } else // t < epoch { if (-(t - (time_type::min)()) > d) return (time_type::min)(); } return t + d; } // Subtract one time from another. static duration_type subtract(const time_type& t1, const time_type& t2) { const time_type epoch; if (t1 >= epoch) { if (t2 >= epoch) { return t1 - t2; } else if (t2 == (time_type::min)()) { return (duration_type::max)(); } else if ((time_type::max)() - t1 < epoch - t2) { return (duration_type::max)(); } else { return t1 - t2; } } else // t1 < epoch { if (t2 < epoch) { return t1 - t2; } else if (t1 == (time_type::min)()) { return (duration_type::min)(); } else if ((time_type::max)() - t2 < epoch - t1) { return (duration_type::min)(); } else { return -(t2 - t1); } } } // Test whether one time is less than another. static bool less_than(const time_type& t1, const time_type& t2) { return t1 < t2; } // Implement just enough of the posix_time::time_duration interface to supply // what the timer_queue requires. class posix_time_duration { public: explicit posix_time_duration(const duration_type& d) : d_(d) { } int64_t ticks() const { return d_.count(); } int64_t total_seconds() const { return duration_cast<1, 1>(); } int64_t total_milliseconds() const { return duration_cast<1, 1000>(); } int64_t total_microseconds() const { return duration_cast<1, 1000000>(); } private: template <int64_t Num, int64_t Den> int64_t duration_cast() const { const int64_t num1 = period_type::num / gcd<period_type::num, Num>::value; const int64_t num2 = Num / gcd<period_type::num, Num>::value; const int64_t den1 = period_type::den / gcd<period_type::den, Den>::value; const int64_t den2 = Den / gcd<period_type::den, Den>::value; const int64_t num = num1 * den2; const int64_t den = num2 * den1; if (num == 1 && den == 1) return ticks(); else if (num != 1 && den == 1) return ticks() * num; else if (num == 1 && period_type::den != 1) return ticks() / den; else return ticks() * num / den; } duration_type d_; }; // Convert to POSIX duration type. static posix_time_duration to_posix_duration(const duration_type& d) { return posix_time_duration(WaitTraits::to_wait_duration(d)); } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_CHRONO_TIME_TRAITS_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_OP_HPP #define BOOST_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 <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/error.hpp> #include <boost/asio/socket_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class win_iocp_socket_recvmsg_op : public operation { public: BOOST_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 boost::system::error_code& result_ec, std::size_t bytes_transferred) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_socket_recvmsg_op* o( static_cast<win_iocp_socket_recvmsg_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Check whether buffers are still valid. if (owner) { buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::validate(o->buffers_); } #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) socket_ops::complete_iocp_recvmsg(o->cancel_token_, ec); o->out_flags_ = 0; BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, ec, bytes_transferred); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/work_dispatcher.hpp
// // detail/work_dispatcher.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 BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP #define BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution/allocator.hpp> #include <boost/asio/execution/blocking.hpp> #include <boost/asio/execution/outstanding_work.hpp> #include <boost/asio/prefer.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename Executor, typename = void> struct is_work_dispatcher_required : true_type { }; template <typename Handler, typename Executor> struct is_work_dispatcher_required<Handler, Executor, enable_if_t< is_same< typename associated_executor<Handler, Executor>::asio_associated_executor_is_unspecialised, void >::value >> : false_type { }; template <typename Handler, typename Executor, typename = void> class work_dispatcher { public: template <typename CompletionHandler> work_dispatcher(CompletionHandler&& handler, const Executor& handler_ex) : handler_(static_cast<CompletionHandler&&>(handler)), executor_(boost::asio::prefer(handler_ex, execution::outstanding_work.tracked)) { } work_dispatcher(const work_dispatcher& other) : handler_(other.handler_), executor_(other.executor_) { } work_dispatcher(work_dispatcher&& other) : handler_(static_cast<Handler&&>(other.handler_)), executor_(static_cast<work_executor_type&&>(other.executor_)) { } void operator()() { associated_allocator_t<Handler> alloc((get_associated_allocator)(handler_)); boost::asio::prefer(executor_, execution::allocator(alloc)).execute( boost::asio::detail::bind_handler( static_cast<Handler&&>(handler_))); } private: typedef decay_t< prefer_result_t<const Executor&, execution::outstanding_work_t::tracked_t > > work_executor_type; Handler handler_; work_executor_type executor_; }; #if !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename Handler, typename Executor> class work_dispatcher<Handler, Executor, enable_if_t<!execution::is_executor<Executor>::value>> { public: template <typename CompletionHandler> work_dispatcher(CompletionHandler&& handler, const Executor& handler_ex) : work_(handler_ex), handler_(static_cast<CompletionHandler&&>(handler)) { } work_dispatcher(const work_dispatcher& other) : work_(other.work_), handler_(other.handler_) { } work_dispatcher(work_dispatcher&& other) : work_(static_cast<executor_work_guard<Executor>&&>(other.work_)), handler_(static_cast<Handler&&>(other.handler_)) { } void operator()() { associated_allocator_t<Handler> alloc((get_associated_allocator)(handler_)); work_.get_executor().dispatch( boost::asio::detail::bind_handler( static_cast<Handler&&>(handler_)), alloc); work_.reset(); } private: executor_work_guard<Executor> work_; Handler handler_; }; #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS) } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/thread.hpp
// // detail/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 BOOST_ASIO_DETAIL_THREAD_HPP #define BOOST_ASIO_DETAIL_THREAD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) # include <boost/asio/detail/null_thread.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_thread.hpp> #elif defined(BOOST_ASIO_WINDOWS) # if defined(UNDER_CE) # include <boost/asio/detail/wince_thread.hpp> # elif defined(BOOST_ASIO_WINDOWS_APP) # include <boost/asio/detail/winapp_thread.hpp> # else # include <boost/asio/detail/win_thread.hpp> # endif #else # include <boost/asio/detail/std_thread.hpp> #endif namespace boost { namespace asio { namespace detail { #if !defined(BOOST_ASIO_HAS_THREADS) typedef null_thread thread; #elif defined(BOOST_ASIO_HAS_PTHREADS) typedef posix_thread thread; #elif defined(BOOST_ASIO_WINDOWS) # if defined(UNDER_CE) typedef wince_thread thread; # elif defined(BOOST_ASIO_WINDOWS_APP) typedef winapp_thread thread; # else typedef win_thread thread; # endif #else typedef std_thread thread; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/handler_tracking.hpp
// // detail/handler_tracking.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 BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP #define BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> namespace boost { namespace asio { class execution_context; } // namespace asio } // namespace boost #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING) # include BOOST_ASIO_CUSTOM_HANDLER_TRACKING #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # include <boost/system/error_code.hpp> # include <boost/asio/detail/cstdint.hpp> # include <boost/asio/detail/static_mutex.hpp> # include <boost/asio/detail/tss_ptr.hpp> #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING) // The user-specified header must define the following macros: // - BOOST_ASIO_INHERIT_TRACKED_HANDLER // - BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER // - BOOST_ASIO_HANDLER_TRACKING_INIT // - BOOST_ASIO_HANDLER_CREATION(args) // - BOOST_ASIO_HANDLER_COMPLETION(args) // - BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) // - BOOST_ASIO_HANDLER_INVOCATION_END // - BOOST_ASIO_HANDLER_OPERATION(args) // - BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) // - BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) // - BOOST_ASIO_HANDLER_REACTOR_READ_EVENT // - BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT // - BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT // - BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) // - BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) # if !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # define BOOST_ASIO_ENABLE_HANDLER_TRACKING 1 # endif /// !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) class handler_tracking { public: class completion; // Base class for objects containing tracked handlers. class tracked_handler { private: // Only the handler_tracking class will have access to the id. friend class handler_tracking; friend class completion; uint64_t id_; protected: // Constructor initialises with no id. tracked_handler() : id_(0) {} // Prevent deletion through this type. ~tracked_handler() {} }; // Initialise the tracking system. BOOST_ASIO_DECL static void init(); class location { public: // Constructor adds a location to the stack. BOOST_ASIO_DECL explicit location(const char* file, int line, const char* func); // Destructor removes a location from the stack. BOOST_ASIO_DECL ~location(); private: // Disallow copying and assignment. location(const location&) = delete; location& operator=(const location&) = delete; friend class handler_tracking; const char* file_; int line_; const char* func_; location* next_; }; // Record the creation of a tracked handler. BOOST_ASIO_DECL static void creation( execution_context& context, tracked_handler& h, const char* object_type, void* object, uintmax_t native_handle, const char* op_name); class completion { public: // Constructor records that handler is to be invoked with no arguments. BOOST_ASIO_DECL explicit completion(const tracked_handler& h); // Destructor records only when an exception is thrown from the handler, or // if the memory is being freed without the handler having been invoked. BOOST_ASIO_DECL ~completion(); // Records that handler is to be invoked with no arguments. BOOST_ASIO_DECL void invocation_begin(); // Records that handler is to be invoked with one arguments. BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec); // Constructor records that handler is to be invoked with two arguments. BOOST_ASIO_DECL void invocation_begin( const boost::system::error_code& ec, std::size_t bytes_transferred); // Constructor records that handler is to be invoked with two arguments. BOOST_ASIO_DECL void invocation_begin( const boost::system::error_code& ec, int signal_number); // Constructor records that handler is to be invoked with two arguments. BOOST_ASIO_DECL void invocation_begin( const boost::system::error_code& ec, const char* arg); // Record that handler invocation has ended. BOOST_ASIO_DECL void invocation_end(); private: friend class handler_tracking; uint64_t id_; bool invoked_; completion* next_; }; // Record an operation that is not directly associated with a handler. BOOST_ASIO_DECL static void operation(execution_context& context, const char* object_type, void* object, uintmax_t native_handle, const char* op_name); // Record that a descriptor has been registered with the reactor. BOOST_ASIO_DECL static void reactor_registration(execution_context& context, uintmax_t native_handle, uintmax_t registration); // Record that a descriptor has been deregistered from the reactor. BOOST_ASIO_DECL static void reactor_deregistration(execution_context& context, uintmax_t native_handle, uintmax_t registration); // Record a reactor-based operation that is associated with a handler. BOOST_ASIO_DECL static void reactor_events(execution_context& context, uintmax_t registration, unsigned events); // Record a reactor-based operation that is associated with a handler. BOOST_ASIO_DECL static void reactor_operation( const tracked_handler& h, const char* op_name, const boost::system::error_code& ec); // Record a reactor-based operation that is associated with a handler. BOOST_ASIO_DECL static void reactor_operation( const tracked_handler& h, const char* op_name, const boost::system::error_code& ec, std::size_t bytes_transferred); // Write a line of output. BOOST_ASIO_DECL static void write_line(const char* format, ...); private: struct tracking_state; BOOST_ASIO_DECL static tracking_state* get_state(); }; # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \ : public boost::asio::detail::handler_tracking::tracked_handler # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \ , public boost::asio::detail::handler_tracking::tracked_handler # define BOOST_ASIO_HANDLER_TRACKING_INIT \ boost::asio::detail::handler_tracking::init() # define BOOST_ASIO_HANDLER_LOCATION(args) \ boost::asio::detail::handler_tracking::location tracked_location args # define BOOST_ASIO_HANDLER_CREATION(args) \ boost::asio::detail::handler_tracking::creation args # define BOOST_ASIO_HANDLER_COMPLETION(args) \ boost::asio::detail::handler_tracking::completion tracked_completion args # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \ tracked_completion.invocation_begin args # define BOOST_ASIO_HANDLER_INVOCATION_END \ tracked_completion.invocation_end() # define BOOST_ASIO_HANDLER_OPERATION(args) \ boost::asio::detail::handler_tracking::operation args # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) \ boost::asio::detail::handler_tracking::reactor_registration args # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) \ boost::asio::detail::handler_tracking::reactor_deregistration args # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 1 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 2 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 4 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) \ boost::asio::detail::handler_tracking::reactor_events args # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) \ boost::asio::detail::handler_tracking::reactor_operation args #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) # define BOOST_ASIO_INHERIT_TRACKED_HANDLER # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0 # define BOOST_ASIO_HANDLER_LOCATION(loc) (void)0 # define BOOST_ASIO_HANDLER_CREATION(args) (void)0 # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0 # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0 # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) (void)0 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) (void)0 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 0 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 0 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 0 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) (void)0 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) (void)0 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/handler_tracking.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_NULL_STATIC_MUTEX_HPP #define BOOST_ASIO_DETAIL_NULL_STATIC_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct null_static_mutex { typedef boost::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 BOOST_ASIO_NULL_STATIC_MUTEX_INIT { 0 } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_HAS_THREADS) #endif // BOOST_ASIO_DETAIL_NULL_STATIC_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/timer_queue.hpp
// // detail/timer_queue.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 BOOST_ASIO_DETAIL_TIMER_QUEUE_HPP #define BOOST_ASIO_DETAIL_TIMER_QUEUE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <cstddef> #include <vector> #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/date_time_fwd.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Time_Traits> class timer_queue : public timer_queue_base { public: // The time type. typedef typename Time_Traits::time_type time_type; // The duration type. typedef typename Time_Traits::duration_type duration_type; // Per-timer data. class per_timer_data { public: per_timer_data() : heap_index_((std::numeric_limits<std::size_t>::max)()), next_(0), prev_(0) { } private: friend class timer_queue; // The operations waiting on the timer. op_queue<wait_op> op_queue_; // The index of the timer in the heap. std::size_t heap_index_; // Pointers to adjacent timers in a linked list. per_timer_data* next_; per_timer_data* prev_; }; // Constructor. timer_queue() : timers_(), heap_() { } // 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. bool enqueue_timer(const time_type& time, per_timer_data& timer, wait_op* op) { // Enqueue the timer object. if (timer.prev_ == 0 && &timer != timers_) { if (this->is_positive_infinity(time)) { // No heap entry is required for timers that never expire. timer.heap_index_ = (std::numeric_limits<std::size_t>::max)(); } else { // Put the new timer at the correct position in the heap. This is done // first since push_back() can throw due to allocation failure. timer.heap_index_ = heap_.size(); heap_entry entry = { time, &timer }; heap_.push_back(entry); up_heap(heap_.size() - 1); } // Insert the new timer into the linked list of active timers. timer.next_ = timers_; timer.prev_ = 0; if (timers_) timers_->prev_ = &timer; timers_ = &timer; } // Enqueue the individual timer operation. timer.op_queue_.push(op); // Interrupt reactor only if newly added timer is first to expire. return timer.heap_index_ == 0 && timer.op_queue_.front() == op; } // Whether there are no timers in the queue. virtual bool empty() const { return timers_ == 0; } // Get the time for the timer that is earliest in the queue. virtual long wait_duration_msec(long max_duration) const { if (heap_.empty()) return max_duration; return this->to_msec( Time_Traits::to_posix_duration( Time_Traits::subtract(heap_[0].time_, Time_Traits::now())), max_duration); } // Get the time for the timer that is earliest in the queue. virtual long wait_duration_usec(long max_duration) const { if (heap_.empty()) return max_duration; return this->to_usec( Time_Traits::to_posix_duration( Time_Traits::subtract(heap_[0].time_, Time_Traits::now())), max_duration); } // Dequeue all timers not later than the current time. virtual void get_ready_timers(op_queue<operation>& ops) { if (!heap_.empty()) { const time_type now = Time_Traits::now(); while (!heap_.empty() && !Time_Traits::less_than(now, heap_[0].time_)) { per_timer_data* timer = heap_[0].timer_; while (wait_op* op = timer->op_queue_.front()) { timer->op_queue_.pop(); op->ec_ = boost::system::error_code(); ops.push(op); } remove_timer(*timer); } } } // Dequeue all timers. virtual void get_all_timers(op_queue<operation>& ops) { while (timers_) { per_timer_data* timer = timers_; timers_ = timers_->next_; ops.push(timer->op_queue_); timer->next_ = 0; timer->prev_ = 0; } heap_.clear(); } // Cancel and dequeue operations for the given timer. 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)()) { std::size_t num_cancelled = 0; if (timer.prev_ != 0 || &timer == timers_) { while (wait_op* op = (num_cancelled != max_cancelled) ? timer.op_queue_.front() : 0) { op->ec_ = boost::asio::error::operation_aborted; timer.op_queue_.pop(); ops.push(op); ++num_cancelled; } if (timer.op_queue_.empty()) remove_timer(timer); } return num_cancelled; } // Cancel and dequeue a specific operation for the given timer. void cancel_timer_by_key(per_timer_data* timer, op_queue<operation>& ops, void* cancellation_key) { if (timer->prev_ != 0 || timer == timers_) { op_queue<wait_op> other_ops; while (wait_op* op = timer->op_queue_.front()) { timer->op_queue_.pop(); if (op->cancellation_key_ == cancellation_key) { op->ec_ = boost::asio::error::operation_aborted; ops.push(op); } else other_ops.push(op); } timer->op_queue_.push(other_ops); if (timer->op_queue_.empty()) remove_timer(*timer); } } // Move operations from one timer to another, empty timer. void move_timer(per_timer_data& target, per_timer_data& source) { target.op_queue_.push(source.op_queue_); target.heap_index_ = source.heap_index_; source.heap_index_ = (std::numeric_limits<std::size_t>::max)(); if (target.heap_index_ < heap_.size()) heap_[target.heap_index_].timer_ = &target; if (timers_ == &source) timers_ = &target; if (source.prev_) source.prev_->next_ = &target; if (source.next_) source.next_->prev_= &target; target.next_ = source.next_; target.prev_ = source.prev_; source.next_ = 0; source.prev_ = 0; } private: // Move the item at the given index up the heap to its correct position. void up_heap(std::size_t index) { while (index > 0) { std::size_t parent = (index - 1) / 2; if (!Time_Traits::less_than(heap_[index].time_, heap_[parent].time_)) break; swap_heap(index, parent); index = parent; } } // Move the item at the given index down the heap to its correct position. void down_heap(std::size_t index) { std::size_t child = index * 2 + 1; while (child < heap_.size()) { std::size_t min_child = (child + 1 == heap_.size() || Time_Traits::less_than( heap_[child].time_, heap_[child + 1].time_)) ? child : child + 1; if (Time_Traits::less_than(heap_[index].time_, heap_[min_child].time_)) break; swap_heap(index, min_child); index = min_child; child = index * 2 + 1; } } // Swap two entries in the heap. void swap_heap(std::size_t index1, std::size_t index2) { heap_entry tmp = heap_[index1]; heap_[index1] = heap_[index2]; heap_[index2] = tmp; heap_[index1].timer_->heap_index_ = index1; heap_[index2].timer_->heap_index_ = index2; } // Remove a timer from the heap and list of timers. void remove_timer(per_timer_data& timer) { // Remove the timer from the heap. std::size_t index = timer.heap_index_; if (!heap_.empty() && index < heap_.size()) { if (index == heap_.size() - 1) { timer.heap_index_ = (std::numeric_limits<std::size_t>::max)(); heap_.pop_back(); } else { swap_heap(index, heap_.size() - 1); timer.heap_index_ = (std::numeric_limits<std::size_t>::max)(); heap_.pop_back(); if (index > 0 && Time_Traits::less_than( heap_[index].time_, heap_[(index - 1) / 2].time_)) up_heap(index); else down_heap(index); } } // Remove the timer from the linked list of active timers. if (timers_ == &timer) timers_ = timer.next_; if (timer.prev_) timer.prev_->next_ = timer.next_; if (timer.next_) timer.next_->prev_= timer.prev_; timer.next_ = 0; timer.prev_ = 0; } // Determine if the specified absolute time is positive infinity. template <typename Time_Type> static bool is_positive_infinity(const Time_Type&) { return false; } // Determine if the specified absolute time is positive infinity. template <typename T, typename TimeSystem> static bool is_positive_infinity( const boost::date_time::base_time<T, TimeSystem>& time) { return time.is_pos_infinity(); } // Helper function to convert a duration into milliseconds. template <typename Duration> long to_msec(const Duration& d, long max_duration) const { if (d.ticks() <= 0) return 0; int64_t msec = d.total_milliseconds(); if (msec == 0) return 1; if (msec > max_duration) return max_duration; return static_cast<long>(msec); } // Helper function to convert a duration into microseconds. template <typename Duration> long to_usec(const Duration& d, long max_duration) const { if (d.ticks() <= 0) return 0; int64_t usec = d.total_microseconds(); if (usec == 0) return 1; if (usec > max_duration) return max_duration; return static_cast<long>(usec); } // The head of a linked list of all active timers. per_timer_data* timers_; struct heap_entry { // The time when the timer should fire. time_type time_; // The associated timer with enqueued operations. per_timer_data* timer_; }; // The heap of timers, with the earliest timer at the front. std::vector<heap_entry> heap_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_POSIX_THREAD_HPP #define BOOST_ASIO_DETAIL_POSIX_THREAD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_PTHREADS) #include <cstddef> #include <pthread.h> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { extern "C" { BOOST_ASIO_DECL void* boost_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. BOOST_ASIO_DECL ~posix_thread(); // Wait for the thread to exit. BOOST_ASIO_DECL void join(); // Get number of CPUs. BOOST_ASIO_DECL static std::size_t hardware_concurrency(); private: friend void* boost_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_; }; BOOST_ASIO_DECL void start_thread(func_base* arg); ::pthread_t thread_; bool joined_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/posix_thread.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/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(BOOST_ASIO_DISABLE_VISIBILITY) # pragma GCC visibility push (default) # endif // !defined(BOOST_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(BOOST_ASIO_DISABLE_OBJC_WORKAROUND) # if !defined(Protocol) && !defined(id) # define Protocol cpp_Protocol # define id cpp_id # define BOOST_ASIO_OBJC_WORKAROUND # endif # endif # endif # endif # if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) # if !defined(BOOST_ASIO_DISABLE_VISIBILITY) # pragma GCC visibility push (default) # endif // !defined(BOOST_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(BOOST_ASIO_DISABLE_OBJC_WORKAROUND) # if !defined(Protocol) && !defined(id) # define Protocol cpp_Protocol # define id cpp_id # define BOOST_ASIO_OBJC_WORKAROUND # endif # endif # endif # endif # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4) # if !defined(BOOST_ASIO_DISABLE_VISIBILITY) # pragma GCC visibility push (default) # endif // !defined(BOOST_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(BOOST_ASIO_DISABLE_CLR_WORKAROUND) # if !defined(generic) # define generic cpp_generic # define BOOST_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
hpp
asio
data/projects/asio/include/boost/asio/detail/reactor.hpp
// // detail/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 BOOST_ASIO_DETAIL_REACTOR_HPP #define BOOST_ASIO_DETAIL_REACTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) || defined(BOOST_ASIO_WINDOWS_RUNTIME) # include <boost/asio/detail/null_reactor.hpp> #elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # include <boost/asio/detail/null_reactor.hpp> #elif defined(BOOST_ASIO_HAS_EPOLL) # include <boost/asio/detail/epoll_reactor.hpp> #elif defined(BOOST_ASIO_HAS_KQUEUE) # include <boost/asio/detail/kqueue_reactor.hpp> #elif defined(BOOST_ASIO_HAS_DEV_POLL) # include <boost/asio/detail/dev_poll_reactor.hpp> #else # include <boost/asio/detail/select_reactor.hpp> #endif namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_HAS_IOCP) || defined(BOOST_ASIO_WINDOWS_RUNTIME) typedef null_reactor reactor; #elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) typedef null_reactor reactor; #elif defined(BOOST_ASIO_HAS_EPOLL) typedef epoll_reactor reactor; #elif defined(BOOST_ASIO_HAS_KQUEUE) typedef kqueue_reactor reactor; #elif defined(BOOST_ASIO_HAS_DEV_POLL) typedef dev_poll_reactor reactor; #else typedef select_reactor reactor; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/throw_error.hpp
// // detail/throw_error.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 BOOST_ASIO_DETAIL_THROW_ERROR_HPP #define BOOST_ASIO_DETAIL_THROW_ERROR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/throw_exception.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { BOOST_ASIO_DECL void do_throw_error( const boost::system::error_code& err BOOST_ASIO_SOURCE_LOCATION_PARAM); BOOST_ASIO_DECL void do_throw_error( const boost::system::error_code& err, const char* location BOOST_ASIO_SOURCE_LOCATION_PARAM); inline void throw_error( const boost::system::error_code& err BOOST_ASIO_SOURCE_LOCATION_DEFAULTED_PARAM) { if (err) do_throw_error(err BOOST_ASIO_SOURCE_LOCATION_ARG); } inline void throw_error( const boost::system::error_code& err, const char* location BOOST_ASIO_SOURCE_LOCATION_DEFAULTED_PARAM) { if (err) do_throw_error(err, location BOOST_ASIO_SOURCE_LOCATION_ARG); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/throw_error.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_THROW_ERROR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/socket_ops.hpp
// // detail/socket_ops.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 BOOST_ASIO_DETAIL_SOCKET_OPS_HPP #define BOOST_ASIO_DETAIL_SOCKET_OPS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { namespace socket_ops { // Socket state bits. enum { // The user wants a non-blocking socket. user_set_non_blocking = 1, // The socket has been set non-blocking. internal_non_blocking = 2, // Helper "state" used to determine whether the socket is non-blocking. non_blocking = user_set_non_blocking | internal_non_blocking, // User wants connection_aborted errors, which are disabled by default. enable_connection_aborted = 4, // The user set the linger option. Needs to be checked when closing. user_set_linger = 8, // The socket is stream-oriented. stream_oriented = 16, // The socket is datagram-oriented. datagram_oriented = 32, // The socket may have been dup()-ed. possible_dup = 64 }; typedef unsigned char state_type; struct noop_deleter { void operator()(void*) {} }; typedef shared_ptr<void> shared_cancel_token_type; typedef weak_ptr<void> weak_cancel_token_type; #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) BOOST_ASIO_DECL socket_type accept(socket_type s, void* addr, std::size_t* addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL socket_type sync_accept(socket_type s, state_type state, void* addr, std::size_t* addrlen, boost::system::error_code& ec); #if defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL void complete_iocp_accept(socket_type s, void* output_buffer, DWORD address_length, void* addr, std::size_t* addrlen, socket_type new_socket, boost::system::error_code& ec); #else // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_accept(socket_type s, state_type state, void* addr, std::size_t* addrlen, boost::system::error_code& ec, socket_type& new_socket); #endif // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL int bind(socket_type s, const void* addr, std::size_t addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL int close(socket_type s, state_type& state, bool destruction, boost::system::error_code& ec); BOOST_ASIO_DECL bool set_user_non_blocking(socket_type s, state_type& state, bool value, boost::system::error_code& ec); BOOST_ASIO_DECL bool set_internal_non_blocking(socket_type s, state_type& state, bool value, boost::system::error_code& ec); BOOST_ASIO_DECL int shutdown(socket_type s, int what, boost::system::error_code& ec); BOOST_ASIO_DECL int connect(socket_type s, const void* addr, std::size_t addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL void sync_connect(socket_type s, const void* addr, std::size_t addrlen, boost::system::error_code& ec); #if defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL void complete_iocp_connect(socket_type s, boost::system::error_code& ec); #endif // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_connect(socket_type s, boost::system::error_code& ec); BOOST_ASIO_DECL int socketpair(int af, int type, int protocol, socket_type sv[2], boost::system::error_code& ec); BOOST_ASIO_DECL bool sockatmark(socket_type s, boost::system::error_code& ec); BOOST_ASIO_DECL size_t available(socket_type s, boost::system::error_code& ec); BOOST_ASIO_DECL int listen(socket_type s, int backlog, boost::system::error_code& ec); #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) typedef WSABUF buf; #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) typedef iovec buf; #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) BOOST_ASIO_DECL void init_buf(buf& b, void* data, size_t size); BOOST_ASIO_DECL void init_buf(buf& b, const void* data, size_t size); BOOST_ASIO_DECL signed_size_type recv(socket_type s, buf* bufs, size_t count, int flags, boost::system::error_code& ec); BOOST_ASIO_DECL signed_size_type recv1(socket_type s, void* data, size_t size, int flags, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_recv(socket_type s, state_type state, buf* bufs, size_t count, int flags, bool all_empty, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_recv1(socket_type s, state_type state, void* data, size_t size, int flags, boost::system::error_code& ec); #if defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL void complete_iocp_recv(state_type state, const weak_cancel_token_type& cancel_token, bool all_empty, boost::system::error_code& ec, size_t bytes_transferred); #else // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_recv(socket_type s, buf* bufs, size_t count, int flags, bool is_stream, boost::system::error_code& ec, size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_recv1(socket_type s, void* data, size_t size, int flags, bool is_stream, boost::system::error_code& ec, size_t& bytes_transferred); #endif // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL signed_size_type recvfrom(socket_type s, buf* bufs, size_t count, int flags, void* addr, std::size_t* addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL signed_size_type recvfrom1(socket_type s, void* data, size_t size, int flags, void* addr, std::size_t* addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_recvfrom(socket_type s, state_type state, buf* bufs, size_t count, int flags, void* addr, std::size_t* addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_recvfrom1(socket_type s, state_type state, void* data, size_t size, int flags, void* addr, std::size_t* addrlen, boost::system::error_code& ec); #if defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL void complete_iocp_recvfrom( const weak_cancel_token_type& cancel_token, boost::system::error_code& ec); #else // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_recvfrom(socket_type s, buf* bufs, size_t count, int flags, void* addr, std::size_t* addrlen, boost::system::error_code& ec, size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_recvfrom1(socket_type s, void* data, size_t size, int flags, void* addr, std::size_t* addrlen, boost::system::error_code& ec, size_t& bytes_transferred); #endif // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL signed_size_type recvmsg(socket_type s, buf* bufs, size_t count, int in_flags, int& out_flags, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_recvmsg(socket_type s, state_type state, buf* bufs, size_t count, int in_flags, int& out_flags, boost::system::error_code& ec); #if defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL void complete_iocp_recvmsg( const weak_cancel_token_type& cancel_token, boost::system::error_code& ec); #else // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_recvmsg(socket_type s, buf* bufs, size_t count, int in_flags, int& out_flags, boost::system::error_code& ec, size_t& bytes_transferred); #endif // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL signed_size_type send(socket_type s, const buf* bufs, size_t count, int flags, boost::system::error_code& ec); BOOST_ASIO_DECL signed_size_type send1(socket_type s, const void* data, size_t size, int flags, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_send(socket_type s, state_type state, const buf* bufs, size_t count, int flags, bool all_empty, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_send1(socket_type s, state_type state, const void* data, size_t size, int flags, boost::system::error_code& ec); #if defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL void complete_iocp_send( const weak_cancel_token_type& cancel_token, boost::system::error_code& ec); #else // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_send(socket_type s, const buf* bufs, size_t count, int flags, boost::system::error_code& ec, size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_send1(socket_type s, const void* data, size_t size, int flags, boost::system::error_code& ec, size_t& bytes_transferred); #endif // defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL signed_size_type sendto(socket_type s, const buf* bufs, size_t count, int flags, const void* addr, std::size_t addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL signed_size_type sendto1(socket_type s, const void* data, size_t size, int flags, const void* addr, std::size_t addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_sendto(socket_type s, state_type state, const buf* bufs, size_t count, int flags, const void* addr, std::size_t addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL size_t sync_sendto1(socket_type s, state_type state, const void* data, size_t size, int flags, const void* addr, std::size_t addrlen, boost::system::error_code& ec); #if !defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL bool non_blocking_sendto(socket_type s, const buf* bufs, size_t count, int flags, const void* addr, std::size_t addrlen, boost::system::error_code& ec, size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_sendto1(socket_type s, const void* data, size_t size, int flags, const void* addr, std::size_t addrlen, boost::system::error_code& ec, size_t& bytes_transferred); #endif // !defined(BOOST_ASIO_HAS_IOCP) BOOST_ASIO_DECL socket_type socket(int af, int type, int protocol, boost::system::error_code& ec); BOOST_ASIO_DECL int setsockopt(socket_type s, state_type& state, int level, int optname, const void* optval, std::size_t optlen, boost::system::error_code& ec); BOOST_ASIO_DECL int getsockopt(socket_type s, state_type state, int level, int optname, void* optval, size_t* optlen, boost::system::error_code& ec); BOOST_ASIO_DECL int getpeername(socket_type s, void* addr, std::size_t* addrlen, bool cached, boost::system::error_code& ec); BOOST_ASIO_DECL int getsockname(socket_type s, void* addr, std::size_t* addrlen, boost::system::error_code& ec); BOOST_ASIO_DECL int ioctl(socket_type s, state_type& state, int cmd, ioctl_arg_type* arg, boost::system::error_code& ec); BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_read(socket_type s, state_type state, int msec, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_write(socket_type s, state_type state, int msec, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_error(socket_type s, state_type state, int msec, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_connect(socket_type s, int msec, boost::system::error_code& ec); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) BOOST_ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest, size_t length, unsigned long scope_id, boost::system::error_code& ec); BOOST_ASIO_DECL int inet_pton(int af, const char* src, void* dest, unsigned long* scope_id, boost::system::error_code& ec); BOOST_ASIO_DECL int gethostname(char* name, int namelen, boost::system::error_code& ec); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) BOOST_ASIO_DECL boost::system::error_code getaddrinfo(const char* host, const char* service, const addrinfo_type& hints, addrinfo_type** result, boost::system::error_code& ec); BOOST_ASIO_DECL boost::system::error_code background_getaddrinfo( const weak_cancel_token_type& cancel_token, const char* host, const char* service, const addrinfo_type& hints, addrinfo_type** result, boost::system::error_code& ec); BOOST_ASIO_DECL void freeaddrinfo(addrinfo_type* ai); BOOST_ASIO_DECL boost::system::error_code getnameinfo(const void* addr, std::size_t addrlen, char* host, std::size_t hostlen, char* serv, std::size_t servlen, int flags, boost::system::error_code& ec); BOOST_ASIO_DECL boost::system::error_code sync_getnameinfo(const void* addr, std::size_t addrlen, char* host, std::size_t hostlen, char* serv, std::size_t servlen, int sock_type, boost::system::error_code& ec); BOOST_ASIO_DECL boost::system::error_code background_getnameinfo( const weak_cancel_token_type& cancel_token, const void* addr, std::size_t addrlen, char* host, std::size_t hostlen, char* serv, std::size_t servlen, int sock_type, boost::system::error_code& ec); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) BOOST_ASIO_DECL u_long_type network_to_host_long(u_long_type value); BOOST_ASIO_DECL u_long_type host_to_network_long(u_long_type value); BOOST_ASIO_DECL u_short_type network_to_host_short(u_short_type value); BOOST_ASIO_DECL u_short_type host_to_network_short(u_short_type value); } // namespace socket_ops } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/socket_ops.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_SOCKET_OPS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactor_op.hpp
// // detail/reactor_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 BOOST_ASIO_DETAIL_REACTOR_OP_HPP #define BOOST_ASIO_DETAIL_REACTOR_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class reactor_op : public operation { public: // The error code to be passed to the completion handler. boost::system::error_code ec_; // The operation key used for targeted cancellation. void* cancellation_key_; // The number of bytes transferred, to be passed to the completion handler. std::size_t bytes_transferred_; // Status returned by perform function. May be used to decide whether it is // worth performing more operations on the descriptor immediately. enum status { not_done, done, done_and_exhausted }; // Perform the operation. Returns true if it is finished. status perform() { return perform_func_(this); } protected: typedef status (*perform_func_type)(reactor_op*); reactor_op(const boost::system::error_code& success_ec, perform_func_type perform_func, func_type complete_func) : operation(complete_func), ec_(success_ec), cancellation_key_(0), bytes_transferred_(0), perform_func_(perform_func) { } private: perform_func_type perform_func_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_REACTOR_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP #define BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/static_mutex.hpp> #include <boost/asio/detail/tss_ptr.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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_ = BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WIN_GLOBAL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/handler_alloc_helpers.hpp
// // detail/handler_alloc_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 BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP #define BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/recycling_allocator.hpp> #include <boost/asio/detail/thread_info_base.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { inline void* default_allocate(std::size_t s, std::size_t align = BOOST_ASIO_DEFAULT_ALIGN) { #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING) return boost::asio::detail::thread_info_base::allocate( boost::asio::detail::thread_context::top_of_thread_call_stack(), s, align); #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING) return boost::asio::aligned_new(align, s); #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING) } inline void default_deallocate(void* p, std::size_t s) { #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING) boost::asio::detail::thread_info_base::deallocate( boost::asio::detail::thread_context::top_of_thread_call_stack(), p, s); #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING) (void)s; boost::asio::aligned_delete(p); #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING) } template <typename T> class default_allocator { public: typedef T value_type; template <typename U> struct rebind { typedef default_allocator<U> other; }; default_allocator() noexcept { } template <typename U> default_allocator(const default_allocator<U>&) noexcept { } T* allocate(std::size_t n) { return static_cast<T*>(default_allocate(sizeof(T) * n, alignof(T))); } void deallocate(T* p, std::size_t n) { default_deallocate(p, sizeof(T) * n); } }; template <> class default_allocator<void> { public: typedef void value_type; template <typename U> struct rebind { typedef default_allocator<U> other; }; default_allocator() noexcept { } template <typename U> default_allocator(const default_allocator<U>&) noexcept { } }; template <typename Allocator> struct get_default_allocator { typedef Allocator type; static type get(const Allocator& a) { return a; } }; template <typename T> struct get_default_allocator<std::allocator<T>> { typedef default_allocator<T> type; static type get(const std::allocator<T>&) { return type(); } }; } // namespace detail } // namespace asio } // namespace boost #define BOOST_ASIO_DEFINE_HANDLER_PTR(op) \ struct ptr \ { \ Handler* h; \ op* v; \ op* p; \ ~ptr() \ { \ reset(); \ } \ static op* allocate(Handler& handler) \ { \ typedef typename ::boost::asio::associated_allocator< \ Handler>::type associated_allocator_type; \ typedef typename ::boost::asio::detail::get_default_allocator< \ associated_allocator_type>::type default_allocator_type; \ BOOST_ASIO_REBIND_ALLOC(default_allocator_type, op) a( \ ::boost::asio::detail::get_default_allocator< \ associated_allocator_type>::get( \ ::boost::asio::get_associated_allocator(handler))); \ return a.allocate(1); \ } \ void reset() \ { \ if (p) \ { \ p->~op(); \ p = 0; \ } \ if (v) \ { \ typedef typename ::boost::asio::associated_allocator< \ Handler>::type associated_allocator_type; \ typedef typename ::boost::asio::detail::get_default_allocator< \ associated_allocator_type>::type default_allocator_type; \ BOOST_ASIO_REBIND_ALLOC(default_allocator_type, op) a( \ ::boost::asio::detail::get_default_allocator< \ associated_allocator_type>::get( \ ::boost::asio::get_associated_allocator(*h))); \ a.deallocate(static_cast<op*>(v), 1); \ v = 0; \ } \ } \ } \ /**/ #define BOOST_ASIO_DEFINE_TAGGED_HANDLER_ALLOCATOR_PTR(purpose, op) \ struct ptr \ { \ const Alloc* a; \ void* v; \ op* p; \ ~ptr() \ { \ reset(); \ } \ static op* allocate(const Alloc& a) \ { \ typedef typename ::boost::asio::detail::get_recycling_allocator< \ Alloc, purpose>::type recycling_allocator_type; \ BOOST_ASIO_REBIND_ALLOC(recycling_allocator_type, op) a1( \ ::boost::asio::detail::get_recycling_allocator< \ Alloc, purpose>::get(a)); \ return a1.allocate(1); \ } \ void reset() \ { \ if (p) \ { \ p->~op(); \ p = 0; \ } \ if (v) \ { \ typedef typename ::boost::asio::detail::get_recycling_allocator< \ Alloc, purpose>::type recycling_allocator_type; \ BOOST_ASIO_REBIND_ALLOC(recycling_allocator_type, op) a1( \ ::boost::asio::detail::get_recycling_allocator< \ Alloc, purpose>::get(*a)); \ a1.deallocate(static_cast<op*>(v), 1); \ v = 0; \ } \ } \ } \ /**/ #define BOOST_ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(op) \ BOOST_ASIO_DEFINE_TAGGED_HANDLER_ALLOCATOR_PTR( \ ::boost::asio::detail::thread_info_base::default_tag, op ) \ /**/ #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_IO_URING_OPERATION_HPP #define BOOST_ASIO_DETAIL_IO_URING_OPERATION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IO_URING) #include <liburing.h> #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class io_uring_operation : public operation { public: // The error code to be passed to the completion handler. boost::system::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 boost::system::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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_OPERATION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_socket_accept_op.hpp
// // detail/win_iocp_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 BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_ACCEPT_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_ACCEPT_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/win_iocp_socket_service_base.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Socket, typename Protocol, typename Handler, typename IoExecutor> class win_iocp_socket_accept_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_accept_op); win_iocp_socket_accept_op(win_iocp_socket_service_base& socket_service, socket_type socket, Socket& peer, const Protocol& protocol, typename Protocol::endpoint* peer_endpoint, bool enable_connection_aborted, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_socket_accept_op::do_complete), socket_service_(socket_service), socket_(socket), peer_(peer), protocol_(protocol), peer_endpoint_(peer_endpoint), enable_connection_aborted_(enable_connection_aborted), proxy_op_(0), cancel_requested_(0), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } socket_holder& new_socket() { return new_socket_; } void* output_buffer() { return output_buffer_; } DWORD address_length() { return sizeof(sockaddr_storage_type) + 16; } void enable_cancellation(long* cancel_requested, operation* proxy_op) { cancel_requested_ = cancel_requested; proxy_op_ = proxy_op; } static void do_complete(void* owner, operation* base, const boost::system::error_code& result_ec, std::size_t /*bytes_transferred*/) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_socket_accept_op* o(static_cast<win_iocp_socket_accept_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; if (owner) { typename Protocol::endpoint peer_endpoint; std::size_t addr_len = peer_endpoint.capacity(); socket_ops::complete_iocp_accept(o->socket_, o->output_buffer(), o->address_length(), peer_endpoint.data(), &addr_len, o->new_socket_.get(), ec); // Restart the accept operation if we got the connection_aborted error // and the enable_connection_aborted socket option is not set. if (ec == boost::asio::error::connection_aborted && !o->enable_connection_aborted_) { o->reset(); if (o->proxy_op_) o->proxy_op_->reset(); o->socket_service_.restart_accept_op(o->socket_, o->new_socket_, o->protocol_.family(), o->protocol_.type(), o->protocol_.protocol(), o->output_buffer(), o->address_length(), o->cancel_requested_, o->proxy_op_ ? o->proxy_op_ : o); p.v = p.p = 0; return; } // If the socket was successfully accepted, transfer ownership of the // socket to the peer object. if (!ec) { o->peer_.assign(o->protocol_, typename Socket::native_handle_type( o->new_socket_.get(), peer_endpoint), ec); if (!ec) o->new_socket_.release(); } // Pass endpoint back to caller. if (o->peer_endpoint_) *o->peer_endpoint_ = peer_endpoint; } BOOST_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_)); BOOST_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, boost::system::error_code> handler(o->handler_, ec); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: win_iocp_socket_service_base& socket_service_; socket_type socket_; socket_holder new_socket_; Socket& peer_; Protocol protocol_; typename Protocol::endpoint* peer_endpoint_; unsigned char output_buffer_[(sizeof(sockaddr_storage_type) + 16) * 2]; bool enable_connection_aborted_; operation* proxy_op_; long* cancel_requested_; Handler handler_; handler_work<Handler, IoExecutor> work_; }; template <typename Protocol, typename PeerIoExecutor, typename Handler, typename IoExecutor> class win_iocp_socket_move_accept_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_move_accept_op); win_iocp_socket_move_accept_op( win_iocp_socket_service_base& socket_service, socket_type socket, const Protocol& protocol, const PeerIoExecutor& peer_io_ex, typename Protocol::endpoint* peer_endpoint, bool enable_connection_aborted, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_socket_move_accept_op::do_complete), socket_service_(socket_service), socket_(socket), peer_(peer_io_ex), protocol_(protocol), peer_endpoint_(peer_endpoint), enable_connection_aborted_(enable_connection_aborted), cancel_requested_(0), proxy_op_(0), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } socket_holder& new_socket() { return new_socket_; } void* output_buffer() { return output_buffer_; } DWORD address_length() { return sizeof(sockaddr_storage_type) + 16; } void enable_cancellation(long* cancel_requested, operation* proxy_op) { cancel_requested_ = cancel_requested; proxy_op_ = proxy_op; } static void do_complete(void* owner, operation* base, const boost::system::error_code& result_ec, std::size_t /*bytes_transferred*/) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_socket_move_accept_op* o( static_cast<win_iocp_socket_move_accept_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; if (owner) { typename Protocol::endpoint peer_endpoint; std::size_t addr_len = peer_endpoint.capacity(); socket_ops::complete_iocp_accept(o->socket_, o->output_buffer(), o->address_length(), peer_endpoint.data(), &addr_len, o->new_socket_.get(), ec); // Restart the accept operation if we got the connection_aborted error // and the enable_connection_aborted socket option is not set. if (ec == boost::asio::error::connection_aborted && !o->enable_connection_aborted_) { o->reset(); if (o->proxy_op_) o->proxy_op_->reset(); o->socket_service_.restart_accept_op(o->socket_, o->new_socket_, o->protocol_.family(), o->protocol_.type(), o->protocol_.protocol(), o->output_buffer(), o->address_length(), o->cancel_requested_, o->proxy_op_ ? o->proxy_op_ : o); p.v = p.p = 0; return; } // If the socket was successfully accepted, transfer ownership of the // socket to the peer object. if (!ec) { o->peer_.assign(o->protocol_, typename Protocol::socket::native_handle_type( o->new_socket_.get(), peer_endpoint), ec); if (!ec) o->new_socket_.release(); } // Pass endpoint back to caller. if (o->peer_endpoint_) *o->peer_endpoint_ = peer_endpoint; } BOOST_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_)); BOOST_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::move_binder2<Handler, boost::system::error_code, peer_socket_type> handler(0, static_cast<Handler&&>(o->handler_), ec, static_cast<peer_socket_type&&>(o->peer_)); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "...")); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: typedef typename Protocol::socket::template rebind_executor<PeerIoExecutor>::other peer_socket_type; win_iocp_socket_service_base& socket_service_; socket_type socket_; socket_holder new_socket_; peer_socket_type peer_; Protocol protocol_; typename Protocol::endpoint* peer_endpoint_; unsigned char output_buffer_[(sizeof(sockaddr_storage_type) + 16) * 2]; bool enable_connection_aborted_; long* cancel_requested_; operation* proxy_op_; Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_ACCEPT_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_OP_HPP #define BOOST_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 <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class win_iocp_null_buffers_op : public reactor_op { public: BOOST_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(boost::system::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 boost::system::error_code& result_ec, std::size_t bytes_transferred) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_null_buffers_op* o(static_cast<win_iocp_null_buffers_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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 = boost::asio::error::operation_aborted; else ec = boost::asio::error::connection_reset; } else if (ec.value() == ERROR_PORT_UNREACHABLE) { ec = boost::asio::error::connection_refused; } BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, ec, bytes_transferred); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: socket_ops::weak_cancel_token_type cancel_token_; Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_WRITE_OP_HPP #define BOOST_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 <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IO_URING) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/descriptor_ops.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/io_uring_operation.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 boost::system::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) { BOOST_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) { BOOST_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_ == boost::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<boost::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: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_descriptor_write_op); io_uring_descriptor_write_op(const boost::system::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 boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_descriptor_write_op* o (static_cast<io_uring_descriptor_write_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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_)); BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, o->ec_, o->bytes_transferred_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_WRITE_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_SIGNAL_INIT_HPP #define BOOST_ASIO_DETAIL_SIGNAL_INIT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #include <csignal> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <int Signal = SIGPIPE> class signal_init { public: // Constructor. signal_init() { std::signal(Signal, SIG_IGN); } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_SIGNAL_INIT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/pop_options.hpp
// // detail/pop_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(BOOST_ASIO_DISABLE_VISIBILITY) # pragma GCC visibility pop # endif // !defined(BOOST_ASIO_DISABLE_VISIBILITY) # endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4) # pragma pop_macro ("emit") # pragma pop_macro ("signal") # pragma pop_macro ("slot") #elif defined(__clang__) // Clang # if defined(__OBJC__) # if !defined(__APPLE_CC__) || (__APPLE_CC__ <= 1) # if defined(BOOST_ASIO_OBJC_WORKAROUND) # undef Protocol # undef id # undef BOOST_ASIO_OBJC_WORKAROUND # endif # endif # endif # if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) # if !defined(BOOST_ASIO_DISABLE_VISIBILITY) # pragma GCC visibility pop # endif // !defined(BOOST_ASIO_DISABLE_VISIBILITY) # endif // !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) # pragma GCC diagnostic pop # pragma pop_macro ("emit") # pragma pop_macro ("signal") # pragma pop_macro ("slot") #elif defined(__GNUC__) // GNU C++ # if defined(__MINGW32__) || defined(__CYGWIN__) # pragma pack (pop) # endif # if defined(__OBJC__) # if !defined(__APPLE_CC__) || (__APPLE_CC__ <= 1) # if defined(BOOST_ASIO_OBJC_WORKAROUND) # undef Protocol # undef id # undef BOOST_ASIO_OBJC_WORKAROUND # endif # endif # endif # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4) # if !defined(BOOST_ASIO_DISABLE_VISIBILITY) # pragma GCC visibility pop # endif // !defined(BOOST_ASIO_DISABLE_VISIBILITY) # endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4) # pragma GCC diagnostic pop # pragma pop_macro ("emit") # pragma pop_macro ("signal") # pragma pop_macro ("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 pop # pragma nopushoptwarn # pragma nopackwarning #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 (pop) # pragma pack (pop) # if defined(__cplusplus_cli) || defined(__cplusplus_winrt) # if defined(BOOST_ASIO_CLR_WORKAROUND) # undef generic # undef BOOST_ASIO_CLR_WORKAROUND # endif # endif # pragma pop_macro ("emit") # pragma pop_macro ("signal") # pragma pop_macro ("slot") #endif
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_EPOLL_REACTOR_HPP #define BOOST_ASIO_DETAIL_EPOLL_REACTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_EPOLL) #include <boost/asio/detail/atomic_count.hpp> #include <boost/asio/detail/conditionally_enabled_mutex.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/object_pool.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/scheduler_task.hpp> #include <boost/asio/detail/select_interrupter.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/timer_queue_set.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/execution_context.hpp> #if defined(BOOST_ASIO_HAS_TIMERFD) # include <sys/timerfd.h> #endif // defined(BOOST_ASIO_HAS_TIMERFD) #include <boost/asio/detail/push_options.hpp> namespace boost { 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_; BOOST_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; } BOOST_ASIO_DECL operation* perform_io(uint32_t events); BOOST_ASIO_DECL static void do_complete( void* owner, operation* base, const boost::system::error_code& ec, std::size_t bytes_transferred); }; // Per-descriptor data. typedef descriptor_state* per_descriptor_data; // Constructor. BOOST_ASIO_DECL epoll_reactor(boost::asio::execution_context& ctx); // Destructor. BOOST_ASIO_DECL ~epoll_reactor(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Recreate internal descriptors following a fork. BOOST_ASIO_DECL void notify_fork( boost::asio::execution_context::fork_event fork_ev); // Initialise the task. BOOST_ASIO_DECL void init_task(); // Register a socket with the reactor. Returns 0 on success, system error // code on failure. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_ASIO_DECL void run(long usec, op_queue<operation>& ops); // Interrupt the select loop. BOOST_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. BOOST_ASIO_DECL static int do_epoll_create(); // Create the timerfd file descriptor. Does not throw. BOOST_ASIO_DECL static int do_timerfd_create(); // Allocate a new descriptor state object. BOOST_ASIO_DECL descriptor_state* allocate_descriptor_state(); // Free an existing descriptor state object. BOOST_ASIO_DECL void free_descriptor_state(descriptor_state* s); // Helper function to add a new timer queue. BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); // Helper function to remove a timer queue. BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); // Called to recalculate and update the timeout. BOOST_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. BOOST_ASIO_DECL int get_timeout(int msec); #if defined(BOOST_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. BOOST_ASIO_DECL int get_timeout(itimerspec& ts); #endif // defined(BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/epoll_reactor.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/epoll_reactor.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_EPOLL) #endif // BOOST_ASIO_DETAIL_EPOLL_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_reactor.hpp
// // detail/null_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 BOOST_ASIO_DETAIL_NULL_REACTOR_HPP #define BOOST_ASIO_DETAIL_NULL_REACTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) \ || defined(BOOST_ASIO_WINDOWS_RUNTIME) \ || defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #include <boost/asio/detail/scheduler_operation.hpp> #include <boost/asio/detail/scheduler_task.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class null_reactor : public execution_context_service_base<null_reactor>, public scheduler_task { public: struct per_descriptor_data { }; // Constructor. null_reactor(boost::asio::execution_context& ctx) : execution_context_service_base<null_reactor>(ctx) { } // Destructor. ~null_reactor() { } // Initialise the task. void init_task() { } // Destroy all user-defined handler objects owned by the service. void shutdown() { } // No-op because should never be called. void run(long /*usec*/, op_queue<scheduler_operation>& /*ops*/) { } // No-op. void interrupt() { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) // || defined(BOOST_ASIO_WINDOWS_RUNTIME) // || defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #endif // BOOST_ASIO_DETAIL_NULL_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/hash_map.hpp
// // detail/hash_map.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 BOOST_ASIO_DETAIL_HASH_MAP_HPP #define BOOST_ASIO_DETAIL_HASH_MAP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <list> #include <utility> #include <boost/asio/detail/assert.hpp> #include <boost/asio/detail/noncopyable.hpp> #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) # include <boost/asio/detail/socket_types.hpp> #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { inline std::size_t calculate_hash_value(int i) { return static_cast<std::size_t>(i); } inline std::size_t calculate_hash_value(void* p) { return reinterpret_cast<std::size_t>(p) + (reinterpret_cast<std::size_t>(p) >> 3); } #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) inline std::size_t calculate_hash_value(SOCKET s) { return static_cast<std::size_t>(s); } #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) // Note: assumes K and V are POD types. template <typename K, typename V> class hash_map : private noncopyable { public: // The type of a value in the map. typedef std::pair<K, V> value_type; // The type of a non-const iterator over the hash map. typedef typename std::list<value_type>::iterator iterator; // The type of a const iterator over the hash map. typedef typename std::list<value_type>::const_iterator const_iterator; // Constructor. hash_map() : size_(0), buckets_(0), num_buckets_(0) { } // Destructor. ~hash_map() { delete[] buckets_; } // Get an iterator for the beginning of the map. iterator begin() { return values_.begin(); } // Get an iterator for the beginning of the map. const_iterator begin() const { return values_.begin(); } // Get an iterator for the end of the map. iterator end() { return values_.end(); } // Get an iterator for the end of the map. const_iterator end() const { return values_.end(); } // Check whether the map is empty. bool empty() const { return values_.empty(); } // Find an entry in the map. iterator find(const K& k) { if (num_buckets_) { size_t bucket = calculate_hash_value(k) % num_buckets_; iterator it = buckets_[bucket].first; if (it == values_.end()) return values_.end(); iterator end_it = buckets_[bucket].last; ++end_it; while (it != end_it) { if (it->first == k) return it; ++it; } } return values_.end(); } // Find an entry in the map. const_iterator find(const K& k) const { if (num_buckets_) { size_t bucket = calculate_hash_value(k) % num_buckets_; const_iterator it = buckets_[bucket].first; if (it == values_.end()) return it; const_iterator end_it = buckets_[bucket].last; ++end_it; while (it != end_it) { if (it->first == k) return it; ++it; } } return values_.end(); } // Insert a new entry into the map. std::pair<iterator, bool> insert(const value_type& v) { if (size_ + 1 >= num_buckets_) rehash(hash_size(size_ + 1)); size_t bucket = calculate_hash_value(v.first) % num_buckets_; iterator it = buckets_[bucket].first; if (it == values_.end()) { buckets_[bucket].first = buckets_[bucket].last = values_insert(values_.end(), v); ++size_; return std::pair<iterator, bool>(buckets_[bucket].last, true); } iterator end_it = buckets_[bucket].last; ++end_it; while (it != end_it) { if (it->first == v.first) return std::pair<iterator, bool>(it, false); ++it; } buckets_[bucket].last = values_insert(end_it, v); ++size_; return std::pair<iterator, bool>(buckets_[bucket].last, true); } // Erase an entry from the map. void erase(iterator it) { BOOST_ASIO_ASSERT(it != values_.end()); BOOST_ASIO_ASSERT(num_buckets_ != 0); size_t bucket = calculate_hash_value(it->first) % num_buckets_; bool is_first = (it == buckets_[bucket].first); bool is_last = (it == buckets_[bucket].last); if (is_first && is_last) buckets_[bucket].first = buckets_[bucket].last = values_.end(); else if (is_first) ++buckets_[bucket].first; else if (is_last) --buckets_[bucket].last; values_erase(it); --size_; } // Erase a key from the map. void erase(const K& k) { iterator it = find(k); if (it != values_.end()) erase(it); } // Remove all entries from the map. void clear() { // Clear the values. values_.clear(); size_ = 0; // Initialise all buckets to empty. iterator end_it = values_.end(); for (size_t i = 0; i < num_buckets_; ++i) buckets_[i].first = buckets_[i].last = end_it; } private: // Calculate the hash size for the specified number of elements. static std::size_t hash_size(std::size_t num_elems) { static std::size_t sizes[] = { #if defined(BOOST_ASIO_HASH_MAP_BUCKETS) BOOST_ASIO_HASH_MAP_BUCKETS #else // BOOST_ASIO_HASH_MAP_BUCKETS 3, 13, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843 #endif // BOOST_ASIO_HASH_MAP_BUCKETS }; const std::size_t nth_size = sizeof(sizes) / sizeof(std::size_t) - 1; for (std::size_t i = 0; i < nth_size; ++i) if (num_elems < sizes[i]) return sizes[i]; return sizes[nth_size]; } // Re-initialise the hash from the values already contained in the list. void rehash(std::size_t num_buckets) { if (num_buckets == num_buckets_) return; BOOST_ASIO_ASSERT(num_buckets != 0); iterator end_iter = values_.end(); // Update number of buckets and initialise all buckets to empty. bucket_type* tmp = new bucket_type[num_buckets]; delete[] buckets_; buckets_ = tmp; num_buckets_ = num_buckets; for (std::size_t i = 0; i < num_buckets_; ++i) buckets_[i].first = buckets_[i].last = end_iter; // Put all values back into the hash. iterator iter = values_.begin(); while (iter != end_iter) { std::size_t bucket = calculate_hash_value(iter->first) % num_buckets_; if (buckets_[bucket].last == end_iter) { buckets_[bucket].first = buckets_[bucket].last = iter++; } else if (++buckets_[bucket].last == iter) { ++iter; } else { values_.splice(buckets_[bucket].last, values_, iter++); --buckets_[bucket].last; } } } // Insert an element into the values list by splicing from the spares list, // if a spare is available, and otherwise by inserting a new element. iterator values_insert(iterator it, const value_type& v) { if (spares_.empty()) { return values_.insert(it, v); } else { spares_.front() = v; values_.splice(it, spares_, spares_.begin()); return --it; } } // Erase an element from the values list by splicing it to the spares list. void values_erase(iterator it) { *it = value_type(); spares_.splice(spares_.begin(), values_, it); } // The number of elements in the hash. std::size_t size_; // The list of all values in the hash map. std::list<value_type> values_; // The list of spare nodes waiting to be recycled. Assumes that POD types only // are stored in the hash map. std::list<value_type> spares_; // The type for a bucket in the hash table. struct bucket_type { iterator first; iterator last; }; // The buckets in the hash. bucket_type* buckets_; // The number of buckets in the hash. std::size_t num_buckets_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_HASH_MAP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_POSIX_EVENT_HPP #define BOOST_ASIO_DETAIL_POSIX_EVENT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_PTHREADS) #include <cstddef> #include <pthread.h> #include <boost/asio/detail/assert.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class posix_event : private noncopyable { public: // Constructor. BOOST_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) { BOOST_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) { BOOST_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) { BOOST_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) { BOOST_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) { BOOST_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) { BOOST_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) { BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/posix_event.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_EVENT_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP #define BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Helper function to create thread-specific storage. BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_tss_ptr.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) #endif // BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/future.hpp
// // detail/future.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 BOOST_ASIO_DETAIL_FUTURE_HPP #define BOOST_ASIO_DETAIL_FUTURE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <future> // Even though the future header is available, libstdc++ may not implement the // std::future class itself. However, we need to have already included the // future header to reliably test for _GLIBCXX_HAS_GTHREADS. #if defined(__GNUC__) && !defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # if defined(_GLIBCXX_HAS_GTHREADS) # define BOOST_ASIO_HAS_STD_FUTURE_CLASS 1 # endif // defined(_GLIBCXX_HAS_GTHREADS) #else // defined(__GNUC__) && !defined(BOOST_ASIO_HAS_CLANG_LIBCXX) # define BOOST_ASIO_HAS_STD_FUTURE_CLASS 1 #endif // defined(__GNUC__) && !defined(BOOST_ASIO_HAS_CLANG_LIBCXX) #endif // BOOST_ASIO_DETAIL_FUTURE_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_SCOPED_PTR_HPP #define BOOST_ASIO_DETAIL_SCOPED_PTR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SCOPED_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/std_event.hpp
// // detail/std_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 BOOST_ASIO_DETAIL_STD_EVENT_HPP #define BOOST_ASIO_DETAIL_STD_EVENT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <chrono> #include <condition_variable> #include <boost/asio/detail/assert.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class std_event : private noncopyable { public: // Constructor. std_event() : state_(0) { } // Destructor. ~std_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) { BOOST_ASIO_ASSERT(lock.locked()); (void)lock; state_ |= 1; cond_.notify_all(); } // Unlock the mutex and signal one waiter. template <typename Lock> void unlock_and_signal_one(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); lock.unlock(); if (have_waiters) cond_.notify_one(); } // Unlock the mutex and signal one waiter who may destroy us. template <typename Lock> void unlock_and_signal_one_for_destruction(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); if (have_waiters) cond_.notify_one(); lock.unlock(); } // If there's a waiter, unlock the mutex and signal it. template <typename Lock> bool maybe_unlock_and_signal_one(Lock& lock) { BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; if (state_ > 1) { lock.unlock(); cond_.notify_one(); return true; } return false; } // Reset the event. template <typename Lock> void clear(Lock& lock) { BOOST_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) { BOOST_ASIO_ASSERT(lock.locked()); unique_lock_adapter u_lock(lock); while ((state_ & 1) == 0) { waiter w(state_); cond_.wait(u_lock.unique_lock_); } } // Timed wait for the event to become signalled. template <typename Lock> bool wait_for_usec(Lock& lock, long usec) { BOOST_ASIO_ASSERT(lock.locked()); unique_lock_adapter u_lock(lock); if ((state_ & 1) == 0) { waiter w(state_); cond_.wait_for(u_lock.unique_lock_, std::chrono::microseconds(usec)); } return (state_ & 1) != 0; } private: // Helper class to temporarily adapt a scoped_lock into a unique_lock so that // it can be passed to std::condition_variable::wait(). struct unique_lock_adapter { template <typename Lock> explicit unique_lock_adapter(Lock& lock) : unique_lock_(lock.mutex().mutex_, std::adopt_lock) { } ~unique_lock_adapter() { unique_lock_.release(); } std::unique_lock<std::mutex> unique_lock_; }; // Helper to increment and decrement the state to track outstanding waiters. class waiter { public: explicit waiter(std::size_t& state) : state_(state) { state_ += 2; } ~waiter() { state_ -= 2; } private: std::size_t& state_; }; std::condition_variable cond_; std::size_t state_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_STD_EVENT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/cstdint.hpp
// // detail/cstdint.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 BOOST_ASIO_DETAIL_CSTDINT_HPP #define BOOST_ASIO_DETAIL_CSTDINT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <cstdint> namespace boost { namespace asio { using std::int16_t; using std::int_least16_t; using std::uint16_t; using std::uint_least16_t; using std::int32_t; using std::int_least32_t; using std::uint32_t; using std::uint_least32_t; using std::int64_t; using std::int_least64_t; using std::uint64_t; using std::uint_least64_t; using std::uintptr_t; using std::uintmax_t; } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_CSTDINT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/eventfd_select_interrupter.hpp
// // detail/eventfd_select_interrupter.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Roelof Naude (roelof.naude at gmail 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 BOOST_ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP #define BOOST_ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_EVENTFD) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class eventfd_select_interrupter { public: // Constructor. BOOST_ASIO_DECL eventfd_select_interrupter(); // Destructor. BOOST_ASIO_DECL ~eventfd_select_interrupter(); // Recreate the interrupter's descriptors. Used after a fork. BOOST_ASIO_DECL void recreate(); // Interrupt the select call. BOOST_ASIO_DECL void interrupt(); // Reset the select interrupter. Returns true if the reset was successful. BOOST_ASIO_DECL bool reset(); // Get the read descriptor to be passed to select. int read_descriptor() const { return read_descriptor_; } private: // Open the descriptors. Throws on error. BOOST_ASIO_DECL void open_descriptors(); // Close the descriptors. BOOST_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 // 64bit value will be written on the other end of the connection and this // descriptor will become readable. int read_descriptor_; // The write end of a connection used to interrupt the select call. A single // 64bit non-zero value may be written to this to wake up the select which is // waiting for the other end to become readable. This descriptor will only // differ from the read descriptor when a pipe is used. int write_descriptor_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/eventfd_select_interrupter.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_EVENTFD) #endif // BOOST_ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/std_static_mutex.hpp
// // detail/std_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 BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP #define BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <mutex> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class std_event; class std_static_mutex : private noncopyable { public: typedef boost::asio::detail::scoped_lock<std_static_mutex> scoped_lock; // Constructor. std_static_mutex(int) { } // Destructor. ~std_static_mutex() { } // Initialise the mutex. void init() { // Nothing to do. } // Lock the mutex. void lock() { mutex_.lock(); } // Unlock the mutex. void unlock() { mutex_.unlock(); } private: friend class std_event; std::mutex mutex_; }; #define BOOST_ASIO_STD_STATIC_MUTEX_INIT 0 } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_STD_STATIC_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/old_win_sdk_compat.hpp
// // detail/old_win_sdk_compat.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 BOOST_ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP #define BOOST_ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) // Guess whether we are building against on old Platform SDK. #if !defined(IN6ADDR_ANY_INIT) #define BOOST_ASIO_HAS_OLD_WIN_SDK 1 #endif // !defined(IN6ADDR_ANY_INIT) #if defined(BOOST_ASIO_HAS_OLD_WIN_SDK) // Emulation of types that are missing from old Platform SDKs. // // N.B. this emulation is also used if building for a Windows 2000 target with // a recent (i.e. Vista or later) SDK, as the SDK does not provide IPv6 support // in that case. #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { enum { sockaddr_storage_maxsize = 128, // Maximum size. sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment. sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)), sockaddr_storage_pad2size = (sockaddr_storage_maxsize - (sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize)) }; struct sockaddr_storage_emulation { short ss_family; char __ss_pad1[sockaddr_storage_pad1size]; __int64 __ss_align; char __ss_pad2[sockaddr_storage_pad2size]; }; struct in6_addr_emulation { union { u_char Byte[16]; u_short Word[8]; } u; }; #if !defined(s6_addr) # define _S6_un u # define _S6_u8 Byte # define s6_addr _S6_un._S6_u8 #endif // !defined(s6_addr) struct sockaddr_in6_emulation { short sin6_family; u_short sin6_port; u_long sin6_flowinfo; in6_addr_emulation sin6_addr; u_long sin6_scope_id; }; struct ipv6_mreq_emulation { in6_addr_emulation ipv6mr_multiaddr; unsigned int ipv6mr_interface; }; struct addrinfo_emulation { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; size_t ai_addrlen; char* ai_canonname; sockaddr* ai_addr; addrinfo_emulation* ai_next; }; #if !defined(AI_PASSIVE) # define AI_PASSIVE 0x1 #endif #if !defined(AI_CANONNAME) # define AI_CANONNAME 0x2 #endif #if !defined(AI_NUMERICHOST) # define AI_NUMERICHOST 0x4 #endif #if !defined(EAI_AGAIN) # define EAI_AGAIN WSATRY_AGAIN #endif #if !defined(EAI_BADFLAGS) # define EAI_BADFLAGS WSAEINVAL #endif #if !defined(EAI_FAIL) # define EAI_FAIL WSANO_RECOVERY #endif #if !defined(EAI_FAMILY) # define EAI_FAMILY WSAEAFNOSUPPORT #endif #if !defined(EAI_MEMORY) # define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY #endif #if !defined(EAI_NODATA) # define EAI_NODATA WSANO_DATA #endif #if !defined(EAI_NONAME) # define EAI_NONAME WSAHOST_NOT_FOUND #endif #if !defined(EAI_SERVICE) # define EAI_SERVICE WSATYPE_NOT_FOUND #endif #if !defined(EAI_SOCKTYPE) # define EAI_SOCKTYPE WSAESOCKTNOSUPPORT #endif #if !defined(NI_NOFQDN) # define NI_NOFQDN 0x01 #endif #if !defined(NI_NUMERICHOST) # define NI_NUMERICHOST 0x02 #endif #if !defined(NI_NAMEREQD) # define NI_NAMEREQD 0x04 #endif #if !defined(NI_NUMERICSERV) # define NI_NUMERICSERV 0x08 #endif #if !defined(NI_DGRAM) # define NI_DGRAM 0x10 #endif #if !defined(IPPROTO_IPV6) # define IPPROTO_IPV6 41 #endif #if !defined(IPV6_UNICAST_HOPS) # define IPV6_UNICAST_HOPS 4 #endif #if !defined(IPV6_MULTICAST_IF) # define IPV6_MULTICAST_IF 9 #endif #if !defined(IPV6_MULTICAST_HOPS) # define IPV6_MULTICAST_HOPS 10 #endif #if !defined(IPV6_MULTICAST_LOOP) # define IPV6_MULTICAST_LOOP 11 #endif #if !defined(IPV6_JOIN_GROUP) # define IPV6_JOIN_GROUP 12 #endif #if !defined(IPV6_LEAVE_GROUP) # define IPV6_LEAVE_GROUP 13 #endif } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_OLD_WIN_SDK) // Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY. #if !defined(IPV6_V6ONLY) # define IPV6_V6ONLY 27 #endif // Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6. #if !defined(IPPROTO_ICMPV6) # define IPPROTO_ICMPV6 58 #endif #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_thread_info.hpp
// // detail/win_iocp_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 BOOST_ASIO_DETAIL_WIN_IOCP_THREAD_INFO_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_THREAD_INFO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/thread_info_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct win_iocp_thread_info : public thread_info_base { }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WIN_IOCP_THREAD_INFO_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP #define BOOST_ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_IO_URING_FILE_SERVICE_HPP #define BOOST_ASIO_DETAIL_IO_URING_FILE_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_FILE) \ && defined(BOOST_ASIO_HAS_IO_URING) #include <string> #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/descriptor_ops.hpp> #include <boost/asio/detail/io_uring_descriptor_service.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/file_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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_; }; BOOST_ASIO_DECL io_uring_file_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_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. BOOST_ASIO_DECL boost::system::error_code open(implementation_type& impl, const char* path, file_base::flags open_flags, boost::system::error_code& ec); // Assign a native descriptor to a file implementation. boost::system::error_code assign(implementation_type& impl, const native_handle_type& native_descriptor, boost::system::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. boost::system::error_code close(implementation_type& impl, boost::system::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, boost::system::error_code& ec) { return descriptor_service_.release(impl, ec); } // Cancel all operations associated with the file. boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec) { return descriptor_service_.cancel(impl, ec); } // Get the size of the file. BOOST_ASIO_DECL uint64_t size(const implementation_type& impl, boost::system::error_code& ec) const; // Alter the size of the file. BOOST_ASIO_DECL boost::system::error_code resize(implementation_type& impl, uint64_t n, boost::system::error_code& ec); // Synchronise the file to disk. BOOST_ASIO_DECL boost::system::error_code sync_all(implementation_type& impl, boost::system::error_code& ec); // Synchronise the file data to disk. BOOST_ASIO_DECL boost::system::error_code sync_data(implementation_type& impl, boost::system::error_code& ec); // Seek to a position in the file. BOOST_ASIO_DECL uint64_t seek(implementation_type& impl, int64_t offset, file_base::seek_basis whence, boost::system::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, boost::system::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, boost::system::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, boost::system::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, boost::system::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 boost::system::error_code success_ec_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/io_uring_file_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_FILE) // && defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_FILE_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_THREAD_CONTEXT_HPP #define BOOST_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 <boost/asio/detail/call_stack.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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. BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/thread_context.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_THREAD_CONTEXT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/dependent_type.hpp
// // detail/dependent_type.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 BOOST_ASIO_DETAIL_DEPENDENT_TYPE_HPP #define BOOST_ASIO_DETAIL_DEPENDENT_TYPE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename DependsOn, typename T> struct dependent_type { typedef T type; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_DEPENDENT_TYPE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/source_location.hpp
// // detail/source_location.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 BOOST_ASIO_DETAIL_SOURCE_LOCATION_HPP #define BOOST_ASIO_DETAIL_SOURCE_LOCATION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #if defined(BOOST_ASIO_HAS_STD_SOURCE_LOCATION) # include <source_location> #elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) # include <experimental/source_location> #else // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) # error BOOST_ASIO_HAS_SOURCE_LOCATION is set \ but no source_location is available #endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_HAS_STD_SOURCE_LOCATION) using std::source_location; #elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) using std::experimental::source_location; #endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_SOURCE_LOCATION) } // namespace detail } // namespace asio } // namespace boost #endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION) #endif // BOOST_ASIO_DETAIL_SOURCE_LOCATION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/socket_option.hpp
// // detail/socket_option.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 BOOST_ASIO_DETAIL_SOCKET_OPTION_HPP #define BOOST_ASIO_DETAIL_SOCKET_OPTION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <cstddef> #include <stdexcept> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/throw_exception.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { namespace socket_option { // Helper template for implementing boolean-based options. template <int Level, int Name> class boolean { public: // Default constructor. boolean() : value_(0) { } // Construct with a specific option value. explicit boolean(bool v) : value_(v ? 1 : 0) { } // Set the current value of the boolean. boolean& operator=(bool v) { value_ = v ? 1 : 0; return *this; } // Get the current value of the boolean. bool value() const { return !!value_; } // Convert to bool. operator bool() const { return !!value_; } // Test for false. bool operator!() const { return !value_; } // Get the level of the socket option. template <typename Protocol> int level(const Protocol&) const { return Level; } // Get the name of the socket option. template <typename Protocol> int name(const Protocol&) const { return Name; } // Get the address of the boolean data. template <typename Protocol> int* data(const Protocol&) { return &value_; } // Get the address of the boolean data. template <typename Protocol> const int* data(const Protocol&) const { return &value_; } // Get the size of the boolean data. template <typename Protocol> std::size_t size(const Protocol&) const { return sizeof(value_); } // Set the size of the boolean data. template <typename Protocol> void resize(const Protocol&, std::size_t s) { // On some platforms (e.g. Windows Vista), the getsockopt function will // return the size of a boolean socket option as one byte, even though a // four byte integer was passed in. switch (s) { case sizeof(char): value_ = *reinterpret_cast<char*>(&value_) ? 1 : 0; break; case sizeof(value_): break; default: { std::length_error ex("boolean socket option resize"); boost::asio::detail::throw_exception(ex); } } } private: int value_; }; // Helper template for implementing integer options. template <int Level, int Name> class integer { public: // Default constructor. integer() : value_(0) { } // Construct with a specific option value. explicit integer(int v) : value_(v) { } // Set the value of the int option. integer& operator=(int v) { value_ = v; return *this; } // Get the current value of the int option. int value() const { return value_; } // Get the level of the socket option. template <typename Protocol> int level(const Protocol&) const { return Level; } // Get the name of the socket option. template <typename Protocol> int name(const Protocol&) const { return Name; } // Get the address of the int data. template <typename Protocol> int* data(const Protocol&) { return &value_; } // Get the address of the int data. template <typename Protocol> const int* data(const Protocol&) const { return &value_; } // Get the size of the int data. template <typename Protocol> std::size_t size(const Protocol&) const { return sizeof(value_); } // Set the size of the int data. template <typename Protocol> void resize(const Protocol&, std::size_t s) { if (s != sizeof(value_)) { std::length_error ex("integer socket option resize"); boost::asio::detail::throw_exception(ex); } } private: int value_; }; // Helper template for implementing linger options. template <int Level, int Name> class linger { public: // Default constructor. linger() { value_.l_onoff = 0; value_.l_linger = 0; } // Construct with specific option values. linger(bool e, int t) { enabled(e); timeout BOOST_ASIO_PREVENT_MACRO_SUBSTITUTION(t); } // Set the value for whether linger is enabled. void enabled(bool value) { value_.l_onoff = value ? 1 : 0; } // Get the value for whether linger is enabled. bool enabled() const { return value_.l_onoff != 0; } // Set the value for the linger timeout. void timeout BOOST_ASIO_PREVENT_MACRO_SUBSTITUTION(int value) { #if defined(WIN32) value_.l_linger = static_cast<u_short>(value); #else value_.l_linger = value; #endif } // Get the value for the linger timeout. int timeout BOOST_ASIO_PREVENT_MACRO_SUBSTITUTION() const { return static_cast<int>(value_.l_linger); } // Get the level of the socket option. template <typename Protocol> int level(const Protocol&) const { return Level; } // Get the name of the socket option. template <typename Protocol> int name(const Protocol&) const { return Name; } // Get the address of the linger data. template <typename Protocol> detail::linger_type* data(const Protocol&) { return &value_; } // Get the address of the linger data. template <typename Protocol> const detail::linger_type* data(const Protocol&) const { return &value_; } // Get the size of the linger data. template <typename Protocol> std::size_t size(const Protocol&) const { return sizeof(value_); } // Set the size of the int data. template <typename Protocol> void resize(const Protocol&, std::size_t s) { if (s != sizeof(value_)) { std::length_error ex("linger socket option resize"); boost::asio::detail::throw_exception(ex); } } private: detail::linger_type value_; }; } // namespace socket_option } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SOCKET_OPTION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_overlapped_op.hpp
// // detail/win_iocp_overlapped_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 BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class win_iocp_overlapped_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_overlapped_op); win_iocp_overlapped_op(Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_overlapped_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& result_ec, std::size_t bytes_transferred) { boost::system::error_code ec(result_ec); // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); win_iocp_overlapped_op* o(static_cast<win_iocp_overlapped_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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_)); BOOST_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, boost::system::error_code, std::size_t> handler(o->handler_, ec, bytes_transferred); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/tss_ptr.hpp
// // detail/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 BOOST_ASIO_DETAIL_TSS_PTR_HPP #define BOOST_ASIO_DETAIL_TSS_PTR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) # include <boost/asio/detail/null_tss_ptr.hpp> #elif defined(BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION) # include <boost/asio/detail/keyword_tss_ptr.hpp> #elif defined(BOOST_ASIO_WINDOWS) # include <boost/asio/detail/win_tss_ptr.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_tss_ptr.hpp> #else # error Only Windows and POSIX are supported! #endif #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T> class tss_ptr #if !defined(BOOST_ASIO_HAS_THREADS) : public null_tss_ptr<T> #elif defined(BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION) : public keyword_tss_ptr<T> #elif defined(BOOST_ASIO_WINDOWS) : public win_tss_ptr<T> #elif defined(BOOST_ASIO_HAS_PTHREADS) : public posix_tss_ptr<T> #endif { public: void operator=(T* value) { #if !defined(BOOST_ASIO_HAS_THREADS) null_tss_ptr<T>::operator=(value); #elif defined(BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION) keyword_tss_ptr<T>::operator=(value); #elif defined(BOOST_ASIO_WINDOWS) win_tss_ptr<T>::operator=(value); #elif defined(BOOST_ASIO_HAS_PTHREADS) posix_tss_ptr<T>::operator=(value); #endif } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_TSS_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/object_pool.hpp
// // detail/object_pool.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 BOOST_ASIO_DETAIL_OBJECT_POOL_HPP #define BOOST_ASIO_DETAIL_OBJECT_POOL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Object> class object_pool; class object_pool_access { public: template <typename Object> static Object* create() { return new Object; } template <typename Object, typename Arg> static Object* create(Arg arg) { return new Object(arg); } template <typename Object> static void destroy(Object* o) { delete o; } template <typename Object> static Object*& next(Object* o) { return o->next_; } template <typename Object> static Object*& prev(Object* o) { return o->prev_; } }; template <typename Object> class object_pool : private noncopyable { public: // Constructor. object_pool() : live_list_(0), free_list_(0) { } // Destructor destroys all objects. ~object_pool() { destroy_list(live_list_); destroy_list(free_list_); } // Get the object at the start of the live list. Object* first() { return live_list_; } // Allocate a new object. Object* alloc() { Object* o = free_list_; if (o) free_list_ = object_pool_access::next(free_list_); else o = object_pool_access::create<Object>(); object_pool_access::next(o) = live_list_; object_pool_access::prev(o) = 0; if (live_list_) object_pool_access::prev(live_list_) = o; live_list_ = o; return o; } // Allocate a new object with an argument. template <typename Arg> Object* alloc(Arg arg) { Object* o = free_list_; if (o) free_list_ = object_pool_access::next(free_list_); else o = object_pool_access::create<Object>(arg); object_pool_access::next(o) = live_list_; object_pool_access::prev(o) = 0; if (live_list_) object_pool_access::prev(live_list_) = o; live_list_ = o; return o; } // Free an object. Moves it to the free list. No destructors are run. void free(Object* o) { if (live_list_ == o) live_list_ = object_pool_access::next(o); if (object_pool_access::prev(o)) { object_pool_access::next(object_pool_access::prev(o)) = object_pool_access::next(o); } if (object_pool_access::next(o)) { object_pool_access::prev(object_pool_access::next(o)) = object_pool_access::prev(o); } object_pool_access::next(o) = free_list_; object_pool_access::prev(o) = 0; free_list_ = o; } private: // Helper function to destroy all elements in a list. void destroy_list(Object* list) { while (list) { Object* o = list; list = object_pool_access::next(o); object_pool_access::destroy(o); } } // The list of live objects. Object* live_list_; // The free list. Object* free_list_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_OBJECT_POOL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_tss_ptr.hpp
// // detail/posix_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 BOOST_ASIO_DETAIL_POSIX_TSS_PTR_HPP #define BOOST_ASIO_DETAIL_POSIX_TSS_PTR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_PTHREADS) #include <pthread.h> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Helper function to create thread-specific storage. BOOST_ASIO_DECL void posix_tss_ptr_create(pthread_key_t& key); template <typename T> class posix_tss_ptr : private noncopyable { public: // Constructor. posix_tss_ptr() { posix_tss_ptr_create(tss_key_); } // Destructor. ~posix_tss_ptr() { ::pthread_key_delete(tss_key_); } // Get the value. operator T*() const { return static_cast<T*>(::pthread_getspecific(tss_key_)); } // Set the value. void operator=(T* value) { ::pthread_setspecific(tss_key_, value); } private: // Thread-specific storage to allow unlocked access to determine whether a // thread is a member of the pool. pthread_key_t tss_key_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/posix_tss_ptr.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_TSS_PTR_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_IO_URING_SOCKET_SERVICE_BASE_HPP #define BOOST_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 <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IO_URING) #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/buffer.hpp> #include <boost/asio/cancellation_type.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/socket_base.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/io_uring_null_buffers_op.hpp> #include <boost/asio/detail/io_uring_service.hpp> #include <boost/asio/detail/io_uring_socket_recv_op.hpp> #include <boost/asio/detail/io_uring_socket_recvmsg_op.hpp> #include <boost/asio/detail/io_uring_socket_send_op.hpp> #include <boost/asio/detail/io_uring_wait_op.hpp> #include <boost/asio/detail/socket_holder.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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. BOOST_ASIO_DECL io_uring_socket_service_base(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void base_shutdown(); // Construct a new socket implementation. BOOST_ASIO_DECL void construct(base_implementation_type& impl); // Move-construct a new socket implementation. BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl, base_implementation_type& other_impl) noexcept; // Move-assign from another socket implementation. BOOST_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. BOOST_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. BOOST_ASIO_DECL boost::system::error_code close( base_implementation_type& impl, boost::system::error_code& ec); // Release ownership of the socket. BOOST_ASIO_DECL socket_type release( base_implementation_type& impl, boost::system::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. BOOST_ASIO_DECL boost::system::error_code cancel( base_implementation_type& impl, boost::system::error_code& ec); // Determine whether the socket is at the out-of-band data mark. bool at_mark(const base_implementation_type& impl, boost::system::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, boost::system::error_code& ec) const { return socket_ops::available(impl.socket_, ec); } // Place the socket into the state where it will listen for new connections. boost::system::error_code listen(base_implementation_type& impl, int backlog, boost::system::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> boost::system::error_code io_control(base_implementation_type& impl, IO_Control_Command& command, boost::system::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. boost::system::error_code non_blocking(base_implementation_type& impl, bool mode, boost::system::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. boost::system::error_code native_non_blocking(base_implementation_type& impl, bool mode, boost::system::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. boost::system::error_code wait(base_implementation_type& impl, socket_base::wait_type w, boost::system::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 = boost::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.socket_, poll_flags, handler, io_ex); BOOST_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, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::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, boost::system::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::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 = { boost::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); } BOOST_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<boost::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::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 = { boost::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); } BOOST_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, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::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, boost::system::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 = boost_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 = boost::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 = { boost::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); } BOOST_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<boost::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 = boost_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 = boost::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 = { boost::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); } BOOST_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, boost::system::error_code& ec) { buffer_sequence_adapter<boost::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, boost::system::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 = boost_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 = boost::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 = { boost::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); } BOOST_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 = boost_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 = boost::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 = { boost::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); } BOOST_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. BOOST_ASIO_DECL boost::system::error_code do_open( base_implementation_type& impl, int af, int type, int protocol, boost::system::error_code& ec); // Assign a native socket to a socket implementation. BOOST_ASIO_DECL boost::system::error_code do_assign( base_implementation_type& impl, int type, const native_handle_type& native_socket, boost::system::error_code& ec); // Start the asynchronous read or write operation. BOOST_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. BOOST_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 boost::system::error_code success_ec_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/io_uring_socket_service_base.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_SOCKET_SERVICE_BASE_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP #define BOOST_ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <boost/asio/ip/basic_resolver_query.hpp> #include <boost/asio/ip/basic_resolver_results.hpp> #include <boost/asio/post.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/winrt_async_manager.hpp> #include <boost/asio/detail/winrt_resolve_op.hpp> #include <boost/asio/detail/winrt_utils.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_io_context.hpp> #else // defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/scheduler.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/push_options.hpp> namespace boost { 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 boost::asio::ip::basic_resolver_query<Protocol> query_type; // The results type. typedef boost::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, boost::system::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 = boost::system::error_code(e->HResult, boost::system::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 = boost_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 = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(query, handler, io_ex); BOOST_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_ = boost::system::error_code( e->HResult, boost::system::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&, boost::system::error_code& ec) { ec = boost::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) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const results_type results; boost::asio::post(io_ex, detail::bind_handler(handler, ec, results)); } private: // The scheduler implementation used for delivering completions. #if defined(BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/resolver_service.hpp
// // detail/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 BOOST_ASIO_DETAIL_RESOLVER_SERVICE_HPP #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <boost/asio/ip/basic_resolver_query.hpp> #include <boost/asio/ip/basic_resolver_results.hpp> #include <boost/asio/detail/concurrency_hint.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/resolve_endpoint_op.hpp> #include <boost/asio/detail/resolve_query_op.hpp> #include <boost/asio/detail/resolver_service_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol> class resolver_service : public execution_context_service_base<resolver_service<Protocol>>, public resolver_service_base { public: // The implementation type of the resolver. A cancellation token is used to // indicate to the background thread 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 boost::asio::ip::basic_resolver_query<Protocol> query_type; // The results type. typedef boost::asio::ip::basic_resolver_results<Protocol> results_type; // Constructor. resolver_service(execution_context& context) : execution_context_service_base<resolver_service<Protocol>>(context), resolver_service_base(context) { } // Destroy all user-defined handler objects owned by the service. void shutdown() { this->base_shutdown(); } // Perform any fork-related housekeeping. void notify_fork(execution_context::fork_event fork_ev) { this->base_notify_fork(fork_ev); } // Resolve a query to a list of entries. results_type resolve(implementation_type&, const query_type& qry, boost::system::error_code& ec) { boost::asio::detail::addrinfo_type* address_info = 0; socket_ops::getaddrinfo(qry.host_name().c_str(), qry.service_name().c_str(), qry.hints(), &address_info, ec); auto_addrinfo auto_address_info(address_info); BOOST_ASIO_ERROR_LOCATION(ec); return ec ? results_type() : results_type::create( address_info, qry.host_name(), qry.service_name()); } // Asynchronously resolve a query to a list of entries. template <typename Handler, typename IoExecutor> void async_resolve(implementation_type& impl, const query_type& qry, Handler& handler, const IoExecutor& io_ex) { // Allocate and construct an operation to wrap the handler. typedef resolve_query_op<Protocol, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(impl, qry, scheduler_, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "resolver", &impl, 0, "async_resolve")); start_resolve_op(p.p); p.v = p.p = 0; } // Resolve an endpoint to a list of entries. results_type resolve(implementation_type&, const endpoint_type& endpoint, boost::system::error_code& ec) { char host_name[NI_MAXHOST]; char service_name[NI_MAXSERV]; socket_ops::sync_getnameinfo(endpoint.data(), endpoint.size(), host_name, NI_MAXHOST, service_name, NI_MAXSERV, endpoint.protocol().type(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec ? results_type() : results_type::create( endpoint, host_name, service_name); } // Asynchronously resolve an endpoint to a list of entries. template <typename Handler, typename IoExecutor> void async_resolve(implementation_type& impl, const endpoint_type& endpoint, Handler& handler, const IoExecutor& io_ex) { // Allocate and construct an operation to wrap the handler. typedef resolve_endpoint_op<Protocol, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(impl, endpoint, scheduler_, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "resolver", &impl, 0, "async_resolve")); start_resolve_op(p.p); p.v = p.p = 0; } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/handler_work.hpp
// // detail/handler_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 BOOST_ASIO_DETAIL_HANDLER_WORK_HPP #define BOOST_ASIO_DETAIL_HANDLER_WORK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/associated_allocator.hpp> #include <boost/asio/associated_executor.hpp> #include <boost/asio/associated_immediate_executor.hpp> #include <boost/asio/detail/initiate_dispatch.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/work_dispatcher.hpp> #include <boost/asio/execution/allocator.hpp> #include <boost/asio/execution/blocking.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution/outstanding_work.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/prefer.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { class executor; class io_context; #if !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) class any_completion_executor; class any_io_executor; #endif // !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) namespace execution { template <typename...> class any_executor; } // namespace execution namespace detail { template <typename Executor, typename CandidateExecutor = void, typename IoContext = io_context, typename PolymorphicExecutor = executor, typename = void> class handler_work_base { public: explicit handler_work_base(int, int, const Executor& ex) noexcept : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } template <typename OtherExecutor> handler_work_base(bool /*base1_owns_work*/, const Executor& ex, const OtherExecutor& /*candidate*/) noexcept : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } handler_work_base(const handler_work_base& other) noexcept : executor_(other.executor_) { } handler_work_base(handler_work_base&& other) noexcept : executor_(static_cast<executor_type&&>(other.executor_)) { } bool owns_work() const noexcept { return true; } template <typename Function, typename Handler> void dispatch(Function& function, Handler& handler) { boost::asio::prefer(executor_, execution::allocator((get_associated_allocator)(handler)) ).execute(static_cast<Function&&>(function)); } private: typedef decay_t< prefer_result_t<Executor, execution::outstanding_work_t::tracked_t> > executor_type; executor_type executor_; }; template <typename Executor, typename CandidateExecutor, typename IoContext, typename PolymorphicExecutor> class handler_work_base<Executor, CandidateExecutor, IoContext, PolymorphicExecutor, enable_if_t< !execution::is_executor<Executor>::value && (!is_same<Executor, PolymorphicExecutor>::value || !is_same<CandidateExecutor, void>::value) > > { public: explicit handler_work_base(int, int, const Executor& ex) noexcept : executor_(ex), owns_work_(true) { executor_.on_work_started(); } handler_work_base(bool /*base1_owns_work*/, const Executor& ex, const Executor& candidate) noexcept : executor_(ex), owns_work_(ex != candidate) { if (owns_work_) executor_.on_work_started(); } template <typename OtherExecutor> handler_work_base(bool /*base1_owns_work*/, const Executor& ex, const OtherExecutor& /*candidate*/) noexcept : executor_(ex), owns_work_(true) { executor_.on_work_started(); } handler_work_base(const handler_work_base& other) noexcept : executor_(other.executor_), owns_work_(other.owns_work_) { if (owns_work_) executor_.on_work_started(); } handler_work_base(handler_work_base&& other) noexcept : executor_(static_cast<Executor&&>(other.executor_)), owns_work_(other.owns_work_) { other.owns_work_ = false; } ~handler_work_base() { if (owns_work_) executor_.on_work_finished(); } bool owns_work() const noexcept { return owns_work_; } template <typename Function, typename Handler> void dispatch(Function& function, Handler& handler) { executor_.dispatch(static_cast<Function&&>(function), boost::asio::get_associated_allocator(handler)); } private: Executor executor_; bool owns_work_; }; template <typename Executor, typename IoContext, typename PolymorphicExecutor> class handler_work_base<Executor, void, IoContext, PolymorphicExecutor, enable_if_t< is_same< Executor, typename IoContext::executor_type >::value > > { public: explicit handler_work_base(int, int, const Executor&) { } bool owns_work() const noexcept { return false; } template <typename Function, typename Handler> void dispatch(Function& function, Handler&) { // When using a native implementation, I/O completion handlers are // already dispatched according to the execution context's executor's // rules. We can call the function directly. static_cast<Function&&>(function)(); } }; template <typename Executor, typename IoContext> class handler_work_base<Executor, void, IoContext, Executor> { public: explicit handler_work_base(int, int, const Executor& ex) noexcept #if !defined(BOOST_ASIO_NO_TYPEID) : executor_( ex.target_type() == typeid(typename IoContext::executor_type) ? Executor() : ex) #else // !defined(BOOST_ASIO_NO_TYPEID) : executor_(ex) #endif // !defined(BOOST_ASIO_NO_TYPEID) { if (executor_) executor_.on_work_started(); } handler_work_base(bool /*base1_owns_work*/, const Executor& ex, const Executor& candidate) noexcept : executor_(ex != candidate ? ex : Executor()) { if (executor_) executor_.on_work_started(); } template <typename OtherExecutor> handler_work_base(const Executor& ex, const OtherExecutor&) noexcept : executor_(ex) { executor_.on_work_started(); } handler_work_base(const handler_work_base& other) noexcept : executor_(other.executor_) { if (executor_) executor_.on_work_started(); } handler_work_base(handler_work_base&& other) noexcept : executor_(static_cast<Executor&&>(other.executor_)) { } ~handler_work_base() { if (executor_) executor_.on_work_finished(); } bool owns_work() const noexcept { return !!executor_; } template <typename Function, typename Handler> void dispatch(Function& function, Handler& handler) { executor_.dispatch(static_cast<Function&&>(function), boost::asio::get_associated_allocator(handler)); } private: Executor executor_; }; template <typename... SupportableProperties, typename CandidateExecutor, typename IoContext, typename PolymorphicExecutor> class handler_work_base<execution::any_executor<SupportableProperties...>, CandidateExecutor, IoContext, PolymorphicExecutor> { public: typedef execution::any_executor<SupportableProperties...> executor_type; explicit handler_work_base(int, int, const executor_type& ex) noexcept #if !defined(BOOST_ASIO_NO_TYPEID) : executor_( ex.target_type() == typeid(typename IoContext::executor_type) ? executor_type() : boost::asio::prefer(ex, execution::outstanding_work.tracked)) #else // !defined(BOOST_ASIO_NO_TYPEID) : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) #endif // !defined(BOOST_ASIO_NO_TYPEID) { } handler_work_base(bool base1_owns_work, const executor_type& ex, const executor_type& candidate) noexcept : executor_( !base1_owns_work && ex == candidate ? executor_type() : boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } template <typename OtherExecutor> handler_work_base(bool /*base1_owns_work*/, const executor_type& ex, const OtherExecutor& /*candidate*/) noexcept : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } handler_work_base(const handler_work_base& other) noexcept : executor_(other.executor_) { } handler_work_base(handler_work_base&& other) noexcept : executor_(static_cast<executor_type&&>(other.executor_)) { } bool owns_work() const noexcept { return !!executor_; } template <typename Function, typename Handler> void dispatch(Function& function, Handler&) { executor_.execute(static_cast<Function&&>(function)); } private: executor_type executor_; }; #if !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) template <typename Executor, typename CandidateExecutor, typename IoContext, typename PolymorphicExecutor> class handler_work_base< Executor, CandidateExecutor, IoContext, PolymorphicExecutor, enable_if_t< is_same<Executor, any_completion_executor>::value || is_same<Executor, any_io_executor>::value > > { public: typedef Executor executor_type; explicit handler_work_base(int, int, const executor_type& ex) noexcept #if !defined(BOOST_ASIO_NO_TYPEID) : executor_( ex.target_type() == typeid(typename IoContext::executor_type) ? executor_type() : boost::asio::prefer(ex, execution::outstanding_work.tracked)) #else // !defined(BOOST_ASIO_NO_TYPEID) : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) #endif // !defined(BOOST_ASIO_NO_TYPEID) { } handler_work_base(bool base1_owns_work, const executor_type& ex, const executor_type& candidate) noexcept : executor_( !base1_owns_work && ex == candidate ? executor_type() : boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } template <typename OtherExecutor> handler_work_base(bool /*base1_owns_work*/, const executor_type& ex, const OtherExecutor& /*candidate*/) noexcept : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } handler_work_base(const handler_work_base& other) noexcept : executor_(other.executor_) { } handler_work_base(handler_work_base&& other) noexcept : executor_(static_cast<executor_type&&>(other.executor_)) { } bool owns_work() const noexcept { return !!executor_; } template <typename Function, typename Handler> void dispatch(Function& function, Handler&) { executor_.execute(static_cast<Function&&>(function)); } private: executor_type executor_; }; #endif // !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) template <typename Handler, typename IoExecutor, typename = void> class handler_work : handler_work_base<IoExecutor>, handler_work_base<associated_executor_t<Handler, IoExecutor>, IoExecutor> { public: typedef handler_work_base<IoExecutor> base1_type; typedef handler_work_base<associated_executor_t<Handler, IoExecutor>, IoExecutor> base2_type; handler_work(Handler& handler, const IoExecutor& io_ex) noexcept : base1_type(0, 0, io_ex), base2_type(base1_type::owns_work(), boost::asio::get_associated_executor(handler, io_ex), io_ex) { } template <typename Function> void complete(Function& function, Handler& handler) { if (!base1_type::owns_work() && !base2_type::owns_work()) { // When using a native implementation, I/O completion handlers are // already dispatched according to the execution context's executor's // rules. We can call the function directly. static_cast<Function&&>(function)(); } else { base2_type::dispatch(function, handler); } } }; template <typename Handler, typename IoExecutor> class handler_work< Handler, IoExecutor, enable_if_t< is_same< typename associated_executor<Handler, IoExecutor>::asio_associated_executor_is_unspecialised, void >::value > > : handler_work_base<IoExecutor> { public: typedef handler_work_base<IoExecutor> base1_type; handler_work(Handler&, const IoExecutor& io_ex) noexcept : base1_type(0, 0, io_ex) { } template <typename Function> void complete(Function& function, Handler& handler) { if (!base1_type::owns_work()) { // When using a native implementation, I/O completion handlers are // already dispatched according to the execution context's executor's // rules. We can call the function directly. static_cast<Function&&>(function)(); } else { base1_type::dispatch(function, handler); } } }; template <typename Handler, typename IoExecutor> class immediate_handler_work { public: typedef handler_work<Handler, IoExecutor> handler_work_type; explicit immediate_handler_work(handler_work_type&& w) : handler_work_(static_cast<handler_work_type&&>(w)) { } template <typename Function> void complete(Function& function, Handler& handler, const void* io_ex) { typedef associated_immediate_executor_t<Handler, IoExecutor> immediate_ex_type; immediate_ex_type immediate_ex = (get_associated_immediate_executor)( handler, *static_cast<const IoExecutor*>(io_ex)); (initiate_dispatch_with_executor<immediate_ex_type>(immediate_ex))( static_cast<Function&&>(function)); } private: handler_work_type handler_work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_HANDLER_WORK_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WAIT_HANDLER_HPP #define BOOST_ASIO_DETAIL_WAIT_HANDLER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class wait_handler : public wait_op { public: BOOST_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 boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. wait_handler* h(static_cast<wait_handler*>(base)); ptr p = { boost::asio::detail::addressof(h->handler_), h, h }; BOOST_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, boost::system::error_code> handler(h->handler_, h->ec_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WAIT_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_NULL_THREAD_HPP #define BOOST_ASIO_DETAIL_NULL_THREAD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class null_thread : private noncopyable { public: // Constructor. template <typename Function> null_thread(Function, unsigned int = 0) { boost::asio::detail::throw_error( boost::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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_HAS_THREADS) #endif // BOOST_ASIO_DETAIL_NULL_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_STD_THREAD_HPP #define BOOST_ASIO_DETAIL_STD_THREAD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <thread> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_STD_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_global.hpp
// // detail/null_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 BOOST_ASIO_DETAIL_NULL_GLOBAL_HPP #define BOOST_ASIO_DETAIL_NULL_GLOBAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T> struct null_global_impl { null_global_impl() : ptr_(0) { } // Destructor automatically cleans up the global. ~null_global_impl() { delete ptr_; } static null_global_impl instance_; T* ptr_; }; template <typename T> null_global_impl<T> null_global_impl<T>::instance_; template <typename T> T& null_global() { if (null_global_impl<T>::instance_.ptr_ == 0) null_global_impl<T>::instance_.ptr_ = new T; return *null_global_impl<T>::instance_.ptr_; } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_NULL_GLOBAL_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_FD_SET_ADAPTER_HPP #define BOOST_ASIO_DETAIL_FD_SET_ADAPTER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <boost/asio/detail/posix_fd_set_adapter.hpp> #include <boost/asio/detail/win_fd_set_adapter.hpp> namespace boost { namespace asio { namespace detail { #if defined(BOOST_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 } // namespace boost #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_FD_SET_ADAPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/chrono.hpp
// // detail/chrono.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 BOOST_ASIO_DETAIL_CHRONO_HPP #define BOOST_ASIO_DETAIL_CHRONO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <chrono> namespace boost { namespace asio { namespace chrono { using std::chrono::duration; using std::chrono::time_point; using std::chrono::duration_cast; using std::chrono::nanoseconds; using std::chrono::microseconds; using std::chrono::milliseconds; using std::chrono::seconds; using std::chrono::minutes; using std::chrono::hours; using std::chrono::time_point_cast; #if defined(BOOST_ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) typedef std::chrono::monotonic_clock steady_clock; #else // defined(BOOST_ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) using std::chrono::steady_clock; #endif // defined(BOOST_ASIO_HAS_STD_CHRONO_MONOTONIC_CLOCK) using std::chrono::system_clock; using std::chrono::high_resolution_clock; } // namespace chrono } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_CHRONO_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/recycling_allocator.hpp
// // detail/recycling_allocator.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 BOOST_ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP #define BOOST_ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/thread_context.hpp> #include <boost/asio/detail/thread_info_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T, typename Purpose = thread_info_base::default_tag> class recycling_allocator { public: typedef T value_type; template <typename U> struct rebind { typedef recycling_allocator<U, Purpose> other; }; recycling_allocator() { } template <typename U> recycling_allocator(const recycling_allocator<U, Purpose>&) { } T* allocate(std::size_t n) { void* p = thread_info_base::allocate(Purpose(), thread_context::top_of_thread_call_stack(), sizeof(T) * n, alignof(T)); return static_cast<T*>(p); } void deallocate(T* p, std::size_t n) { thread_info_base::deallocate(Purpose(), thread_context::top_of_thread_call_stack(), p, sizeof(T) * n); } }; template <typename Purpose> class recycling_allocator<void, Purpose> { public: typedef void value_type; template <typename U> struct rebind { typedef recycling_allocator<U, Purpose> other; }; recycling_allocator() { } template <typename U> recycling_allocator(const recycling_allocator<U, Purpose>&) { } }; template <typename Allocator, typename Purpose> struct get_recycling_allocator { typedef Allocator type; static type get(const Allocator& a) { return a; } }; template <typename T, typename Purpose> struct get_recycling_allocator<std::allocator<T>, Purpose> { typedef recycling_allocator<T, Purpose> type; static type get(const std::allocator<T>&) { return type(); } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/date_time_fwd.hpp
// // detail/date_time_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 BOOST_ASIO_DETAIL_DATE_TIME_FWD_HPP #define BOOST_ASIO_DETAIL_DATE_TIME_FWD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> namespace boost { namespace date_time { template<class T, class TimeSystem> class base_time; } // namespace date_time namespace posix_time { class ptime; } // namespace posix_time } // namespace boost #endif // BOOST_ASIO_DETAIL_DATE_TIME_FWD_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WIN_IOCP_IO_CONTEXT_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_IO_CONTEXT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/scoped_ptr.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/thread.hpp> #include <boost/asio/detail/thread_context.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/timer_queue_set.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/detail/win_iocp_operation.hpp> #include <boost/asio/detail/win_iocp_thread_info.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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. BOOST_ASIO_DECL win_iocp_io_context(boost::asio::execution_context& ctx, int concurrency_hint = -1, bool own_thread = true); // Destructor. BOOST_ASIO_DECL ~win_iocp_io_context(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Initialise the task. Nothing to do here. void init_task() { } // Register a handle with the IO completion port. BOOST_ASIO_DECL boost::system::error_code register_handle( HANDLE handle, boost::system::error_code& ec); // Run the event loop until stopped or no more work. BOOST_ASIO_DECL size_t run(boost::system::error_code& ec); // Run until stopped or one operation is performed. BOOST_ASIO_DECL size_t run_one(boost::system::error_code& ec); // Run until timeout, interrupted, or one operation is performed. BOOST_ASIO_DECL size_t wait_one(long usec, boost::system::error_code& ec); // Poll for operations without blocking. BOOST_ASIO_DECL size_t poll(boost::system::error_code& ec); // Poll for one operation without blocking. BOOST_ASIO_DECL size_t poll_one(boost::system::error_code& ec); // Stop the event processing loop. BOOST_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. BOOST_ASIO_DECL bool can_dispatch(); /// Capture the current exception so it can be rethrown from a run function. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_ASIO_DECL void on_completion(win_iocp_operation* op, const boost::system::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). BOOST_ASIO_DECL size_t do_one(DWORD msec, win_iocp_thread_info& this_thread, boost::system::error_code& ec); // Helper to calculate the GetQueuedCompletionStatus timeout. BOOST_ASIO_DECL static DWORD get_gqcs_timeout(); // Helper function to add a new timer queue. BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); // Helper function to remove a timer queue. BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); // Called to recalculate and update the timeout. BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/win_iocp_io_context.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_iocp_io_context.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_IO_CONTEXT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_async_op.hpp
// // detail/winrt_async_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 BOOST_ASIO_DETAIL_WINRT_ASYNC_OP_HPP #define BOOST_ASIO_DETAIL_WINRT_ASYNC_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename TResult> class winrt_async_op : public operation { public: // The error code to be passed to the completion handler. boost::system::error_code ec_; // The result of the operation, to be passed to the completion handler. TResult result_; protected: winrt_async_op(func_type complete_func) : operation(complete_func), result_() { } }; template <> class winrt_async_op<void> : public operation { public: // The error code to be passed to the completion handler. boost::system::error_code ec_; protected: winrt_async_op(func_type complete_func) : operation(complete_func) { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WINRT_ASYNC_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_FENCED_BLOCK_HPP #define BOOST_ASIO_DETAIL_FENCED_BLOCK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) \ || defined(BOOST_ASIO_DISABLE_FENCED_BLOCK) # include <boost/asio/detail/null_fenced_block.hpp> #else # include <boost/asio/detail/std_fenced_block.hpp> #endif namespace boost { namespace asio { namespace detail { #if !defined(BOOST_ASIO_HAS_THREADS) \ || defined(BOOST_ASIO_DISABLE_FENCED_BLOCK) typedef null_fenced_block fenced_block; #else typedef std_fenced_block fenced_block; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_FENCED_BLOCK_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WINRT_UTILS_HPP #define BOOST_ASIO_DETAIL_WINRT_UTILS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <codecvt> #include <cstdlib> #include <future> #include <locale> #include <robuffer.h> #include <windows.storage.streams.h> #include <wrl/implements.h> #include <boost/asio/buffer.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 boost::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); boost::asio::buffer_copy(boost::asio::buffer(bytes, size), buffers); b->Length = size; return b; } } // namespace winrt_utils } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_UTILS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/executor_function.hpp
// // detail/executor_function.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 BOOST_ASIO_DETAIL_EXECUTOR_FUNCTION_HPP #define BOOST_ASIO_DETAIL_EXECUTOR_FUNCTION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Lightweight, move-only function object wrapper. class executor_function { public: template <typename F, typename Alloc> explicit executor_function(F f, const Alloc& a) { // Allocate and construct an object to wrap the function. typedef impl<F, Alloc> impl_type; typename impl_type::ptr p = { detail::addressof(a), impl_type::ptr::allocate(a), 0 }; impl_ = new (p.v) impl_type(static_cast<F&&>(f), a); p.v = 0; } executor_function(executor_function&& other) noexcept : impl_(other.impl_) { other.impl_ = 0; } ~executor_function() { if (impl_) impl_->complete_(impl_, false); } void operator()() { if (impl_) { impl_base* i = impl_; impl_ = 0; i->complete_(i, true); } } private: // Base class for polymorphic function implementations. struct impl_base { void (*complete_)(impl_base*, bool); }; // Polymorphic function implementation. template <typename Function, typename Alloc> struct impl : impl_base { BOOST_ASIO_DEFINE_TAGGED_HANDLER_ALLOCATOR_PTR( thread_info_base::executor_function_tag, impl); template <typename F> impl(F&& f, const Alloc& a) : function_(static_cast<F&&>(f)), allocator_(a) { complete_ = &executor_function::complete<Function, Alloc>; } Function function_; Alloc allocator_; }; // Helper to complete function invocation. template <typename Function, typename Alloc> static void complete(impl_base* base, bool call) { // Take ownership of the function object. impl<Function, Alloc>* i(static_cast<impl<Function, Alloc>*>(base)); Alloc allocator(i->allocator_); typename impl<Function, Alloc>::ptr p = { detail::addressof(allocator), i, i }; // Make a copy of the function 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 function may be the true owner of the memory // associated with the function. Consequently, a local copy of the function // is required to ensure that any owning sub-object remains valid until // after we have deallocated the memory here. Function function(static_cast<Function&&>(i->function_)); p.reset(); // Make the upcall if required. if (call) { static_cast<Function&&>(function)(); } } impl_base* impl_; }; // Lightweight, non-owning, copyable function object wrapper. class executor_function_view { public: template <typename F> explicit executor_function_view(F& f) noexcept : complete_(&executor_function_view::complete<F>), function_(&f) { } void operator()() { complete_(function_); } private: // Helper to complete function invocation. template <typename F> static void complete(void* f) { (*static_cast<F*>(f))(); } void (*complete_)(void*); void* function_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_EXECUTOR_FUNCTION_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_TIMER_QUEUE_SET_HPP #define BOOST_ASIO_DETAIL_TIMER_QUEUE_SET_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class timer_queue_set { public: // Constructor. BOOST_ASIO_DECL timer_queue_set(); // Add a timer queue to the set. BOOST_ASIO_DECL void insert(timer_queue_base* q); // Remove a timer queue from the set. BOOST_ASIO_DECL void erase(timer_queue_base* q); // Determine whether all queues are empty. BOOST_ASIO_DECL bool all_empty() const; // Get the wait duration in milliseconds. BOOST_ASIO_DECL long wait_duration_msec(long max_duration) const; // Get the wait duration in microseconds. BOOST_ASIO_DECL long wait_duration_usec(long max_duration) const; // Dequeue all ready timers. BOOST_ASIO_DECL void get_ready_timers(op_queue<operation>& ops); // Dequeue all timers. BOOST_ASIO_DECL void get_all_timers(op_queue<operation>& ops); private: timer_queue_base* first_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/timer_queue_set.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_SET_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_resolve_op.hpp
// // detail/winrt_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 BOOST_ASIO_DETAIL_WINRT_RESOLVE_OP_HPP #define BOOST_ASIO_DETAIL_WINRT_RESOLVE_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/winrt_async_op.hpp> #include <boost/asio/ip/basic_resolver_results.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol, typename Handler, typename IoExecutor> class winrt_resolve_op : public winrt_async_op< Windows::Foundation::Collections::IVectorView< Windows::Networking::EndpointPair^>^> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(winrt_resolve_op); typedef typename Protocol::endpoint endpoint_type; typedef boost::asio::ip::basic_resolver_query<Protocol> query_type; typedef boost::asio::ip::basic_resolver_results<Protocol> results_type; winrt_resolve_op(const query_type& query, Handler& handler, const IoExecutor& io_ex) : winrt_async_op< Windows::Foundation::Collections::IVectorView< Windows::Networking::EndpointPair^>^>( &winrt_resolve_op::do_complete), query_(query), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code&, std::size_t) { // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); winrt_resolve_op* o(static_cast<winrt_resolve_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; BOOST_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_)); results_type results = results_type(); if (!o->ec_) { try { results = results_type::create(o->result_, o->query_.hints(), o->query_.host_name(), o->query_.service_name()); } catch (Platform::Exception^ e) { o->ec_ = boost::system::error_code(e->HResult, boost::system::system_category()); } } // 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, boost::system::error_code, results_type> handler(o->handler_, o->ec_, results); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "...")); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: query_type query_; Handler handler_; handler_work<Handler, IoExecutor> executor_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_RESOLVE_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_IO_CONTROL_HPP #define BOOST_ASIO_DETAIL_IO_CONTROL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <cstddef> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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>(BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IO_CONTROL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_fd_set_adapter.hpp
// // detail/win_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 BOOST_ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP #define BOOST_ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/reactor_op_queue.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Adapts the FD_SET type to meet the Descriptor_Set concept's requirements. class win_fd_set_adapter : noncopyable { public: enum { default_fd_set_size = 1024 }; win_fd_set_adapter() : capacity_(default_fd_set_size), max_descriptor_(invalid_socket) { fd_set_ = static_cast<win_fd_set*>(::operator new( sizeof(win_fd_set) - sizeof(SOCKET) + sizeof(SOCKET) * (capacity_))); fd_set_->fd_count = 0; } ~win_fd_set_adapter() { ::operator delete(fd_set_); } void reset() { fd_set_->fd_count = 0; max_descriptor_ = invalid_socket; } bool set(socket_type descriptor) { for (u_int i = 0; i < fd_set_->fd_count; ++i) if (fd_set_->fd_array[i] == descriptor) return true; reserve(fd_set_->fd_count + 1); fd_set_->fd_array[fd_set_->fd_count++] = descriptor; return true; } void set(reactor_op_queue<socket_type>& operations, op_queue<operation>&) { reactor_op_queue<socket_type>::iterator i = operations.begin(); while (i != operations.end()) { reactor_op_queue<socket_type>::iterator op_iter = i++; reserve(fd_set_->fd_count + 1); fd_set_->fd_array[fd_set_->fd_count++] = op_iter->first; } } bool is_set(socket_type descriptor) const { return !!__WSAFDIsSet(descriptor, const_cast<fd_set*>(reinterpret_cast<const fd_set*>(fd_set_))); } operator fd_set*() { return reinterpret_cast<fd_set*>(fd_set_); } socket_type max_descriptor() const { return max_descriptor_; } void perform(reactor_op_queue<socket_type>& operations, op_queue<operation>& ops) const { for (u_int i = 0; i < fd_set_->fd_count; ++i) operations.perform_operations(fd_set_->fd_array[i], ops); } private: // This structure is defined to be compatible with the Windows API fd_set // structure, but without being dependent on the value of FD_SETSIZE. We use // the "struct hack" to allow the number of descriptors to be varied at // runtime. struct win_fd_set { u_int fd_count; SOCKET fd_array[1]; }; // Increase the fd_set_ capacity to at least the specified number of elements. void reserve(u_int n) { if (n <= capacity_) return; u_int new_capacity = capacity_ + capacity_ / 2; if (new_capacity < n) new_capacity = n; win_fd_set* new_fd_set = static_cast<win_fd_set*>(::operator new( sizeof(win_fd_set) - sizeof(SOCKET) + sizeof(SOCKET) * (new_capacity))); new_fd_set->fd_count = fd_set_->fd_count; for (u_int i = 0; i < fd_set_->fd_count; ++i) new_fd_set->fd_array[i] = fd_set_->fd_array[i]; ::operator delete(fd_set_); fd_set_ = new_fd_set; capacity_ = new_capacity; } win_fd_set* fd_set_; u_int capacity_; socket_type max_descriptor_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/is_executor.hpp
// // detail/is_executor.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 BOOST_ASIO_DETAIL_IS_EXECUTOR_HPP #define BOOST_ASIO_DETAIL_IS_EXECUTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct executor_memfns_base { void context(); void on_work_started(); void on_work_finished(); void dispatch(); void post(); void defer(); }; template <typename T> struct executor_memfns_derived : T, executor_memfns_base { }; template <typename T, T> struct executor_memfns_check { }; template <typename> char (&context_memfn_helper(...))[2]; template <typename T> char context_memfn_helper( executor_memfns_check< void (executor_memfns_base::*)(), &executor_memfns_derived<T>::context>*); template <typename> char (&on_work_started_memfn_helper(...))[2]; template <typename T> char on_work_started_memfn_helper( executor_memfns_check< void (executor_memfns_base::*)(), &executor_memfns_derived<T>::on_work_started>*); template <typename> char (&on_work_finished_memfn_helper(...))[2]; template <typename T> char on_work_finished_memfn_helper( executor_memfns_check< void (executor_memfns_base::*)(), &executor_memfns_derived<T>::on_work_finished>*); template <typename> char (&dispatch_memfn_helper(...))[2]; template <typename T> char dispatch_memfn_helper( executor_memfns_check< void (executor_memfns_base::*)(), &executor_memfns_derived<T>::dispatch>*); template <typename> char (&post_memfn_helper(...))[2]; template <typename T> char post_memfn_helper( executor_memfns_check< void (executor_memfns_base::*)(), &executor_memfns_derived<T>::post>*); template <typename> char (&defer_memfn_helper(...))[2]; template <typename T> char defer_memfn_helper( executor_memfns_check< void (executor_memfns_base::*)(), &executor_memfns_derived<T>::defer>*); template <typename T> struct is_executor_class : integral_constant<bool, sizeof(context_memfn_helper<T>(0)) != 1 && sizeof(on_work_started_memfn_helper<T>(0)) != 1 && sizeof(on_work_finished_memfn_helper<T>(0)) != 1 && sizeof(dispatch_memfn_helper<T>(0)) != 1 && sizeof(post_memfn_helper<T>(0)) != 1 && sizeof(defer_memfn_helper<T>(0)) != 1> { }; template <typename T> struct is_executor : conditional<is_class<T>::value, is_executor_class<T>, false_type>::type { }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IS_EXECUTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/completion_handler.hpp
// // detail/completion_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 BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP #define BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class completion_handler : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(completion_handler); completion_handler(Handler& h, const IoExecutor& io_ex) : operation(&completion_handler::do_complete), handler_(static_cast<Handler&&>(h)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. completion_handler* h(static_cast<completion_handler*>(base)); ptr p = { boost::asio::detail::addressof(h->handler_), h, h }; BOOST_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. Handler handler(static_cast<Handler&&>(h->handler_)); p.h = boost::asio::detail::addressof(handler); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN(()); w.complete(handler, handler); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/string_view.hpp
// // detail/string_view.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 BOOST_ASIO_DETAIL_STRING_VIEW_HPP #define BOOST_ASIO_DETAIL_STRING_VIEW_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_STRING_VIEW) #if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) # include <string_view> #elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) # include <experimental/string_view> #else // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) # error BOOST_ASIO_HAS_STRING_VIEW is set but no string_view is available #endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) namespace boost { namespace asio { #if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) using std::basic_string_view; using std::string_view; #elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) using std::experimental::basic_string_view; using std::experimental::string_view; #endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) } // namespace asio } // namespace boost # define BOOST_ASIO_STRING_VIEW_PARAM boost::asio::string_view #else // defined(BOOST_ASIO_HAS_STRING_VIEW) # define BOOST_ASIO_STRING_VIEW_PARAM const std::string& #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) #endif // BOOST_ASIO_DETAIL_STRING_VIEW_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_ARRAY_FWD_HPP #define BOOST_ASIO_DETAIL_ARRAY_FWD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/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 // BOOST_ASIO_DETAIL_ARRAY_FWD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/global.hpp
// // detail/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 BOOST_ASIO_DETAIL_GLOBAL_HPP #define BOOST_ASIO_DETAIL_GLOBAL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) # include <boost/asio/detail/null_global.hpp> #elif defined(BOOST_ASIO_WINDOWS) # include <boost/asio/detail/win_global.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_global.hpp> #else # include <boost/asio/detail/std_global.hpp> #endif namespace boost { namespace asio { namespace detail { template <typename T> inline T& global() { #if !defined(BOOST_ASIO_HAS_THREADS) return null_global<T>(); #elif defined(BOOST_ASIO_WINDOWS) return win_global<T>(); #elif defined(BOOST_ASIO_HAS_PTHREADS) return posix_global<T>(); #else return std_global<T>(); #endif } } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_GLOBAL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_service_base.hpp
// // detail/reactive_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 BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_IOCP) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/buffer.hpp> #include <boost/asio/cancellation_type.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/socket_base.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/reactive_null_buffers_op.hpp> #include <boost/asio/detail/reactive_socket_recv_op.hpp> #include <boost/asio/detail/reactive_socket_recvmsg_op.hpp> #include <boost/asio/detail/reactive_socket_send_op.hpp> #include <boost/asio/detail/reactive_wait_op.hpp> #include <boost/asio/detail/reactor.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/socket_holder.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class reactive_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-descriptor data used by the reactor. reactor::per_descriptor_data reactor_data_; }; // Constructor. BOOST_ASIO_DECL reactive_socket_service_base(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void base_shutdown(); // Construct a new socket implementation. BOOST_ASIO_DECL void construct(base_implementation_type& impl); // Move-construct a new socket implementation. BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl, base_implementation_type& other_impl) noexcept; // Move-assign from another socket implementation. BOOST_ASIO_DECL void base_move_assign(base_implementation_type& impl, reactive_socket_service_base& other_service, base_implementation_type& other_impl); // Destroy a socket implementation. BOOST_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. BOOST_ASIO_DECL boost::system::error_code close( base_implementation_type& impl, boost::system::error_code& ec); // Release ownership of the socket. BOOST_ASIO_DECL socket_type release( base_implementation_type& impl, boost::system::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. BOOST_ASIO_DECL boost::system::error_code cancel( base_implementation_type& impl, boost::system::error_code& ec); // Determine whether the socket is at the out-of-band data mark. bool at_mark(const base_implementation_type& impl, boost::system::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, boost::system::error_code& ec) const { return socket_ops::available(impl.socket_, ec); } // Place the socket into the state where it will listen for new connections. boost::system::error_code listen(base_implementation_type& impl, int backlog, boost::system::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> boost::system::error_code io_control(base_implementation_type& impl, IO_Control_Command& command, boost::system::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. boost::system::error_code non_blocking(base_implementation_type& impl, bool mode, boost::system::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. boost::system::error_code native_non_blocking(base_implementation_type& impl, bool mode, boost::system::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. boost::system::error_code wait(base_implementation_type& impl, socket_base::wait_type w, boost::system::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 = boost::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_wait_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_wait")); int op_type; switch (w) { case socket_base::wait_read: op_type = reactor::read_op; break; case socket_base::wait_write: op_type = reactor::write_op; break; case socket_base::wait_error: op_type = reactor::except_op; break; default: p.p->ec_ = boost::asio::error::invalid_argument; start_op(impl, reactor::read_op, p.p, is_continuation, false, true, &io_ex, 0); p.v = p.p = 0; return; } // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, op_type); } start_op(impl, op_type, p.p, is_continuation, false, false, &io_ex, 0); 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, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::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, boost::system::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_send_op< ConstBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::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<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::write_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_send")); start_op(impl, reactor::write_op, p.p, is_continuation, true, ((impl.state_ & socket_ops::stream_oriented) && buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::all_empty(buffers)), &io_ex, 0); 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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::write_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_send(null_buffers)")); start_op(impl, reactor::write_op, p.p, is_continuation, false, false, &io_ex, 0); 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, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::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, boost::system::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_recv_op< MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::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<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_receive")); start_op(impl, (flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, p.p, is_continuation, (flags & socket_base::message_out_of_band) == 0, ((impl.state_ & socket_ops::stream_oriented) && buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::all_empty(buffers)), &io_ex, 0); 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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_receive(null_buffers)")); start_op(impl, (flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, p.p, is_continuation, false, false, &io_ex, 0); 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, boost::system::error_code& ec) { buffer_sequence_adapter<boost::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, boost::system::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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_socket_recvmsg_op< MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, impl.socket_, 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<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.context(), *p.p, "socket", &impl, impl.socket_, "async_receive_with_flags")); start_op(impl, (in_flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, p.p, is_continuation, (in_flags & socket_base::message_out_of_band) == 0, false, &io_ex, 0); 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 = boost_asio_handler_cont_helpers::is_continuation(handler); associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef reactive_null_buffers_op<Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(success_ec_, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<reactor_op_cancellation>( &reactor_, &impl.reactor_data_, impl.socket_, reactor::read_op); } BOOST_ASIO_HANDLER_CREATION((reactor_.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, (in_flags & socket_base::message_out_of_band) ? reactor::except_op : reactor::read_op, p.p, is_continuation, false, false, &io_ex, 0); p.v = p.p = 0; } protected: // Open a new socket implementation. BOOST_ASIO_DECL boost::system::error_code do_open( base_implementation_type& impl, int af, int type, int protocol, boost::system::error_code& ec); // Assign a native socket to a socket implementation. BOOST_ASIO_DECL boost::system::error_code do_assign( base_implementation_type& impl, int type, const native_handle_type& native_socket, boost::system::error_code& ec); // Start the asynchronous read or write operation. BOOST_ASIO_DECL void do_start_op(base_implementation_type& impl, int op_type, reactor_op* op, bool is_continuation, bool is_non_blocking, bool noop, void (*on_immediate)(operation* op, bool, const void*), const void* immediate_arg); // Start the asynchronous operation for handlers that are specialised for // immediate completion. template <typename Op> void start_op(base_implementation_type& impl, int op_type, Op* op, bool is_continuation, bool is_non_blocking, bool noop, const void* io_ex, ...) { return do_start_op(impl, op_type, op, is_continuation, is_non_blocking, noop, &Op::do_immediate, io_ex); } // Start the asynchronous operation for handlers that are not specialised for // immediate completion. template <typename Op> void start_op(base_implementation_type& impl, int op_type, Op* op, bool is_continuation, bool is_non_blocking, bool noop, const void*, enable_if_t< is_same< typename associated_immediate_executor< typename Op::handler_type, typename Op::io_executor_type >::asio_associated_immediate_executor_is_unspecialised, void >::value >*) { return do_start_op(impl, op_type, op, is_continuation, is_non_blocking, noop, &reactor::call_post_immediate_completion, &reactor_); } // Start the asynchronous accept operation. BOOST_ASIO_DECL void do_start_accept_op(base_implementation_type& impl, reactor_op* op, bool is_continuation, bool peer_is_open, void (*on_immediate)(operation* op, bool, const void*), const void* immediate_arg); // Start the asynchronous accept operation for handlers that are specialised // for immediate completion. template <typename Op> void start_accept_op(base_implementation_type& impl, Op* op, bool is_continuation, bool peer_is_open, const void* io_ex, ...) { return do_start_accept_op(impl, op, is_continuation, peer_is_open, &Op::do_immediate, io_ex); } // Start the asynchronous operation for handlers that are not specialised for // immediate completion. template <typename Op> void start_accept_op(base_implementation_type& impl, Op* op, bool is_continuation, bool peer_is_open, const void*, enable_if_t< is_same< typename associated_immediate_executor< typename Op::handler_type, typename Op::io_executor_type >::asio_associated_immediate_executor_is_unspecialised, void >::value >*) { return do_start_accept_op(impl, op, is_continuation, peer_is_open, &reactor::call_post_immediate_completion, &reactor_); } // Start the asynchronous connect operation. BOOST_ASIO_DECL void do_start_connect_op(base_implementation_type& impl, reactor_op* op, bool is_continuation, const void* addr, size_t addrlen, void (*on_immediate)(operation* op, bool, const void*), const void* immediate_arg); // Start the asynchronous operation for handlers that are specialised for // immediate completion. template <typename Op> void start_connect_op(base_implementation_type& impl, Op* op, bool is_continuation, const void* addr, size_t addrlen, const void* io_ex, ...) { return do_start_connect_op(impl, op, is_continuation, addr, addrlen, &Op::do_immediate, io_ex); } // Start the asynchronous operation for handlers that are not specialised for // immediate completion. template <typename Op> void start_connect_op(base_implementation_type& impl, Op* op, bool is_continuation, const void* addr, size_t addrlen, const void*, enable_if_t< is_same< typename associated_immediate_executor< typename Op::handler_type, typename Op::io_executor_type >::asio_associated_immediate_executor_is_unspecialised, void >::value >*) { return do_start_connect_op(impl, op, is_continuation, addr, addrlen, &reactor::call_post_immediate_completion, &reactor_); } // Helper class used to implement per-operation cancellation class reactor_op_cancellation { public: reactor_op_cancellation(reactor* r, reactor::per_descriptor_data* p, socket_type d, int o) : reactor_(r), reactor_data_(p), descriptor_(d), op_type_(o) { } void operator()(cancellation_type_t type) { if (!!(type & (cancellation_type::terminal | cancellation_type::partial | cancellation_type::total))) { reactor_->cancel_ops_by_key(descriptor_, *reactor_data_, op_type_, this); } } private: reactor* reactor_; reactor::per_descriptor_data* reactor_data_; socket_type descriptor_; int op_type_; }; // The selector that performs event demultiplexing for the service. reactor& reactor_; // Cached success value to avoid accessing category singleton. const boost::system::error_code success_ec_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/reactive_socket_service_base.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // !defined(BOOST_ASIO_HAS_IOCP) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #endif // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SERVICE_BASE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/assert.hpp
// // detail/assert.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 BOOST_ASIO_DETAIL_ASSERT_HPP #define BOOST_ASIO_DETAIL_ASSERT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_BOOST_ASSERT) # include <boost/assert.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_ASSERT) # include <cassert> #endif // defined(BOOST_ASIO_HAS_BOOST_ASSERT) #if defined(BOOST_ASIO_HAS_BOOST_ASSERT) # define BOOST_ASIO_ASSERT(expr) BOOST_ASSERT(expr) #else // defined(BOOST_ASIO_HAS_BOOST_ASSERT) # define BOOST_ASIO_ASSERT(expr) assert(expr) #endif // defined(BOOST_ASIO_HAS_BOOST_ASSERT) #endif // BOOST_ASIO_DETAIL_ASSERT_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_IO_URING_SOCKET_ACCEPT_OP_HPP #define BOOST_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 <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IO_URING) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_work.hpp> #include <boost/asio/detail/io_uring_operation.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/socket_holder.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 boost::system::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) { BOOST_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) { BOOST_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_ == boost::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: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_accept_op); io_uring_socket_accept_op(const boost::system::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 boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_accept_op* o(static_cast<io_uring_socket_accept_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; // On success, assign new connection to peer socket object. if (owner) o->do_assign(); BOOST_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_)); BOOST_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, boost::system::error_code> handler(o->handler_, o->ec_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); w.complete(handler, handler.handler_); BOOST_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: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_move_accept_op); io_uring_socket_move_accept_op(const boost::system::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 boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_move_accept_op* o( static_cast<io_uring_socket_move_accept_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; // On success, assign new connection to peer socket object. if (owner) o->do_assign(); BOOST_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_)); BOOST_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, boost::system::error_code, peer_socket_type> handler(0, static_cast<Handler&&>(o->handler_), o->ec_, static_cast<peer_socket_type&&>(*o)); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "...")); w.complete(handler, handler.handler_); BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_SOCKET_ACCEPT_OP_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_ATOMIC_COUNT_HPP #define BOOST_ASIO_DETAIL_ATOMIC_COUNT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) // Nothing to include. #else // !defined(BOOST_ASIO_HAS_THREADS) # include <atomic> #endif // !defined(BOOST_ASIO_HAS_THREADS) namespace boost { namespace asio { namespace detail { #if !defined(BOOST_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(BOOST_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(BOOST_ASIO_HAS_THREADS) } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_ATOMIC_COUNT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winapp_thread.hpp
// // detail/winapp_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 BOOST_ASIO_DETAIL_WINAPP_THREAD_HPP #define BOOST_ASIO_DETAIL_WINAPP_THREAD_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS) && defined(BOOST_ASIO_WINDOWS_APP) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_ptr.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/throw_error.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { DWORD WINAPI winapp_thread_function(LPVOID arg); class winapp_thread : private noncopyable { public: // Constructor. template <typename Function> winapp_thread(Function f, unsigned int = 0) { scoped_ptr<func_base> arg(new func<Function>(f)); DWORD thread_id = 0; thread_ = ::CreateThread(0, 0, winapp_thread_function, arg.get(), 0, &thread_id); if (!thread_) { DWORD last_error = ::GetLastError(); boost::system::error_code ec(last_error, boost::asio::error::get_system_category()); boost::asio::detail::throw_error(ec, "thread"); } arg.release(); } // Destructor. ~winapp_thread() { ::CloseHandle(thread_); } // Wait for the thread to exit. void join() { ::WaitForSingleObjectEx(thread_, INFINITE, false); } // Get number of CPUs. static std::size_t hardware_concurrency() { SYSTEM_INFO system_info; ::GetNativeSystemInfo(&system_info); return system_info.dwNumberOfProcessors; } private: friend DWORD WINAPI winapp_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 winapp_thread_function(LPVOID arg) { scoped_ptr<winapp_thread::func_base> func( static_cast<winapp_thread::func_base*>(arg)); func->run(); return 0; } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS) && defined(BOOST_ASIO_WINDOWS_APP) #endif // BOOST_ASIO_DETAIL_WINAPP_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_SOCKET_TYPES_HPP #define BOOST_ASIO_DETAIL_SOCKET_TYPES_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) // Empty. #elif defined(BOOST_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 BOOST_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(BOOST_ASIO_WINDOWS_APP) # include <mswsock.h> # endif // !defined(BOOST_ASIO_WINDOWS_APP) # if defined(BOOST_ASIO_WSPIAPI_H_DEFINED) # undef _WSPIAPI_H_ # undef BOOST_ASIO_WSPIAPI_H_DEFINED # endif // defined(BOOST_ASIO_WSPIAPI_H_DEFINED) # if !defined(BOOST_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(BOOST_ASIO_WINDOWS_APP) # pragma comment(lib, "mswsock.lib") # endif // !defined(BOOST_ASIO_WINDOWS_APP) # endif // defined(_MSC_VER) || defined(__BORLANDC__) # endif // !defined(BOOST_ASIO_NO_DEFAULT_LINKED_LIBS) # include <boost/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 <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { #if defined(BOOST_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 BOOST_ASIO_OS_DEF(c) BOOST_ASIO_OS_DEF_##c # define BOOST_ASIO_OS_DEF_AF_UNSPEC 0 # define BOOST_ASIO_OS_DEF_AF_INET 2 # define BOOST_ASIO_OS_DEF_AF_INET6 23 # define BOOST_ASIO_OS_DEF_SOCK_STREAM 1 # define BOOST_ASIO_OS_DEF_SOCK_DGRAM 2 # define BOOST_ASIO_OS_DEF_SOCK_RAW 3 # define BOOST_ASIO_OS_DEF_SOCK_SEQPACKET 5 # define BOOST_ASIO_OS_DEF_IPPROTO_IP 0 # define BOOST_ASIO_OS_DEF_IPPROTO_IPV6 41 # define BOOST_ASIO_OS_DEF_IPPROTO_TCP 6 # define BOOST_ASIO_OS_DEF_IPPROTO_UDP 17 # define BOOST_ASIO_OS_DEF_IPPROTO_ICMP 1 # define BOOST_ASIO_OS_DEF_IPPROTO_ICMPV6 58 # define BOOST_ASIO_OS_DEF_FIONBIO 1 # define BOOST_ASIO_OS_DEF_FIONREAD 2 # define BOOST_ASIO_OS_DEF_INADDR_ANY 0 # define BOOST_ASIO_OS_DEF_MSG_OOB 0x1 # define BOOST_ASIO_OS_DEF_MSG_PEEK 0x2 # define BOOST_ASIO_OS_DEF_MSG_DONTROUTE 0x4 # define BOOST_ASIO_OS_DEF_MSG_EOR 0 // Not supported. # define BOOST_ASIO_OS_DEF_SHUT_RD 0x0 # define BOOST_ASIO_OS_DEF_SHUT_WR 0x1 # define BOOST_ASIO_OS_DEF_SHUT_RDWR 0x2 # define BOOST_ASIO_OS_DEF_SOMAXCONN 0x7fffffff # define BOOST_ASIO_OS_DEF_SOL_SOCKET 0xffff # define BOOST_ASIO_OS_DEF_SO_BROADCAST 0x20 # define BOOST_ASIO_OS_DEF_SO_DEBUG 0x1 # define BOOST_ASIO_OS_DEF_SO_DONTROUTE 0x10 # define BOOST_ASIO_OS_DEF_SO_KEEPALIVE 0x8 # define BOOST_ASIO_OS_DEF_SO_LINGER 0x80 # define BOOST_ASIO_OS_DEF_SO_OOBINLINE 0x100 # define BOOST_ASIO_OS_DEF_SO_SNDBUF 0x1001 # define BOOST_ASIO_OS_DEF_SO_RCVBUF 0x1002 # define BOOST_ASIO_OS_DEF_SO_SNDLOWAT 0x1003 # define BOOST_ASIO_OS_DEF_SO_RCVLOWAT 0x1004 # define BOOST_ASIO_OS_DEF_SO_REUSEADDR 0x4 # define BOOST_ASIO_OS_DEF_TCP_NODELAY 0x1 # define BOOST_ASIO_OS_DEF_IP_MULTICAST_IF 2 # define BOOST_ASIO_OS_DEF_IP_MULTICAST_TTL 3 # define BOOST_ASIO_OS_DEF_IP_MULTICAST_LOOP 4 # define BOOST_ASIO_OS_DEF_IP_ADD_MEMBERSHIP 5 # define BOOST_ASIO_OS_DEF_IP_DROP_MEMBERSHIP 6 # define BOOST_ASIO_OS_DEF_IP_TTL 7 # define BOOST_ASIO_OS_DEF_IPV6_UNICAST_HOPS 4 # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_IF 9 # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_HOPS 10 # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_LOOP 11 # define BOOST_ASIO_OS_DEF_IPV6_JOIN_GROUP 12 # define BOOST_ASIO_OS_DEF_IPV6_LEAVE_GROUP 13 # define BOOST_ASIO_OS_DEF_AI_CANONNAME 0x2 # define BOOST_ASIO_OS_DEF_AI_PASSIVE 0x1 # define BOOST_ASIO_OS_DEF_AI_NUMERICHOST 0x4 # define BOOST_ASIO_OS_DEF_AI_NUMERICSERV 0x8 # define BOOST_ASIO_OS_DEF_AI_V4MAPPED 0x800 # define BOOST_ASIO_OS_DEF_AI_ALL 0x100 # define BOOST_ASIO_OS_DEF_AI_ADDRCONFIG 0x400 # define BOOST_ASIO_OS_DEF_SA_RESTART 0x1 # define BOOST_ASIO_OS_DEF_SA_NOCLDSTOP 0x2 # define BOOST_ASIO_OS_DEF_SA_NOCLDWAIT 0x4 #elif defined(BOOST_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(BOOST_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 BOOST_ASIO_OS_DEF(c) BOOST_ASIO_OS_DEF_##c # define BOOST_ASIO_OS_DEF_AF_UNSPEC AF_UNSPEC # define BOOST_ASIO_OS_DEF_AF_INET AF_INET # define BOOST_ASIO_OS_DEF_AF_INET6 AF_INET6 # define BOOST_ASIO_OS_DEF_SOCK_STREAM SOCK_STREAM # define BOOST_ASIO_OS_DEF_SOCK_DGRAM SOCK_DGRAM # define BOOST_ASIO_OS_DEF_SOCK_RAW SOCK_RAW # define BOOST_ASIO_OS_DEF_SOCK_SEQPACKET SOCK_SEQPACKET # define BOOST_ASIO_OS_DEF_IPPROTO_IP IPPROTO_IP # define BOOST_ASIO_OS_DEF_IPPROTO_IPV6 IPPROTO_IPV6 # define BOOST_ASIO_OS_DEF_IPPROTO_TCP IPPROTO_TCP # define BOOST_ASIO_OS_DEF_IPPROTO_UDP IPPROTO_UDP # define BOOST_ASIO_OS_DEF_IPPROTO_ICMP IPPROTO_ICMP # define BOOST_ASIO_OS_DEF_IPPROTO_ICMPV6 IPPROTO_ICMPV6 # define BOOST_ASIO_OS_DEF_FIONBIO FIONBIO # define BOOST_ASIO_OS_DEF_FIONREAD FIONREAD # define BOOST_ASIO_OS_DEF_INADDR_ANY INADDR_ANY # define BOOST_ASIO_OS_DEF_MSG_OOB MSG_OOB # define BOOST_ASIO_OS_DEF_MSG_PEEK MSG_PEEK # define BOOST_ASIO_OS_DEF_MSG_DONTROUTE MSG_DONTROUTE # define BOOST_ASIO_OS_DEF_MSG_EOR 0 // Not supported on Windows. # define BOOST_ASIO_OS_DEF_SHUT_RD SD_RECEIVE # define BOOST_ASIO_OS_DEF_SHUT_WR SD_SEND # define BOOST_ASIO_OS_DEF_SHUT_RDWR SD_BOTH # define BOOST_ASIO_OS_DEF_SOMAXCONN SOMAXCONN # define BOOST_ASIO_OS_DEF_SOL_SOCKET SOL_SOCKET # define BOOST_ASIO_OS_DEF_SO_BROADCAST SO_BROADCAST # define BOOST_ASIO_OS_DEF_SO_DEBUG SO_DEBUG # define BOOST_ASIO_OS_DEF_SO_DONTROUTE SO_DONTROUTE # define BOOST_ASIO_OS_DEF_SO_KEEPALIVE SO_KEEPALIVE # define BOOST_ASIO_OS_DEF_SO_LINGER SO_LINGER # define BOOST_ASIO_OS_DEF_SO_OOBINLINE SO_OOBINLINE # define BOOST_ASIO_OS_DEF_SO_SNDBUF SO_SNDBUF # define BOOST_ASIO_OS_DEF_SO_RCVBUF SO_RCVBUF # define BOOST_ASIO_OS_DEF_SO_SNDLOWAT SO_SNDLOWAT # define BOOST_ASIO_OS_DEF_SO_RCVLOWAT SO_RCVLOWAT # define BOOST_ASIO_OS_DEF_SO_REUSEADDR SO_REUSEADDR # define BOOST_ASIO_OS_DEF_TCP_NODELAY TCP_NODELAY # define BOOST_ASIO_OS_DEF_IP_MULTICAST_IF IP_MULTICAST_IF # define BOOST_ASIO_OS_DEF_IP_MULTICAST_TTL IP_MULTICAST_TTL # define BOOST_ASIO_OS_DEF_IP_MULTICAST_LOOP IP_MULTICAST_LOOP # define BOOST_ASIO_OS_DEF_IP_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP # define BOOST_ASIO_OS_DEF_IP_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP # define BOOST_ASIO_OS_DEF_IP_TTL IP_TTL # define BOOST_ASIO_OS_DEF_IPV6_UNICAST_HOPS IPV6_UNICAST_HOPS # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_IF IPV6_MULTICAST_IF # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_HOPS IPV6_MULTICAST_HOPS # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_LOOP IPV6_MULTICAST_LOOP # define BOOST_ASIO_OS_DEF_IPV6_JOIN_GROUP IPV6_JOIN_GROUP # define BOOST_ASIO_OS_DEF_IPV6_LEAVE_GROUP IPV6_LEAVE_GROUP # define BOOST_ASIO_OS_DEF_AI_CANONNAME AI_CANONNAME # define BOOST_ASIO_OS_DEF_AI_PASSIVE AI_PASSIVE # define BOOST_ASIO_OS_DEF_AI_NUMERICHOST AI_NUMERICHOST # if defined(AI_NUMERICSERV) # define BOOST_ASIO_OS_DEF_AI_NUMERICSERV AI_NUMERICSERV # else # define BOOST_ASIO_OS_DEF_AI_NUMERICSERV 0 # endif # if defined(AI_V4MAPPED) # define BOOST_ASIO_OS_DEF_AI_V4MAPPED AI_V4MAPPED # else # define BOOST_ASIO_OS_DEF_AI_V4MAPPED 0 # endif # if defined(AI_ALL) # define BOOST_ASIO_OS_DEF_AI_ALL AI_ALL # else # define BOOST_ASIO_OS_DEF_AI_ALL 0 # endif # if defined(AI_ADDRCONFIG) # define BOOST_ASIO_OS_DEF_AI_ADDRCONFIG AI_ADDRCONFIG # else # define BOOST_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 BOOST_ASIO_OS_DEF_SA_RESTART 0x1 # define BOOST_ASIO_OS_DEF_SA_NOCLDSTOP 0x2 # define BOOST_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(BOOST_ASIO_HAS_SSIZE_T) typedef ssize_t signed_size_type; #else // defined(BOOST_ASIO_HAS_SSIZE_T) typedef int signed_size_type; #endif // defined(BOOST_ASIO_HAS_SSIZE_T) # define BOOST_ASIO_OS_DEF(c) BOOST_ASIO_OS_DEF_##c # define BOOST_ASIO_OS_DEF_AF_UNSPEC AF_UNSPEC # define BOOST_ASIO_OS_DEF_AF_INET AF_INET # define BOOST_ASIO_OS_DEF_AF_INET6 AF_INET6 # define BOOST_ASIO_OS_DEF_SOCK_STREAM SOCK_STREAM # define BOOST_ASIO_OS_DEF_SOCK_DGRAM SOCK_DGRAM # define BOOST_ASIO_OS_DEF_SOCK_RAW SOCK_RAW # define BOOST_ASIO_OS_DEF_SOCK_SEQPACKET SOCK_SEQPACKET # define BOOST_ASIO_OS_DEF_IPPROTO_IP IPPROTO_IP # define BOOST_ASIO_OS_DEF_IPPROTO_IPV6 IPPROTO_IPV6 # define BOOST_ASIO_OS_DEF_IPPROTO_TCP IPPROTO_TCP # define BOOST_ASIO_OS_DEF_IPPROTO_UDP IPPROTO_UDP # define BOOST_ASIO_OS_DEF_IPPROTO_ICMP IPPROTO_ICMP # define BOOST_ASIO_OS_DEF_IPPROTO_ICMPV6 IPPROTO_ICMPV6 # define BOOST_ASIO_OS_DEF_FIONBIO FIONBIO # define BOOST_ASIO_OS_DEF_FIONREAD FIONREAD # define BOOST_ASIO_OS_DEF_INADDR_ANY INADDR_ANY # define BOOST_ASIO_OS_DEF_MSG_OOB MSG_OOB # define BOOST_ASIO_OS_DEF_MSG_PEEK MSG_PEEK # define BOOST_ASIO_OS_DEF_MSG_DONTROUTE MSG_DONTROUTE # define BOOST_ASIO_OS_DEF_MSG_EOR MSG_EOR # define BOOST_ASIO_OS_DEF_SHUT_RD SHUT_RD # define BOOST_ASIO_OS_DEF_SHUT_WR SHUT_WR # define BOOST_ASIO_OS_DEF_SHUT_RDWR SHUT_RDWR # define BOOST_ASIO_OS_DEF_SOMAXCONN SOMAXCONN # define BOOST_ASIO_OS_DEF_SOL_SOCKET SOL_SOCKET # define BOOST_ASIO_OS_DEF_SO_BROADCAST SO_BROADCAST # define BOOST_ASIO_OS_DEF_SO_DEBUG SO_DEBUG # define BOOST_ASIO_OS_DEF_SO_DONTROUTE SO_DONTROUTE # define BOOST_ASIO_OS_DEF_SO_KEEPALIVE SO_KEEPALIVE # define BOOST_ASIO_OS_DEF_SO_LINGER SO_LINGER # define BOOST_ASIO_OS_DEF_SO_OOBINLINE SO_OOBINLINE # define BOOST_ASIO_OS_DEF_SO_SNDBUF SO_SNDBUF # define BOOST_ASIO_OS_DEF_SO_RCVBUF SO_RCVBUF # define BOOST_ASIO_OS_DEF_SO_SNDLOWAT SO_SNDLOWAT # define BOOST_ASIO_OS_DEF_SO_RCVLOWAT SO_RCVLOWAT # define BOOST_ASIO_OS_DEF_SO_REUSEADDR SO_REUSEADDR # define BOOST_ASIO_OS_DEF_TCP_NODELAY TCP_NODELAY # define BOOST_ASIO_OS_DEF_IP_MULTICAST_IF IP_MULTICAST_IF # define BOOST_ASIO_OS_DEF_IP_MULTICAST_TTL IP_MULTICAST_TTL # define BOOST_ASIO_OS_DEF_IP_MULTICAST_LOOP IP_MULTICAST_LOOP # define BOOST_ASIO_OS_DEF_IP_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP # define BOOST_ASIO_OS_DEF_IP_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP # define BOOST_ASIO_OS_DEF_IP_TTL IP_TTL # define BOOST_ASIO_OS_DEF_IPV6_UNICAST_HOPS IPV6_UNICAST_HOPS # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_IF IPV6_MULTICAST_IF # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_HOPS IPV6_MULTICAST_HOPS # define BOOST_ASIO_OS_DEF_IPV6_MULTICAST_LOOP IPV6_MULTICAST_LOOP # define BOOST_ASIO_OS_DEF_IPV6_JOIN_GROUP IPV6_JOIN_GROUP # define BOOST_ASIO_OS_DEF_IPV6_LEAVE_GROUP IPV6_LEAVE_GROUP # define BOOST_ASIO_OS_DEF_AI_CANONNAME AI_CANONNAME # define BOOST_ASIO_OS_DEF_AI_PASSIVE AI_PASSIVE # define BOOST_ASIO_OS_DEF_AI_NUMERICHOST AI_NUMERICHOST # if defined(AI_NUMERICSERV) # define BOOST_ASIO_OS_DEF_AI_NUMERICSERV AI_NUMERICSERV # else # define BOOST_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 BOOST_ASIO_OS_DEF_AI_V4MAPPED AI_V4MAPPED # else # define BOOST_ASIO_OS_DEF_AI_V4MAPPED 0 # endif # if defined(AI_ALL) && !defined(__QNXNTO__) # define BOOST_ASIO_OS_DEF_AI_ALL AI_ALL # else # define BOOST_ASIO_OS_DEF_AI_ALL 0 # endif # if defined(AI_ADDRCONFIG) && !defined(__QNXNTO__) # define BOOST_ASIO_OS_DEF_AI_ADDRCONFIG AI_ADDRCONFIG # else # define BOOST_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 BOOST_ASIO_OS_DEF_SA_RESTART SA_RESTART # define BOOST_ASIO_OS_DEF_SA_NOCLDSTOP SA_NOCLDSTOP # define BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SOCKET_TYPES_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_SELECT_REACTOR_HPP #define BOOST_ASIO_DETAIL_SELECT_REACTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) \ || (!defined(BOOST_ASIO_HAS_DEV_POLL) \ && !defined(BOOST_ASIO_HAS_EPOLL) \ && !defined(BOOST_ASIO_HAS_KQUEUE) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME)) #include <cstddef> #include <boost/asio/detail/fd_set_adapter.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/reactor_op_queue.hpp> #include <boost/asio/detail/scheduler_task.hpp> #include <boost/asio/detail/select_interrupter.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/timer_queue_set.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/execution_context.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/thread.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class select_reactor : public execution_context_service_base<select_reactor> #if !defined(BOOST_ASIO_HAS_IOCP) , public scheduler_task #endif // !defined(BOOST_ASIO_HAS_IOCP) { public: #if defined(BOOST_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(BOOST_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(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) // Per-descriptor data. struct per_descriptor_data { }; // Constructor. BOOST_ASIO_DECL select_reactor(boost::asio::execution_context& ctx); // Destructor. BOOST_ASIO_DECL ~select_reactor(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Recreate internal descriptors following a fork. BOOST_ASIO_DECL void notify_fork( boost::asio::execution_context::fork_event fork_ev); // Initialise the task, but only if the reactor is not in its own thread. BOOST_ASIO_DECL void init_task(); // Register a socket with the reactor. Returns 0 on success, system error // code on failure. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_ASIO_DECL void deregister_internal_descriptor( socket_type descriptor, per_descriptor_data&); // Perform any post-deregistration cleanup tasks associated with the // descriptor data. BOOST_ASIO_DECL void cleanup_descriptor_data(per_descriptor_data&); // Move descriptor registration from one descriptor_data object to another. BOOST_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. BOOST_ASIO_DECL void run(long usec, op_queue<operation>& ops); // Interrupt the select loop. BOOST_ASIO_DECL void interrupt(); private: #if defined(BOOST_ASIO_HAS_IOCP) // Run the select loop in the thread. BOOST_ASIO_DECL void run_thread(); #endif // defined(BOOST_ASIO_HAS_IOCP) // Helper function to add a new timer queue. BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); // Helper function to remove a timer queue. BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); // Get the timeout value for the select call. BOOST_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. BOOST_ASIO_DECL void cancel_ops_unlocked(socket_type descriptor, const boost::system::error_code& ec); // The scheduler implementation used to post completions. # if defined(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context scheduler_type; # else // defined(BOOST_ASIO_HAS_IOCP) typedef class scheduler scheduler_type; # endif // defined(BOOST_ASIO_HAS_IOCP) scheduler_type& scheduler_; // Mutex to protect access to internal data. boost::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(BOOST_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. boost::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) { } BOOST_ASIO_DECL static void do_complete(void* owner, operation* base, const boost::system::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(BOOST_ASIO_HAS_IOCP) // Whether the service has been shut down. bool shutdown_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/select_reactor.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/select_reactor.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IOCP) // || (!defined(BOOST_ASIO_HAS_DEV_POLL) // && !defined(BOOST_ASIO_HAS_EPOLL) // && !defined(BOOST_ASIO_HAS_KQUEUE) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)) #endif // BOOST_ASIO_DETAIL_SELECT_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/service_registry.hpp
// // detail/service_registry.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 BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP #define BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <typeinfo> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { class io_context; namespace detail { template <typename T> class typeid_wrapper {}; class service_registry : private noncopyable { public: // Constructor. BOOST_ASIO_DECL service_registry(execution_context& owner); // Destructor. BOOST_ASIO_DECL ~service_registry(); // Shutdown all services. BOOST_ASIO_DECL void shutdown_services(); // Destroy all services. BOOST_ASIO_DECL void destroy_services(); // Notify all services of a fork event. BOOST_ASIO_DECL void notify_fork(execution_context::fork_event fork_ev); // Get the service object corresponding to the specified service type. Will // create a new service object automatically if no such object already // exists. Ownership of the service object is not transferred to the caller. template <typename Service> Service& use_service(); // Get the service object corresponding to the specified service type. Will // create a new service object automatically if no such object already // exists. Ownership of the service object is not transferred to the caller. // This overload is used for backwards compatibility with services that // inherit from io_context::service. template <typename Service> Service& use_service(io_context& owner); // Add a service object. Throws on error, in which case ownership of the // object is retained by the caller. template <typename Service> void add_service(Service* new_service); // Check whether a service object of the specified type already exists. template <typename Service> bool has_service() const; private: // Initalise a service's key when the key_type typedef is not available. template <typename Service> static void init_key(execution_context::service::key& key, ...); #if !defined(BOOST_ASIO_NO_TYPEID) // Initalise a service's key when the key_type typedef is available. template <typename Service> static void init_key(execution_context::service::key& key, enable_if_t<is_base_of<typename Service::key_type, Service>::value>*); #endif // !defined(BOOST_ASIO_NO_TYPEID) // Initialise a service's key based on its id. BOOST_ASIO_DECL static void init_key_from_id( execution_context::service::key& key, const execution_context::id& id); #if !defined(BOOST_ASIO_NO_TYPEID) // Initialise a service's key based on its id. template <typename Service> static void init_key_from_id(execution_context::service::key& key, const service_id<Service>& /*id*/); #endif // !defined(BOOST_ASIO_NO_TYPEID) // Check if a service matches the given id. BOOST_ASIO_DECL static bool keys_match( const execution_context::service::key& key1, const execution_context::service::key& key2); // The type of a factory function used for creating a service instance. typedef execution_context::service*(*factory_type)(void*); // Factory function for creating a service instance. template <typename Service, typename Owner> static execution_context::service* create(void* owner); // Destroy a service instance. BOOST_ASIO_DECL static void destroy(execution_context::service* service); // Helper class to manage service pointers. struct auto_service_ptr; friend struct auto_service_ptr; struct auto_service_ptr { execution_context::service* ptr_; ~auto_service_ptr() { destroy(ptr_); } }; // Get the service object corresponding to the specified service key. Will // create a new service object automatically if no such object already // exists. Ownership of the service object is not transferred to the caller. BOOST_ASIO_DECL execution_context::service* do_use_service( const execution_context::service::key& key, factory_type factory, void* owner); // Add a service object. Throws on error, in which case ownership of the // object is retained by the caller. BOOST_ASIO_DECL void do_add_service( const execution_context::service::key& key, execution_context::service* new_service); // Check whether a service object with the specified key already exists. BOOST_ASIO_DECL bool do_has_service( const execution_context::service::key& key) const; // Mutex to protect access to internal data. mutable boost::asio::detail::mutex mutex_; // The owner of this service registry and the services it contains. execution_context& owner_; // The first service in the list of contained services. execution_context::service* first_service_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/service_registry.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/service_registry.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_file_service.hpp
// // detail/win_iocp_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 BOOST_ASIO_DETAIL_WIN_IOCP_FILE_SERVICE_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_FILE_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_IOCP) && defined(BOOST_ASIO_HAS_FILE) #include <string> #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/win_iocp_handle_service.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/file_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Extend win_iocp_handle_service to provide file support. class win_iocp_file_service : public execution_context_service_base<win_iocp_file_service> { public: // The native type of a file. typedef win_iocp_handle_service::native_handle_type native_handle_type; // The implementation type of the file. class implementation_type : win_iocp_handle_service::implementation_type { private: // Only this service will have access to the internal values. friend class win_iocp_file_service; uint64_t offset_; bool is_stream_; }; // Constructor. BOOST_ASIO_DECL win_iocp_file_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new file implementation. void construct(implementation_type& impl) { handle_service_.construct(impl); impl.offset_ = 0; impl.is_stream_ = false; } // Move-construct a new file implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) { handle_service_.move_construct(impl, other_impl); impl.offset_ = other_impl.offset_; impl.is_stream_ = other_impl.is_stream_; other_impl.offset_ = 0; } // Move-assign from another file implementation. void move_assign(implementation_type& impl, win_iocp_file_service& other_service, implementation_type& other_impl) { handle_service_.move_assign(impl, other_service.handle_service_, other_impl); impl.offset_ = other_impl.offset_; impl.is_stream_ = other_impl.is_stream_; other_impl.offset_ = 0; } // Destroy a file implementation. void destroy(implementation_type& impl) { handle_service_.destroy(impl); } // Set whether the implementation is stream-oriented. void set_is_stream(implementation_type& impl, bool is_stream) { impl.is_stream_ = is_stream; } // Open the file using the specified path name. BOOST_ASIO_DECL boost::system::error_code open(implementation_type& impl, const char* path, file_base::flags open_flags, boost::system::error_code& ec); // Assign a native handle to a file implementation. boost::system::error_code assign(implementation_type& impl, const native_handle_type& native_handle, boost::system::error_code& ec) { return handle_service_.assign(impl, native_handle, ec); } // Determine whether the file is open. bool is_open(const implementation_type& impl) const { return handle_service_.is_open(impl); } // Destroy a file implementation. boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec) { return handle_service_.close(impl, ec); } // Get the native file representation. native_handle_type native_handle(const implementation_type& impl) const { return handle_service_.native_handle(impl); } // Release ownership of a file. native_handle_type release(implementation_type& impl, boost::system::error_code& ec) { return handle_service_.release(impl, ec); } // Cancel all operations associated with the file. boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec) { return handle_service_.cancel(impl, ec); } // Get the size of the file. BOOST_ASIO_DECL uint64_t size(const implementation_type& impl, boost::system::error_code& ec) const; // Alter the size of the file. BOOST_ASIO_DECL boost::system::error_code resize(implementation_type& impl, uint64_t n, boost::system::error_code& ec); // Synchronise the file to disk. BOOST_ASIO_DECL boost::system::error_code sync_all(implementation_type& impl, boost::system::error_code& ec); // Synchronise the file data to disk. BOOST_ASIO_DECL boost::system::error_code sync_data(implementation_type& impl, boost::system::error_code& ec); // Seek to a position in the file. BOOST_ASIO_DECL uint64_t seek(implementation_type& impl, int64_t offset, file_base::seek_basis whence, boost::system::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, boost::system::error_code& ec) { uint64_t offset = impl.offset_; impl.offset_ += boost::asio::buffer_size(buffers); return handle_service_.write_some_at(impl, offset, 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) { uint64_t offset = impl.offset_; impl.offset_ += boost::asio::buffer_size(buffers); handle_service_.async_write_some_at(impl, offset, 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, boost::system::error_code& ec) { return handle_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) { handle_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, boost::system::error_code& ec) { uint64_t offset = impl.offset_; impl.offset_ += boost::asio::buffer_size(buffers); return handle_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(implementation_type& impl, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { uint64_t offset = impl.offset_; impl.offset_ += boost::asio::buffer_size(buffers); handle_service_.async_read_some_at(impl, offset, 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, boost::system::error_code& ec) { return handle_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) { handle_service_.async_read_some_at(impl, offset, buffers, handler, io_ex); } private: // The implementation used for initiating asynchronous operations. win_iocp_handle_service handle_service_; // Emulation of Windows IO_STATUS_BLOCK structure. struct io_status_block { union u { LONG Status; void* Pointer; }; ULONG_PTR Information; }; // Emulation of flag passed to NtFlushBuffersFileEx. enum { flush_flags_file_data_sync_only = 4 }; // The type of a NtFlushBuffersFileEx function pointer. typedef LONG (NTAPI *nt_flush_buffers_file_ex_fn)( HANDLE, ULONG, void*, ULONG, io_status_block*); // The NTFlushBuffersFileEx function pointer. nt_flush_buffers_file_ex_fn nt_flush_buffers_file_ex_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_iocp_file_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IOCP) && defined(BOOST_ASIO_HAS_FILE) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_FILE_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP #define BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <cstddef> #include <boost/asio/detail/event.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/thread.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/timer_queue_set.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/execution_context.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_io_context.hpp> #else // defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/scheduler.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/thread.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class winrt_timer_scheduler : public execution_context_service_base<winrt_timer_scheduler> { public: // Constructor. BOOST_ASIO_DECL winrt_timer_scheduler(execution_context& context); // Destructor. BOOST_ASIO_DECL ~winrt_timer_scheduler(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Recreate internal descriptors following a fork. BOOST_ASIO_DECL void notify_fork(execution_context::fork_event fork_ev); // Initialise the task. No effect as this class uses its own thread. BOOST_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. BOOST_ASIO_DECL void run_thread(); // Entry point for the select loop thread. BOOST_ASIO_DECL static void call_run_thread(winrt_timer_scheduler* reactor); // Helper function to add a new timer queue. BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); // Helper function to remove a timer queue. BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); // The scheduler implementation used to post completions. #if defined(BOOST_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. boost::asio::detail::mutex mutex_; // Event used to wake up background thread. boost::asio::detail::event event_; // The timer queues. timer_queue_set timer_queues_; // The background thread that is waiting for timers to expire. boost::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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/winrt_timer_scheduler.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/winrt_timer_scheduler.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_TYPE_TRAITS_HPP #define BOOST_ASIO_DETAIL_TYPE_TRAITS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <type_traits> namespace boost { 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(BOOST_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(BOOST_ASIO_HAS_STD_INVOKE_RESULT) using std::result_of; template <typename T> using result_of_t = typename std::result_of<T>::type; #endif // defined(BOOST_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 } // namespace boost #endif // BOOST_ASIO_DETAIL_TYPE_TRAITS_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_CALL_STACK_HPP #define BOOST_ASIO_DETAIL_CALL_STACK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/tss_ptr.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { 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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_CALL_STACK_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/buffer_sequence_adapter.hpp
// // detail/buffer_sequence_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 BOOST_ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP #define BOOST_ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/buffer.hpp> #include <boost/asio/detail/array_fwd.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/registered_buffer.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class buffer_sequence_adapter_base { #if defined(BOOST_ASIO_WINDOWS_RUNTIME) public: // The maximum number of buffers to support in a single operation. enum { max_buffers = 1 }; protected: typedef Windows::Storage::Streams::IBuffer^ native_buffer_type; BOOST_ASIO_DECL static void init_native_buffer( native_buffer_type& buf, const boost::asio::mutable_buffer& buffer); BOOST_ASIO_DECL static void init_native_buffer( native_buffer_type& buf, const boost::asio::const_buffer& buffer); #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) public: // The maximum number of buffers to support in a single operation. enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len }; protected: typedef WSABUF native_buffer_type; static void init_native_buffer(WSABUF& buf, const boost::asio::mutable_buffer& buffer) { buf.buf = static_cast<char*>(buffer.data()); buf.len = static_cast<ULONG>(buffer.size()); } static void init_native_buffer(WSABUF& buf, const boost::asio::const_buffer& buffer) { buf.buf = const_cast<char*>(static_cast<const char*>(buffer.data())); buf.len = static_cast<ULONG>(buffer.size()); } #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) public: // The maximum number of buffers to support in a single operation. enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len }; protected: typedef iovec native_buffer_type; static void init_iov_base(void*& base, void* addr) { base = addr; } template <typename T> static void init_iov_base(T& base, void* addr) { base = static_cast<T>(addr); } static void init_native_buffer(iovec& iov, const boost::asio::mutable_buffer& buffer) { init_iov_base(iov.iov_base, buffer.data()); iov.iov_len = buffer.size(); } static void init_native_buffer(iovec& iov, const boost::asio::const_buffer& buffer) { init_iov_base(iov.iov_base, const_cast<void*>(buffer.data())); iov.iov_len = buffer.size(); } #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) }; // Helper class to translate buffers into the native buffer representation. template <typename Buffer, typename Buffers> class buffer_sequence_adapter : buffer_sequence_adapter_base { public: enum { is_single_buffer = false }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter(const Buffers& buffer_sequence) : count_(0), total_buffer_size_(0) { buffer_sequence_adapter::init( boost::asio::buffer_sequence_begin(buffer_sequence), boost::asio::buffer_sequence_end(buffer_sequence)); } native_buffer_type* buffers() { return buffers_; } std::size_t count() const { return count_; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const Buffers& buffer_sequence) { return buffer_sequence_adapter::all_empty( boost::asio::buffer_sequence_begin(buffer_sequence), boost::asio::buffer_sequence_end(buffer_sequence)); } static void validate(const Buffers& buffer_sequence) { buffer_sequence_adapter::validate( boost::asio::buffer_sequence_begin(buffer_sequence), boost::asio::buffer_sequence_end(buffer_sequence)); } static Buffer first(const Buffers& buffer_sequence) { return buffer_sequence_adapter::first( boost::asio::buffer_sequence_begin(buffer_sequence), boost::asio::buffer_sequence_end(buffer_sequence)); } enum { linearisation_storage_size = 8192 }; static Buffer linearise(const Buffers& buffer_sequence, const boost::asio::mutable_buffer& storage) { return buffer_sequence_adapter::linearise( boost::asio::buffer_sequence_begin(buffer_sequence), boost::asio::buffer_sequence_end(buffer_sequence), storage); } private: template <typename Iterator> void init(Iterator begin, Iterator end) { Iterator iter = begin; for (; iter != end && count_ < max_buffers; ++iter, ++count_) { Buffer buffer(*iter); init_native_buffer(buffers_[count_], buffer); total_buffer_size_ += buffer.size(); } } template <typename Iterator> static bool all_empty(Iterator begin, Iterator end) { Iterator iter = begin; std::size_t i = 0; for (; iter != end && i < max_buffers; ++iter, ++i) if (Buffer(*iter).size() > 0) return false; return true; } template <typename Iterator> static void validate(Iterator begin, Iterator end) { Iterator iter = begin; for (; iter != end; ++iter) { Buffer buffer(*iter); buffer.data(); } } template <typename Iterator> static Buffer first(Iterator begin, Iterator end) { Iterator iter = begin; for (; iter != end; ++iter) { Buffer buffer(*iter); if (buffer.size() != 0) return buffer; } return Buffer(); } template <typename Iterator> static Buffer linearise(Iterator begin, Iterator end, const boost::asio::mutable_buffer& storage) { boost::asio::mutable_buffer unused_storage = storage; Iterator iter = begin; while (iter != end && unused_storage.size() != 0) { Buffer buffer(*iter); ++iter; if (buffer.size() == 0) continue; if (unused_storage.size() == storage.size()) { if (iter == end) return buffer; if (buffer.size() >= unused_storage.size()) return buffer; } unused_storage += boost::asio::buffer_copy(unused_storage, buffer); } return Buffer(storage.data(), storage.size() - unused_storage.size()); } native_buffer_type buffers_[max_buffers]; std::size_t count_; std::size_t total_buffer_size_; }; template <typename Buffer> class buffer_sequence_adapter<Buffer, boost::asio::mutable_buffer> : buffer_sequence_adapter_base { public: enum { is_single_buffer = true }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter( const boost::asio::mutable_buffer& buffer_sequence) { init_native_buffer(buffer_, Buffer(buffer_sequence)); total_buffer_size_ = buffer_sequence.size(); } native_buffer_type* buffers() { return &buffer_; } std::size_t count() const { return 1; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const boost::asio::mutable_buffer& buffer_sequence) { return buffer_sequence.size() == 0; } static void validate(const boost::asio::mutable_buffer& buffer_sequence) { buffer_sequence.data(); } static Buffer first(const boost::asio::mutable_buffer& buffer_sequence) { return Buffer(buffer_sequence); } enum { linearisation_storage_size = 1 }; static Buffer linearise(const boost::asio::mutable_buffer& buffer_sequence, const Buffer&) { return Buffer(buffer_sequence); } private: native_buffer_type buffer_; std::size_t total_buffer_size_; }; template <typename Buffer> class buffer_sequence_adapter<Buffer, boost::asio::const_buffer> : buffer_sequence_adapter_base { public: enum { is_single_buffer = true }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter( const boost::asio::const_buffer& buffer_sequence) { init_native_buffer(buffer_, Buffer(buffer_sequence)); total_buffer_size_ = buffer_sequence.size(); } native_buffer_type* buffers() { return &buffer_; } std::size_t count() const { return 1; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const boost::asio::const_buffer& buffer_sequence) { return buffer_sequence.size() == 0; } static void validate(const boost::asio::const_buffer& buffer_sequence) { buffer_sequence.data(); } static Buffer first(const boost::asio::const_buffer& buffer_sequence) { return Buffer(buffer_sequence); } enum { linearisation_storage_size = 1 }; static Buffer linearise(const boost::asio::const_buffer& buffer_sequence, const Buffer&) { return Buffer(buffer_sequence); } private: native_buffer_type buffer_; std::size_t total_buffer_size_; }; #if !defined(BOOST_ASIO_NO_DEPRECATED) template <typename Buffer> class buffer_sequence_adapter<Buffer, boost::asio::mutable_buffers_1> : buffer_sequence_adapter_base { public: enum { is_single_buffer = true }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter( const boost::asio::mutable_buffers_1& buffer_sequence) { init_native_buffer(buffer_, Buffer(buffer_sequence)); total_buffer_size_ = buffer_sequence.size(); } native_buffer_type* buffers() { return &buffer_; } std::size_t count() const { return 1; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const boost::asio::mutable_buffers_1& buffer_sequence) { return buffer_sequence.size() == 0; } static void validate(const boost::asio::mutable_buffers_1& buffer_sequence) { buffer_sequence.data(); } static Buffer first(const boost::asio::mutable_buffers_1& buffer_sequence) { return Buffer(buffer_sequence); } enum { linearisation_storage_size = 1 }; static Buffer linearise(const boost::asio::mutable_buffers_1& buffer_sequence, const Buffer&) { return Buffer(buffer_sequence); } private: native_buffer_type buffer_; std::size_t total_buffer_size_; }; template <typename Buffer> class buffer_sequence_adapter<Buffer, boost::asio::const_buffers_1> : buffer_sequence_adapter_base { public: enum { is_single_buffer = true }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter( const boost::asio::const_buffers_1& buffer_sequence) { init_native_buffer(buffer_, Buffer(buffer_sequence)); total_buffer_size_ = buffer_sequence.size(); } native_buffer_type* buffers() { return &buffer_; } std::size_t count() const { return 1; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const boost::asio::const_buffers_1& buffer_sequence) { return buffer_sequence.size() == 0; } static void validate(const boost::asio::const_buffers_1& buffer_sequence) { buffer_sequence.data(); } static Buffer first(const boost::asio::const_buffers_1& buffer_sequence) { return Buffer(buffer_sequence); } enum { linearisation_storage_size = 1 }; static Buffer linearise(const boost::asio::const_buffers_1& buffer_sequence, const Buffer&) { return Buffer(buffer_sequence); } private: native_buffer_type buffer_; std::size_t total_buffer_size_; }; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) template <typename Buffer> class buffer_sequence_adapter<Buffer, boost::asio::mutable_registered_buffer> : buffer_sequence_adapter_base { public: enum { is_single_buffer = true }; enum { is_registered_buffer = true }; explicit buffer_sequence_adapter( const boost::asio::mutable_registered_buffer& buffer_sequence) { init_native_buffer(buffer_, buffer_sequence.buffer()); total_buffer_size_ = buffer_sequence.size(); registered_id_ = buffer_sequence.id(); } native_buffer_type* buffers() { return &buffer_; } std::size_t count() const { return 1; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_id_; } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty( const boost::asio::mutable_registered_buffer& buffer_sequence) { return buffer_sequence.size() == 0; } static void validate( const boost::asio::mutable_registered_buffer& buffer_sequence) { buffer_sequence.data(); } static Buffer first( const boost::asio::mutable_registered_buffer& buffer_sequence) { return Buffer(buffer_sequence.buffer()); } enum { linearisation_storage_size = 1 }; static Buffer linearise( const boost::asio::mutable_registered_buffer& buffer_sequence, const Buffer&) { return Buffer(buffer_sequence.buffer()); } private: native_buffer_type buffer_; std::size_t total_buffer_size_; registered_buffer_id registered_id_; }; template <typename Buffer> class buffer_sequence_adapter<Buffer, boost::asio::const_registered_buffer> : buffer_sequence_adapter_base { public: enum { is_single_buffer = true }; enum { is_registered_buffer = true }; explicit buffer_sequence_adapter( const boost::asio::const_registered_buffer& buffer_sequence) { init_native_buffer(buffer_, buffer_sequence.buffer()); total_buffer_size_ = buffer_sequence.size(); registered_id_ = buffer_sequence.id(); } native_buffer_type* buffers() { return &buffer_; } std::size_t count() const { return 1; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_id_; } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty( const boost::asio::const_registered_buffer& buffer_sequence) { return buffer_sequence.size() == 0; } static void validate( const boost::asio::const_registered_buffer& buffer_sequence) { buffer_sequence.data(); } static Buffer first( const boost::asio::const_registered_buffer& buffer_sequence) { return Buffer(buffer_sequence.buffer()); } enum { linearisation_storage_size = 1 }; static Buffer linearise( const boost::asio::const_registered_buffer& buffer_sequence, const Buffer&) { return Buffer(buffer_sequence.buffer()); } private: native_buffer_type buffer_; std::size_t total_buffer_size_; registered_buffer_id registered_id_; }; template <typename Buffer, typename Elem> class buffer_sequence_adapter<Buffer, boost::array<Elem, 2>> : buffer_sequence_adapter_base { public: enum { is_single_buffer = false }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter( const boost::array<Elem, 2>& buffer_sequence) { init_native_buffer(buffers_[0], Buffer(buffer_sequence[0])); init_native_buffer(buffers_[1], Buffer(buffer_sequence[1])); total_buffer_size_ = buffer_sequence[0].size() + buffer_sequence[1].size(); } native_buffer_type* buffers() { return buffers_; } std::size_t count() const { return 2; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const boost::array<Elem, 2>& buffer_sequence) { return buffer_sequence[0].size() == 0 && buffer_sequence[1].size() == 0; } static void validate(const boost::array<Elem, 2>& buffer_sequence) { buffer_sequence[0].data(); buffer_sequence[1].data(); } static Buffer first(const boost::array<Elem, 2>& buffer_sequence) { return Buffer(buffer_sequence[0].size() != 0 ? buffer_sequence[0] : buffer_sequence[1]); } enum { linearisation_storage_size = 8192 }; static Buffer linearise(const boost::array<Elem, 2>& buffer_sequence, const boost::asio::mutable_buffer& storage) { if (buffer_sequence[0].size() == 0) return Buffer(buffer_sequence[1]); if (buffer_sequence[1].size() == 0) return Buffer(buffer_sequence[0]); return Buffer(storage.data(), boost::asio::buffer_copy(storage, buffer_sequence)); } private: native_buffer_type buffers_[2]; std::size_t total_buffer_size_; }; template <typename Buffer, typename Elem> class buffer_sequence_adapter<Buffer, std::array<Elem, 2>> : buffer_sequence_adapter_base { public: enum { is_single_buffer = false }; enum { is_registered_buffer = false }; explicit buffer_sequence_adapter( const std::array<Elem, 2>& buffer_sequence) { init_native_buffer(buffers_[0], Buffer(buffer_sequence[0])); init_native_buffer(buffers_[1], Buffer(buffer_sequence[1])); total_buffer_size_ = buffer_sequence[0].size() + buffer_sequence[1].size(); } native_buffer_type* buffers() { return buffers_; } std::size_t count() const { return 2; } std::size_t total_size() const { return total_buffer_size_; } registered_buffer_id registered_id() const { return registered_buffer_id(); } bool all_empty() const { return total_buffer_size_ == 0; } static bool all_empty(const std::array<Elem, 2>& buffer_sequence) { return buffer_sequence[0].size() == 0 && buffer_sequence[1].size() == 0; } static void validate(const std::array<Elem, 2>& buffer_sequence) { buffer_sequence[0].data(); buffer_sequence[1].data(); } static Buffer first(const std::array<Elem, 2>& buffer_sequence) { return Buffer(buffer_sequence[0].size() != 0 ? buffer_sequence[0] : buffer_sequence[1]); } enum { linearisation_storage_size = 8192 }; static Buffer linearise(const std::array<Elem, 2>& buffer_sequence, const boost::asio::mutable_buffer& storage) { if (buffer_sequence[0].size() == 0) return Buffer(buffer_sequence[1]); if (buffer_sequence[1].size() == 0) return Buffer(buffer_sequence[0]); return Buffer(storage.data(), boost::asio::buffer_copy(storage, buffer_sequence)); } private: native_buffer_type buffers_[2]; std::size_t total_buffer_size_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/buffer_sequence_adapter.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/limits.hpp
// // detail/limits.hpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2011 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 BOOST_ASIO_DETAIL_LIMITS_HPP #define BOOST_ASIO_DETAIL_LIMITS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <limits> #endif // BOOST_ASIO_DETAIL_LIMITS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/wrapped_handler.hpp
// // detail/wrapped_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 BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP #define BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/handler_cont_helpers.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct is_continuation_delegated { template <typename Dispatcher, typename Handler> bool operator()(Dispatcher&, Handler& handler) const { return boost_asio_handler_cont_helpers::is_continuation(handler); } }; struct is_continuation_if_running { template <typename Dispatcher, typename Handler> bool operator()(Dispatcher& dispatcher, Handler&) const { return dispatcher.running_in_this_thread(); } }; template <typename Dispatcher, typename Handler, typename IsContinuation = is_continuation_delegated> class wrapped_handler { public: typedef void result_type; wrapped_handler(Dispatcher dispatcher, Handler& handler) : dispatcher_(dispatcher), handler_(static_cast<Handler&&>(handler)) { } wrapped_handler(const wrapped_handler& other) : dispatcher_(other.dispatcher_), handler_(other.handler_) { } wrapped_handler(wrapped_handler&& other) : dispatcher_(other.dispatcher_), handler_(static_cast<Handler&&>(other.handler_)) { } void operator()() { dispatcher_.dispatch(static_cast<Handler&&>(handler_)); } void operator()() const { dispatcher_.dispatch(handler_); } template <typename Arg1> void operator()(const Arg1& arg1) { dispatcher_.dispatch(detail::bind_handler(handler_, arg1)); } template <typename Arg1> void operator()(const Arg1& arg1) const { dispatcher_.dispatch(detail::bind_handler(handler_, arg1)); } template <typename Arg1, typename Arg2> void operator()(const Arg1& arg1, const Arg2& arg2) { dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2)); } template <typename Arg1, typename Arg2> void operator()(const Arg1& arg1, const Arg2& arg2) const { dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2)); } template <typename Arg1, typename Arg2, typename Arg3> void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) { dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3)); } template <typename Arg1, typename Arg2, typename Arg3> void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const { dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3)); } template <typename Arg1, typename Arg2, typename Arg3, typename Arg4> void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) { dispatcher_.dispatch( detail::bind_handler(handler_, arg1, arg2, arg3, arg4)); } template <typename Arg1, typename Arg2, typename Arg3, typename Arg4> void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) const { dispatcher_.dispatch( detail::bind_handler(handler_, arg1, arg2, arg3, arg4)); } template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) { dispatcher_.dispatch( detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5)); } template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) const { dispatcher_.dispatch( detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5)); } //private: Dispatcher dispatcher_; Handler handler_; }; template <typename Handler, typename Context> class rewrapped_handler { public: explicit rewrapped_handler(Handler& handler, const Context& context) : context_(context), handler_(static_cast<Handler&&>(handler)) { } explicit rewrapped_handler(const Handler& handler, const Context& context) : context_(context), handler_(handler) { } rewrapped_handler(const rewrapped_handler& other) : context_(other.context_), handler_(other.handler_) { } rewrapped_handler(rewrapped_handler&& other) : context_(static_cast<Context&&>(other.context_)), handler_(static_cast<Handler&&>(other.handler_)) { } void operator()() { handler_(); } void operator()() const { handler_(); } //private: Context context_; Handler handler_; }; template <typename Dispatcher, typename Handler, typename IsContinuation> inline bool asio_handler_is_continuation( wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler) { return IsContinuation()(this_handler->dispatcher_, this_handler->handler_); } template <typename Dispatcher, typename Context> inline bool asio_handler_is_continuation( rewrapped_handler<Dispatcher, Context>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->context_); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/kqueue_reactor.hpp
// // detail/kqueue_reactor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2005 Stefan Arentz (stefan at soze 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 BOOST_ASIO_DETAIL_KQUEUE_REACTOR_HPP #define BOOST_ASIO_DETAIL_KQUEUE_REACTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_KQUEUE) #include <cstddef> #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> #include <boost/asio/detail/conditionally_enabled_mutex.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/detail/object_pool.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/scheduler_task.hpp> #include <boost/asio/detail/select_interrupter.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/timer_queue_set.hpp> #include <boost/asio/detail/wait_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> // Older versions of Mac OS X may not define EV_OOBAND. #if !defined(EV_OOBAND) # define EV_OOBAND EV_FLAG1 #endif // !defined(EV_OOBAND) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class scheduler; class kqueue_reactor : public execution_context_service_base<kqueue_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. struct descriptor_state { descriptor_state(bool locking) : mutex_(locking) {} friend class kqueue_reactor; friend class object_pool_access; descriptor_state* next_; descriptor_state* prev_; mutex mutex_; int descriptor_; int num_kevents_; // 1 == read only, 2 == read and write op_queue<reactor_op> op_queue_[max_ops]; bool shutdown_; }; // Per-descriptor data. typedef descriptor_state* per_descriptor_data; // Constructor. BOOST_ASIO_DECL kqueue_reactor(boost::asio::execution_context& ctx); // Destructor. BOOST_ASIO_DECL ~kqueue_reactor(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Recreate internal descriptors following a fork. BOOST_ASIO_DECL void notify_fork( boost::asio::execution_context::fork_event fork_ev); // Initialise the task. BOOST_ASIO_DECL void init_task(); // Register a socket with the reactor. Returns 0 on success, system error // code on failure. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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, &kqueue_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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. BOOST_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>& 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 the kqueue loop. BOOST_ASIO_DECL void run(long usec, op_queue<operation>& ops); // Interrupt the kqueue loop. BOOST_ASIO_DECL void interrupt(); private: // Create the kqueue file descriptor. Throws an exception if the descriptor // cannot be created. BOOST_ASIO_DECL static int do_kqueue_create(); // Allocate a new descriptor state object. BOOST_ASIO_DECL descriptor_state* allocate_descriptor_state(); // Free an existing descriptor state object. BOOST_ASIO_DECL void free_descriptor_state(descriptor_state* s); // Helper function to add a new timer queue. BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); // Helper function to remove a timer queue. BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); // Get the timeout value for the kevent call. BOOST_ASIO_DECL timespec* get_timeout(long usec, timespec& ts); // The scheduler used to post completions. scheduler& scheduler_; // Mutex to protect access to internal data. mutex mutex_; // The kqueue file descriptor. int kqueue_fd_; // The interrupter is used to break a blocking kevent call. select_interrupter interrupter_; // 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_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/kqueue_reactor.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/kqueue_reactor.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_KQUEUE) #endif // BOOST_ASIO_DETAIL_KQUEUE_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_mutex.hpp
// // detail/posix_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 BOOST_ASIO_DETAIL_POSIX_MUTEX_HPP #define BOOST_ASIO_DETAIL_POSIX_MUTEX_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_HAS_PTHREADS) #include <pthread.h> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class posix_event; class posix_mutex : private noncopyable { public: typedef boost::asio::detail::scoped_lock<posix_mutex> scoped_lock; // Constructor. BOOST_ASIO_DECL posix_mutex(); // Destructor. ~posix_mutex() { ::pthread_mutex_destroy(&mutex_); // Ignore EBUSY. } // Lock the mutex. void lock() { (void)::pthread_mutex_lock(&mutex_); // Ignore EINVAL. } // Unlock the mutex. void unlock() { (void)::pthread_mutex_unlock(&mutex_); // Ignore EINVAL. } private: friend class posix_event; ::pthread_mutex_t mutex_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/posix_mutex.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/signal_blocker.hpp
// // detail/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 BOOST_ASIO_DETAIL_SIGNAL_BLOCKER_HPP #define BOOST_ASIO_DETAIL_SIGNAL_BLOCKER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) || defined(BOOST_ASIO_WINDOWS) \ || defined(BOOST_ASIO_WINDOWS_RUNTIME) \ || defined(__CYGWIN__) || defined(__SYMBIAN32__) # include <boost/asio/detail/null_signal_blocker.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_signal_blocker.hpp> #else # error Only Windows and POSIX are supported! #endif namespace boost { namespace asio { namespace detail { #if !defined(BOOST_ASIO_HAS_THREADS) || defined(BOOST_ASIO_WINDOWS) \ || defined(BOOST_ASIO_WINDOWS_RUNTIME) \ || defined(__CYGWIN__) || defined(__SYMBIAN32__) typedef null_signal_blocker signal_blocker; #elif defined(BOOST_ASIO_HAS_PTHREADS) typedef posix_signal_blocker signal_blocker; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_SIGNAL_BLOCKER_HPP
hpp
asio
data/projects/asio/include/boost/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 BOOST_ASIO_DETAIL_SIGNAL_SET_SERVICE_HPP #define BOOST_ASIO_DETAIL_SIGNAL_SET_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <cstddef> #include <signal.h> #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/cancellation_type.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/signal_set_base.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/signal_handler.hpp> #include <boost/asio/detail/signal_op.hpp> #include <boost/asio/detail/socket_types.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_io_context.hpp> #else // defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/scheduler.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) # if defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # include <boost/asio/detail/io_uring_service.hpp> # else // defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # include <boost/asio/detail/reactor.hpp> # endif // defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { #if defined(NSIG) && (NSIG > 0) enum { max_signal_number = NSIG }; #else enum { max_signal_number = 128 }; #endif extern BOOST_ASIO_DECL struct signal_state* get_signal_state(); extern "C" BOOST_ASIO_DECL void boost_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. BOOST_ASIO_DECL signal_set_service(execution_context& context); // Destructor. BOOST_ASIO_DECL ~signal_set_service(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Perform fork-related housekeeping. BOOST_ASIO_DECL void notify_fork( boost::asio::execution_context::fork_event fork_ev); // Construct a new signal_set implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Destroy a signal_set implementation. BOOST_ASIO_DECL void destroy(implementation_type& impl); // Add a signal to a signal_set. boost::system::error_code add(implementation_type& impl, int signal_number, boost::system::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. BOOST_ASIO_DECL boost::system::error_code add(implementation_type& impl, int signal_number, signal_set_base::flags_t f, boost::system::error_code& ec); // Remove a signal to a signal_set. BOOST_ASIO_DECL boost::system::error_code remove(implementation_type& impl, int signal_number, boost::system::error_code& ec); // Remove all signals from a signal_set. BOOST_ASIO_DECL boost::system::error_code clear(implementation_type& impl, boost::system::error_code& ec); // Cancel all operations associated with the signal set. BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec); // Cancel a specific operation associated with the signal set. BOOST_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 = boost::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 = { boost::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); } BOOST_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. BOOST_ASIO_DECL static void deliver_signal(int signal_number); private: // Helper function to add a service to the global signal state. BOOST_ASIO_DECL static void add_service(signal_set_service* service); // Helper function to remove a service from the global signal state. BOOST_ASIO_DECL static void remove_service(signal_set_service* service); // Helper function to create the pipe descriptors. BOOST_ASIO_DECL static void open_descriptors(); // Helper function to close the pipe descriptors. BOOST_ASIO_DECL static void close_descriptors(); // Helper function to start a wait operation. BOOST_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(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context scheduler_impl; #else typedef class scheduler scheduler_impl; #endif scheduler_impl& scheduler_; #if !defined(BOOST_ASIO_WINDOWS) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \ && !defined(__CYGWIN__) // The type used for processing pipe readiness notifications. class pipe_read_op; # if defined(BOOST_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(BOOST_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(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_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 } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/signal_set_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_SIGNAL_SET_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/event.hpp
// // detail/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 BOOST_ASIO_DETAIL_EVENT_HPP #define BOOST_ASIO_DETAIL_EVENT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if !defined(BOOST_ASIO_HAS_THREADS) # include <boost/asio/detail/null_event.hpp> #elif defined(BOOST_ASIO_WINDOWS) # include <boost/asio/detail/win_event.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_event.hpp> #else # include <boost/asio/detail/std_event.hpp> #endif namespace boost { namespace asio { namespace detail { #if !defined(BOOST_ASIO_HAS_THREADS) typedef null_event event; #elif defined(BOOST_ASIO_WINDOWS) typedef win_event event; #elif defined(BOOST_ASIO_HAS_PTHREADS) typedef posix_event event; #else typedef std_event event; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_EVENT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/blocking_executor_op.hpp
// // detail/blocking_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 BOOST_ASIO_DETAIL_BLOCKING_EXECUTOR_OP_HPP #define BOOST_ASIO_DETAIL_BLOCKING_EXECUTOR_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/event.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/scheduler_operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Operation = scheduler_operation> class blocking_executor_op_base : public Operation { public: blocking_executor_op_base(typename Operation::func_type complete_func) : Operation(complete_func), is_complete_(false) { } void wait() { boost::asio::detail::mutex::scoped_lock lock(mutex_); while (!is_complete_) event_.wait(lock); } protected: struct do_complete_cleanup { ~do_complete_cleanup() { boost::asio::detail::mutex::scoped_lock lock(op_->mutex_); op_->is_complete_ = true; op_->event_.unlock_and_signal_one_for_destruction(lock); } blocking_executor_op_base* op_; }; private: boost::asio::detail::mutex mutex_; boost::asio::detail::event event_; bool is_complete_; }; template <typename Handler, typename Operation = scheduler_operation> class blocking_executor_op : public blocking_executor_op_base<Operation> { public: blocking_executor_op(Handler& h) : blocking_executor_op_base<Operation>(&blocking_executor_op::do_complete), handler_(h) { } static void do_complete(void* owner, Operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { BOOST_ASIO_ASSUME(base != 0); blocking_executor_op* o(static_cast<blocking_executor_op*>(base)); typename blocking_executor_op_base<Operation>::do_complete_cleanup on_exit = { o }; (void)on_exit; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN(()); static_cast<Handler&&>(o->handler_)(); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler& handler_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_BLOCKING_EXECUTOR_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_async_manager.hpp
// // detail/winrt_async_manager.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 BOOST_ASIO_DETAIL_WINRT_ASYNC_MANAGER_HPP #define BOOST_ASIO_DETAIL_WINRT_ASYNC_MANAGER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <future> #include <boost/asio/detail/atomic_count.hpp> #include <boost/asio/detail/winrt_async_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #if defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/win_iocp_io_context.hpp> #else // defined(BOOST_ASIO_HAS_IOCP) # include <boost/asio/detail/scheduler.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class winrt_async_manager : public execution_context_service_base<winrt_async_manager> { public: // Constructor. winrt_async_manager(execution_context& context) : execution_context_service_base<winrt_async_manager>(context), scheduler_(use_service<scheduler_impl>(context)), outstanding_ops_(1) { } // Destructor. ~winrt_async_manager() { } // Destroy all user-defined handler objects owned by the service. void shutdown() { if (--outstanding_ops_ > 0) { // Block until last operation is complete. std::future<void> f = promise_.get_future(); f.wait(); } } void sync(Windows::Foundation::IAsyncAction^ action, boost::system::error_code& ec) { using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; auto promise = std::make_shared<std::promise<boost::system::error_code>>(); auto future = promise->get_future(); action->Completed = ref new AsyncActionCompletedHandler( [promise](IAsyncAction^ action, AsyncStatus status) { switch (status) { case AsyncStatus::Canceled: promise->set_value(boost::asio::error::operation_aborted); break; case AsyncStatus::Error: case AsyncStatus::Completed: default: boost::system::error_code ec( action->ErrorCode.Value, boost::system::system_category()); promise->set_value(ec); break; } }); ec = future.get(); } template <typename TResult> TResult sync(Windows::Foundation::IAsyncOperation<TResult>^ operation, boost::system::error_code& ec) { using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; auto promise = std::make_shared<std::promise<boost::system::error_code>>(); auto future = promise->get_future(); operation->Completed = ref new AsyncOperationCompletedHandler<TResult>( [promise](IAsyncOperation<TResult>^ operation, AsyncStatus status) { switch (status) { case AsyncStatus::Canceled: promise->set_value(boost::asio::error::operation_aborted); break; case AsyncStatus::Error: case AsyncStatus::Completed: default: boost::system::error_code ec( operation->ErrorCode.Value, boost::system::system_category()); promise->set_value(ec); break; } }); ec = future.get(); return operation->GetResults(); } template <typename TResult, typename TProgress> TResult sync( Windows::Foundation::IAsyncOperationWithProgress< TResult, TProgress>^ operation, boost::system::error_code& ec) { using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; auto promise = std::make_shared<std::promise<boost::system::error_code>>(); auto future = promise->get_future(); operation->Completed = ref new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>( [promise](IAsyncOperationWithProgress<TResult, TProgress>^ operation, AsyncStatus status) { switch (status) { case AsyncStatus::Canceled: promise->set_value(boost::asio::error::operation_aborted); break; case AsyncStatus::Started: break; case AsyncStatus::Error: case AsyncStatus::Completed: default: boost::system::error_code ec( operation->ErrorCode.Value, boost::system::system_category()); promise->set_value(ec); break; } }); ec = future.get(); return operation->GetResults(); } void async(Windows::Foundation::IAsyncAction^ action, winrt_async_op<void>* handler) { using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; auto on_completed = ref new AsyncActionCompletedHandler( [this, handler](IAsyncAction^ action, AsyncStatus status) { switch (status) { case AsyncStatus::Canceled: handler->ec_ = boost::asio::error::operation_aborted; break; case AsyncStatus::Started: return; case AsyncStatus::Completed: case AsyncStatus::Error: default: handler->ec_ = boost::system::error_code( action->ErrorCode.Value, boost::system::system_category()); break; } scheduler_.post_deferred_completion(handler); if (--outstanding_ops_ == 0) promise_.set_value(); }); scheduler_.work_started(); ++outstanding_ops_; action->Completed = on_completed; } template <typename TResult> void async(Windows::Foundation::IAsyncOperation<TResult>^ operation, winrt_async_op<TResult>* handler) { using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; auto on_completed = ref new AsyncOperationCompletedHandler<TResult>( [this, handler](IAsyncOperation<TResult>^ operation, AsyncStatus status) { switch (status) { case AsyncStatus::Canceled: handler->ec_ = boost::asio::error::operation_aborted; break; case AsyncStatus::Started: return; case AsyncStatus::Completed: handler->result_ = operation->GetResults(); // Fall through. case AsyncStatus::Error: default: handler->ec_ = boost::system::error_code( operation->ErrorCode.Value, boost::system::system_category()); break; } scheduler_.post_deferred_completion(handler); if (--outstanding_ops_ == 0) promise_.set_value(); }); scheduler_.work_started(); ++outstanding_ops_; operation->Completed = on_completed; } template <typename TResult, typename TProgress> void async( Windows::Foundation::IAsyncOperationWithProgress< TResult, TProgress>^ operation, winrt_async_op<TResult>* handler) { using namespace Windows::Foundation; using Windows::Foundation::AsyncStatus; auto on_completed = ref new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>( [this, handler](IAsyncOperationWithProgress< TResult, TProgress>^ operation, AsyncStatus status) { switch (status) { case AsyncStatus::Canceled: handler->ec_ = boost::asio::error::operation_aborted; break; case AsyncStatus::Started: return; case AsyncStatus::Completed: handler->result_ = operation->GetResults(); // Fall through. case AsyncStatus::Error: default: handler->ec_ = boost::system::error_code( operation->ErrorCode.Value, boost::system::system_category()); break; } scheduler_.post_deferred_completion(handler); if (--outstanding_ops_ == 0) promise_.set_value(); }); scheduler_.work_started(); ++outstanding_ops_; operation->Completed = on_completed; } private: // The scheduler implementation used to post completed handlers. #if defined(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context scheduler_impl; #else typedef class scheduler scheduler_impl; #endif scheduler_impl& scheduler_; // Count of outstanding operations. atomic_count outstanding_ops_; // Used to keep wait for outstanding operations to complete. std::promise<void> promise_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_ASYNC_MANAGER_HPP
hpp