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/throw_exception.hpp
// // detail/throw_exception.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_EXCEPTION_HPP #define BOOST_ASIO_DETAIL_THROW_EXCEPTION_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_THROW_EXCEPTION) # include <boost/throw_exception.hpp> #endif // defined(BOOST_ASIO_BOOST_THROW_EXCEPTION) namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_HAS_BOOST_THROW_EXCEPTION) using boost::throw_exception; #else // defined(BOOST_ASIO_HAS_BOOST_THROW_EXCEPTION) // Declare the throw_exception function for all targets. template <typename Exception> void throw_exception( const Exception& e BOOST_ASIO_SOURCE_LOCATION_DEFAULTED_PARAM); // Only define the throw_exception function when exceptions are enabled. // Otherwise, it is up to the application to provide a definition of this // function. # if !defined(BOOST_ASIO_NO_EXCEPTIONS) template <typename Exception> void throw_exception( const Exception& e BOOST_ASIO_SOURCE_LOCATION_PARAM) { throw e; } # endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) #endif // defined(BOOST_ASIO_HAS_BOOST_THROW_EXCEPTION) } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_THROW_EXCEPTION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/consuming_buffers.hpp
// // detail/consuming_buffers.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_CONSUMING_BUFFERS_HPP #define BOOST_ASIO_DETAIL_CONSUMING_BUFFERS_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/buffer.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/limits.hpp> #include <boost/asio/registered_buffer.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Helper template to determine the maximum number of prepared buffers. template <typename Buffers> struct prepared_buffers_max { enum { value = buffer_sequence_adapter_base::max_buffers }; }; template <typename Elem, std::size_t N> struct prepared_buffers_max<boost::array<Elem, N>> { enum { value = N }; }; template <typename Elem, std::size_t N> struct prepared_buffers_max<std::array<Elem, N>> { enum { value = N }; }; // A buffer sequence used to represent a subsequence of the buffers. template <typename Buffer, std::size_t MaxBuffers> struct prepared_buffers { typedef Buffer value_type; typedef const Buffer* const_iterator; enum { max_buffers = MaxBuffers < 16 ? MaxBuffers : 16 }; prepared_buffers() : count(0) {} const_iterator begin() const { return elems; } const_iterator end() const { return elems + count; } Buffer elems[max_buffers]; std::size_t count; }; // A proxy for a sub-range in a list of buffers. template <typename Buffer, typename Buffers, typename Buffer_Iterator> class consuming_buffers { public: typedef prepared_buffers<Buffer, prepared_buffers_max<Buffers>::value> prepared_buffers_type; // Construct to represent the entire list of buffers. explicit consuming_buffers(const Buffers& buffers) : buffers_(buffers), total_consumed_(0), next_elem_(0), next_elem_offset_(0) { using boost::asio::buffer_size; total_size_ = buffer_size(buffers); } // Determine if we are at the end of the buffers. bool empty() const { return total_consumed_ >= total_size_; } // Get the buffer for a single transfer, with a size. prepared_buffers_type prepare(std::size_t max_size) { prepared_buffers_type result; Buffer_Iterator next = boost::asio::buffer_sequence_begin(buffers_); Buffer_Iterator end = boost::asio::buffer_sequence_end(buffers_); std::advance(next, next_elem_); std::size_t elem_offset = next_elem_offset_; while (next != end && max_size > 0 && (result.count) < result.max_buffers) { Buffer next_buf = Buffer(*next) + elem_offset; result.elems[result.count] = boost::asio::buffer(next_buf, max_size); max_size -= result.elems[result.count].size(); elem_offset = 0; if (result.elems[result.count].size() > 0) ++result.count; ++next; } return result; } // Consume the specified number of bytes from the buffers. void consume(std::size_t size) { total_consumed_ += size; Buffer_Iterator next = boost::asio::buffer_sequence_begin(buffers_); Buffer_Iterator end = boost::asio::buffer_sequence_end(buffers_); std::advance(next, next_elem_); while (next != end && size > 0) { Buffer next_buf = Buffer(*next) + next_elem_offset_; if (size < next_buf.size()) { next_elem_offset_ += size; size = 0; } else { size -= next_buf.size(); next_elem_offset_ = 0; ++next_elem_; ++next; } } } // Get the total number of bytes consumed from the buffers. std::size_t total_consumed() const { return total_consumed_; } private: Buffers buffers_; std::size_t total_size_; std::size_t total_consumed_; std::size_t next_elem_; std::size_t next_elem_offset_; }; // Base class of all consuming_buffers specialisations for single buffers. template <typename Buffer> class consuming_single_buffer { public: // Construct to represent the entire list of buffers. template <typename Buffer1> explicit consuming_single_buffer(const Buffer1& buffer) : buffer_(buffer), total_consumed_(0) { } // Determine if we are at the end of the buffers. bool empty() const { return total_consumed_ >= buffer_.size(); } // Get the buffer for a single transfer, with a size. Buffer prepare(std::size_t max_size) { return boost::asio::buffer(buffer_ + total_consumed_, max_size); } // Consume the specified number of bytes from the buffers. void consume(std::size_t size) { total_consumed_ += size; } // Get the total number of bytes consumed from the buffers. std::size_t total_consumed() const { return total_consumed_; } private: Buffer buffer_; std::size_t total_consumed_; }; template <> class consuming_buffers<mutable_buffer, mutable_buffer, const mutable_buffer*> : public consuming_single_buffer<BOOST_ASIO_MUTABLE_BUFFER> { public: explicit consuming_buffers(const mutable_buffer& buffer) : consuming_single_buffer<BOOST_ASIO_MUTABLE_BUFFER>(buffer) { } }; template <> class consuming_buffers<const_buffer, mutable_buffer, const mutable_buffer*> : public consuming_single_buffer<BOOST_ASIO_CONST_BUFFER> { public: explicit consuming_buffers(const mutable_buffer& buffer) : consuming_single_buffer<BOOST_ASIO_CONST_BUFFER>(buffer) { } }; template <> class consuming_buffers<const_buffer, const_buffer, const const_buffer*> : public consuming_single_buffer<BOOST_ASIO_CONST_BUFFER> { public: explicit consuming_buffers(const const_buffer& buffer) : consuming_single_buffer<BOOST_ASIO_CONST_BUFFER>(buffer) { } }; #if !defined(BOOST_ASIO_NO_DEPRECATED) template <> class consuming_buffers<mutable_buffer, mutable_buffers_1, const mutable_buffer*> : public consuming_single_buffer<BOOST_ASIO_MUTABLE_BUFFER> { public: explicit consuming_buffers(const mutable_buffers_1& buffer) : consuming_single_buffer<BOOST_ASIO_MUTABLE_BUFFER>(buffer) { } }; template <> class consuming_buffers<const_buffer, mutable_buffers_1, const mutable_buffer*> : public consuming_single_buffer<BOOST_ASIO_CONST_BUFFER> { public: explicit consuming_buffers(const mutable_buffers_1& buffer) : consuming_single_buffer<BOOST_ASIO_CONST_BUFFER>(buffer) { } }; template <> class consuming_buffers<const_buffer, const_buffers_1, const const_buffer*> : public consuming_single_buffer<BOOST_ASIO_CONST_BUFFER> { public: explicit consuming_buffers(const const_buffers_1& buffer) : consuming_single_buffer<BOOST_ASIO_CONST_BUFFER>(buffer) { } }; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) template <> class consuming_buffers<mutable_buffer, mutable_registered_buffer, const mutable_buffer*> : public consuming_single_buffer<mutable_registered_buffer> { public: explicit consuming_buffers(const mutable_registered_buffer& buffer) : consuming_single_buffer<mutable_registered_buffer>(buffer) { } }; template <> class consuming_buffers<const_buffer, mutable_registered_buffer, const mutable_buffer*> : public consuming_single_buffer<mutable_registered_buffer> { public: explicit consuming_buffers(const mutable_registered_buffer& buffer) : consuming_single_buffer<mutable_registered_buffer>(buffer) { } }; template <> class consuming_buffers<const_buffer, const_registered_buffer, const const_buffer*> : public consuming_single_buffer<const_registered_buffer> { public: explicit consuming_buffers(const const_registered_buffer& buffer) : consuming_single_buffer<const_registered_buffer>(buffer) { } }; template <typename Buffer, typename Elem> class consuming_buffers<Buffer, boost::array<Elem, 2>, typename boost::array<Elem, 2>::const_iterator> { public: // Construct to represent the entire list of buffers. explicit consuming_buffers(const boost::array<Elem, 2>& buffers) : buffers_(buffers), total_consumed_(0) { } // Determine if we are at the end of the buffers. bool empty() const { return total_consumed_ >= Buffer(buffers_[0]).size() + Buffer(buffers_[1]).size(); } // Get the buffer for a single transfer, with a size. boost::array<Buffer, 2> prepare(std::size_t max_size) { boost::array<Buffer, 2> result = {{ Buffer(buffers_[0]), Buffer(buffers_[1]) }}; std::size_t buffer0_size = result[0].size(); result[0] = boost::asio::buffer(result[0] + total_consumed_, max_size); result[1] = boost::asio::buffer( result[1] + (total_consumed_ < buffer0_size ? 0 : total_consumed_ - buffer0_size), max_size - result[0].size()); return result; } // Consume the specified number of bytes from the buffers. void consume(std::size_t size) { total_consumed_ += size; } // Get the total number of bytes consumed from the buffers. std::size_t total_consumed() const { return total_consumed_; } private: boost::array<Elem, 2> buffers_; std::size_t total_consumed_; }; template <typename Buffer, typename Elem> class consuming_buffers<Buffer, std::array<Elem, 2>, typename std::array<Elem, 2>::const_iterator> { public: // Construct to represent the entire list of buffers. explicit consuming_buffers(const std::array<Elem, 2>& buffers) : buffers_(buffers), total_consumed_(0) { } // Determine if we are at the end of the buffers. bool empty() const { return total_consumed_ >= Buffer(buffers_[0]).size() + Buffer(buffers_[1]).size(); } // Get the buffer for a single transfer, with a size. std::array<Buffer, 2> prepare(std::size_t max_size) { std::array<Buffer, 2> result = {{ Buffer(buffers_[0]), Buffer(buffers_[1]) }}; std::size_t buffer0_size = result[0].size(); result[0] = boost::asio::buffer(result[0] + total_consumed_, max_size); result[1] = boost::asio::buffer( result[1] + (total_consumed_ < buffer0_size ? 0 : total_consumed_ - buffer0_size), max_size - result[0].size()); return result; } // Consume the specified number of bytes from the buffers. void consume(std::size_t size) { total_consumed_ += size; } // Get the total number of bytes consumed from the buffers. std::size_t total_consumed() const { return total_consumed_; } private: std::array<Elem, 2> buffers_; std::size_t total_consumed_; }; // Specialisation for null_buffers to ensure that the null_buffers type is // always passed through to the underlying read or write operation. template <typename Buffer> class consuming_buffers<Buffer, null_buffers, const mutable_buffer*> : public boost::asio::null_buffers { public: consuming_buffers(const null_buffers&) { // No-op. } bool empty() { return false; } null_buffers prepare(std::size_t) { return null_buffers(); } void consume(std::size_t) { // No-op. } std::size_t total_consumed() const { return 0; } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_CONSUMING_BUFFERS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_fd_set_adapter.hpp
// // detail/posix_fd_set_adapter.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP #define BOOST_ASIO_DETAIL_POSIX_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__) \ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <cstring> #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 posix_fd_set_adapter : noncopyable { public: posix_fd_set_adapter() : max_descriptor_(invalid_socket) { using namespace std; // Needed for memset on Solaris. FD_ZERO(&fd_set_); } void reset() { using namespace std; // Needed for memset on Solaris. FD_ZERO(&fd_set_); } bool set(socket_type descriptor) { if (descriptor < (socket_type)FD_SETSIZE) { if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_) max_descriptor_ = descriptor; FD_SET(descriptor, &fd_set_); return true; } return false; } void set(reactor_op_queue<socket_type>& operations, op_queue<operation>& ops) { reactor_op_queue<socket_type>::iterator i = operations.begin(); while (i != operations.end()) { reactor_op_queue<socket_type>::iterator op_iter = i++; if (!set(op_iter->first)) { boost::system::error_code ec(error::fd_set_failure); operations.cancel_operations(op_iter, ops, ec); } } } bool is_set(socket_type descriptor) const { return FD_ISSET(descriptor, &fd_set_) != 0; } operator fd_set*() { return &fd_set_; } socket_type max_descriptor() const { return max_descriptor_; } void perform(reactor_op_queue<socket_type>& operations, op_queue<operation>& ops) const { reactor_op_queue<socket_type>::iterator i = operations.begin(); while (i != operations.end()) { reactor_op_queue<socket_type>::iterator op_iter = i++; if (is_set(op_iter->first)) operations.perform_operations(op_iter, ops); } } private: mutable fd_set fd_set_; socket_type max_descriptor_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(__CYGWIN__) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_operation.hpp
// // detail/win_iocp_operation.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_OPERATION_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_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/handler_tracking.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class win_iocp_io_context; // Base class for all operations. A function pointer is used instead of virtual // functions to avoid the associated overhead. class win_iocp_operation : public OVERLAPPED BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER { public: typedef win_iocp_operation operation_type; void complete(void* owner, const boost::system::error_code& ec, std::size_t bytes_transferred) { func_(owner, this, ec, bytes_transferred); } void destroy() { func_(0, this, boost::system::error_code(), 0); } void reset() { Internal = 0; InternalHigh = 0; Offset = 0; OffsetHigh = 0; hEvent = 0; ready_ = 0; } protected: typedef void (*func_type)( void*, win_iocp_operation*, const boost::system::error_code&, std::size_t); win_iocp_operation(func_type func) : next_(0), func_(func) { reset(); } // Prevents deletion through this type. ~win_iocp_operation() { } private: friend class op_queue_access; friend class win_iocp_io_context; win_iocp_operation* next_; func_type func_; long ready_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_OPERATION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/memory.hpp
// // detail/memory.hpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_MEMORY_HPP #define BOOST_ASIO_DETAIL_MEMORY_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 <cstdlib> #include <memory> #include <new> #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/throw_exception.hpp> #if !defined(BOOST_ASIO_HAS_STD_ALIGNED_ALLOC) \ && defined(BOOST_ASIO_HAS_BOOST_ALIGN) # include <boost/align/aligned_alloc.hpp> #endif // !defined(BOOST_ASIO_HAS_STD_ALIGNED_ALLOC) // && defined(BOOST_ASIO_HAS_BOOST_ALIGN) namespace boost { namespace asio { namespace detail { using std::allocate_shared; using std::make_shared; using std::shared_ptr; using std::weak_ptr; using std::addressof; #if defined(BOOST_ASIO_HAS_STD_TO_ADDRESS) using std::to_address; #else // defined(BOOST_ASIO_HAS_STD_TO_ADDRESS) template <typename T> inline T* to_address(T* p) { return p; } template <typename T> inline const T* to_address(const T* p) { return p; } template <typename T> inline volatile T* to_address(volatile T* p) { return p; } template <typename T> inline const volatile T* to_address(const volatile T* p) { return p; } #endif // defined(BOOST_ASIO_HAS_STD_TO_ADDRESS) inline void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space) { return std::align(alignment, size, ptr, space); } } // namespace detail using std::allocator_arg_t; # define BOOST_ASIO_USES_ALLOCATOR(t) \ namespace std { \ template <typename Allocator> \ struct uses_allocator<t, Allocator> : true_type {}; \ } \ /**/ # define BOOST_ASIO_REBIND_ALLOC(alloc, t) \ typename std::allocator_traits<alloc>::template rebind_alloc<t> /**/ inline void* aligned_new(std::size_t align, std::size_t size) { #if defined(BOOST_ASIO_HAS_STD_ALIGNED_ALLOC) align = (align < BOOST_ASIO_DEFAULT_ALIGN) ? BOOST_ASIO_DEFAULT_ALIGN : align; size = (size % align == 0) ? size : size + (align - size % align); void* ptr = std::aligned_alloc(align, size); if (!ptr) { std::bad_alloc ex; boost::asio::detail::throw_exception(ex); } return ptr; #elif defined(BOOST_ASIO_HAS_BOOST_ALIGN) align = (align < BOOST_ASIO_DEFAULT_ALIGN) ? BOOST_ASIO_DEFAULT_ALIGN : align; size = (size % align == 0) ? size : size + (align - size % align); void* ptr = boost::alignment::aligned_alloc(align, size); if (!ptr) { std::bad_alloc ex; boost::asio::detail::throw_exception(ex); } return ptr; #elif defined(BOOST_ASIO_MSVC) align = (align < BOOST_ASIO_DEFAULT_ALIGN) ? BOOST_ASIO_DEFAULT_ALIGN : align; size = (size % align == 0) ? size : size + (align - size % align); void* ptr = _aligned_malloc(size, align); if (!ptr) { std::bad_alloc ex; boost::asio::detail::throw_exception(ex); } return ptr; #else // defined(BOOST_ASIO_MSVC) (void)align; return ::operator new(size); #endif // defined(BOOST_ASIO_MSVC) } inline void aligned_delete(void* ptr) { #if defined(BOOST_ASIO_HAS_STD_ALIGNED_ALLOC) std::free(ptr); #elif defined(BOOST_ASIO_HAS_BOOST_ALIGN) boost::alignment::aligned_free(ptr); #elif defined(BOOST_ASIO_MSVC) _aligned_free(ptr); #else // defined(BOOST_ASIO_MSVC) ::operator delete(ptr); #endif // defined(BOOST_ASIO_MSVC) } } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_MEMORY_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_overlapped_ptr.hpp
// // detail/win_iocp_overlapped_ptr.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_PTR_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_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_IOCP) #include <boost/asio/io_context.hpp> #include <boost/asio/query.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/win_iocp_overlapped_op.hpp> #include <boost/asio/detail/win_iocp_io_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Wraps a handler to create an OVERLAPPED object for use with overlapped I/O. class win_iocp_overlapped_ptr : private noncopyable { public: // Construct an empty win_iocp_overlapped_ptr. win_iocp_overlapped_ptr() : ptr_(0), iocp_service_(0) { } // Construct an win_iocp_overlapped_ptr to contain the specified handler. template <typename Executor, typename Handler> explicit win_iocp_overlapped_ptr(const Executor& ex, Handler&& handler) : ptr_(0), iocp_service_(0) { this->reset(ex, static_cast<Handler&&>(handler)); } // Destructor automatically frees the OVERLAPPED object unless released. ~win_iocp_overlapped_ptr() { reset(); } // Reset to empty. void reset() { if (ptr_) { ptr_->destroy(); ptr_ = 0; iocp_service_->work_finished(); iocp_service_ = 0; } } // Reset to contain the specified handler, freeing any current OVERLAPPED // object. template <typename Executor, typename Handler> void reset(const Executor& ex, Handler handler) { win_iocp_io_context* iocp_service = this->get_iocp_service(ex); typedef win_iocp_overlapped_op<Handler, Executor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; p.p = new (p.v) op(handler, ex); BOOST_ASIO_HANDLER_CREATION((ex.context(), *p.p, "iocp_service", iocp_service, 0, "overlapped")); iocp_service->work_started(); reset(); ptr_ = p.p; p.v = p.p = 0; iocp_service_ = iocp_service; } // Get the contained OVERLAPPED object. OVERLAPPED* get() { return ptr_; } // Get the contained OVERLAPPED object. const OVERLAPPED* get() const { return ptr_; } // Release ownership of the OVERLAPPED object. OVERLAPPED* release() { if (ptr_) iocp_service_->on_pending(ptr_); OVERLAPPED* tmp = ptr_; ptr_ = 0; iocp_service_ = 0; return tmp; } // Post completion notification for overlapped operation. Releases ownership. void complete(const boost::system::error_code& ec, std::size_t bytes_transferred) { if (ptr_) { iocp_service_->on_completion(ptr_, ec, static_cast<DWORD>(bytes_transferred)); ptr_ = 0; iocp_service_ = 0; } } private: template <typename Executor> static win_iocp_io_context* get_iocp_service(const Executor& ex, enable_if_t< can_query<const Executor&, execution::context_t>::value >* = 0) { return &use_service<win_iocp_io_context>( boost::asio::query(ex, execution::context)); } template <typename Executor> static win_iocp_io_context* get_iocp_service(const Executor& ex, enable_if_t< !can_query<const Executor&, execution::context_t>::value >* = 0) { return &use_service<win_iocp_io_context>(ex.context()); } static win_iocp_io_context* get_iocp_service( const io_context::executor_type& ex) { return &boost::asio::query(ex, execution::context).impl_; } win_iocp_operation* ptr_; win_iocp_io_context* iocp_service_; }; } // 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_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/static_mutex.hpp
// // detail/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_STATIC_MUTEX_HPP #define BOOST_ASIO_DETAIL_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/null_static_mutex.hpp> #elif defined(BOOST_ASIO_WINDOWS) # include <boost/asio/detail/win_static_mutex.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_static_mutex.hpp> #else # include <boost/asio/detail/std_static_mutex.hpp> #endif namespace boost { namespace asio { namespace detail { #if !defined(BOOST_ASIO_HAS_THREADS) typedef null_static_mutex static_mutex; # define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_NULL_STATIC_MUTEX_INIT #elif defined(BOOST_ASIO_WINDOWS) typedef win_static_mutex static_mutex; # define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_WIN_STATIC_MUTEX_INIT #elif defined(BOOST_ASIO_HAS_PTHREADS) typedef posix_static_mutex static_mutex; # define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_POSIX_STATIC_MUTEX_INIT #else typedef std_static_mutex static_mutex; # define BOOST_ASIO_STATIC_MUTEX_INIT BOOST_ASIO_STD_STATIC_MUTEX_INIT #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_STATIC_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_ssocket_service_base.hpp
// // detail/winrt_ssocket_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_WINRT_SSOCKET_SERVICE_BASE_HPP #define BOOST_ASIO_DETAIL_WINRT_SSOCKET_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_WINDOWS_RUNTIME) #include <boost/asio/buffer.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/socket_types.hpp> #include <boost/asio/detail/winrt_async_manager.hpp> #include <boost/asio/detail/winrt_socket_recv_op.hpp> #include <boost/asio/detail/winrt_socket_send_op.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_ssocket_service_base { public: // The native type of a socket. typedef Windows::Networking::Sockets::StreamSocket^ native_handle_type; // The implementation type of the socket. struct base_implementation_type { // Default constructor. base_implementation_type() : socket_(nullptr), next_(0), prev_(0) { } // The underlying native socket. native_handle_type socket_; // Pointers to adjacent socket implementations in linked list. base_implementation_type* next_; base_implementation_type* prev_; }; // Constructor. BOOST_ASIO_DECL winrt_ssocket_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&); // 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, winrt_ssocket_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_ != nullptr; } // 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 native_handle_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::system::error_code cancel(base_implementation_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Determine whether the socket is at the out-of-band data mark. bool at_mark(const base_implementation_type&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return false; } // Determine the number of bytes available for reading. std::size_t available(const base_implementation_type&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return 0; } // Perform an IO control command on the socket. template <typename IO_Control_Command> boost::system::error_code io_control(base_implementation_type&, IO_Control_Command&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Gets the non-blocking mode of the socket. bool non_blocking(const base_implementation_type&) const { return false; } // Sets the non-blocking mode of the socket. boost::system::error_code non_blocking(base_implementation_type&, bool, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Gets the non-blocking mode of the native socket implementation. bool native_non_blocking(const base_implementation_type&) const { return false; } // Sets the non-blocking mode of the native socket implementation. boost::system::error_code native_non_blocking(base_implementation_type&, bool, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Send the given data to the peer. template <typename ConstBufferSequence> std::size_t send(base_implementation_type& impl, const ConstBufferSequence& buffers, socket_base::message_flags flags, boost::system::error_code& ec) { return do_send(impl, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::first(buffers), flags, ec); } // Wait until data can be sent without blocking. std::size_t send(base_implementation_type&, const null_buffers&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; 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); // Allocate and construct an operation to wrap the handler. typedef winrt_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(buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "socket", &impl, 0, "async_send")); start_send_op(impl, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::first(buffers), flags, p.p, is_continuation); 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&, const null_buffers&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler(handler, ec, bytes_transferred)); } // Receive some data from the peer. Returns the number of bytes received. template <typename MutableBufferSequence> std::size_t receive(base_implementation_type& impl, const MutableBufferSequence& buffers, socket_base::message_flags flags, boost::system::error_code& ec) { return do_receive(impl, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::first(buffers), flags, ec); } // Wait until data can be received without blocking. std::size_t receive(base_implementation_type&, const null_buffers&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; 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); // Allocate and construct an operation to wrap the handler. typedef winrt_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(buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "socket", &impl, 0, "async_receive")); start_receive_op(impl, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::first(buffers), flags, p.p, is_continuation); p.v = p.p = 0; } // Wait until data can be received without blocking. template <typename Handler, typename IoExecutor> void async_receive(base_implementation_type&, const null_buffers&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler(handler, ec, bytes_transferred)); } protected: // Helper function to obtain endpoints associated with the connection. BOOST_ASIO_DECL std::size_t do_get_endpoint( const base_implementation_type& impl, bool local, void* addr, std::size_t addr_len, boost::system::error_code& ec) const; // Helper function to set a socket option. BOOST_ASIO_DECL boost::system::error_code do_set_option( base_implementation_type& impl, int level, int optname, const void* optval, std::size_t optlen, boost::system::error_code& ec); // Helper function to get a socket option. BOOST_ASIO_DECL void do_get_option( const base_implementation_type& impl, int level, int optname, void* optval, std::size_t* optlen, boost::system::error_code& ec) const; // Helper function to perform a synchronous connect. BOOST_ASIO_DECL boost::system::error_code do_connect( base_implementation_type& impl, const void* addr, boost::system::error_code& ec); // Helper function to start an asynchronous connect. BOOST_ASIO_DECL void start_connect_op( base_implementation_type& impl, const void* addr, winrt_async_op<void>* op, bool is_continuation); // Helper function to perform a synchronous send. BOOST_ASIO_DECL std::size_t do_send( base_implementation_type& impl, const boost::asio::const_buffer& data, socket_base::message_flags flags, boost::system::error_code& ec); // Helper function to start an asynchronous send. BOOST_ASIO_DECL void start_send_op(base_implementation_type& impl, const boost::asio::const_buffer& data, socket_base::message_flags flags, winrt_async_op<unsigned int>* op, bool is_continuation); // Helper function to perform a synchronous receive. BOOST_ASIO_DECL std::size_t do_receive( base_implementation_type& impl, const boost::asio::mutable_buffer& data, socket_base::message_flags flags, boost::system::error_code& ec); // Helper function to start an asynchronous receive. BOOST_ASIO_DECL void start_receive_op(base_implementation_type& impl, const boost::asio::mutable_buffer& data, socket_base::message_flags flags, winrt_async_op<Windows::Storage::Streams::IBuffer^>* op, bool is_continuation); // 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_; // The manager that keeps track of outstanding operations. winrt_async_manager& async_manager_; // 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/winrt_ssocket_service_base.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_WINRT_SSOCKET_SERVICE_BASE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/base_from_completion_cond.hpp
// // detail/base_from_completion_cond.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_BASE_FROM_COMPLETION_COND_HPP #define BOOST_ASIO_DETAIL_BASE_FROM_COMPLETION_COND_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/completion_condition.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename CompletionCondition> class base_from_completion_cond { protected: explicit base_from_completion_cond(CompletionCondition& completion_condition) : completion_condition_( static_cast<CompletionCondition&&>(completion_condition)) { } std::size_t check_for_completion( const boost::system::error_code& ec, std::size_t total_transferred) { return detail::adapt_completion_condition_result( completion_condition_(ec, total_transferred)); } private: CompletionCondition completion_condition_; }; template <> class base_from_completion_cond<transfer_all_t> { protected: explicit base_from_completion_cond(transfer_all_t) { } static std::size_t check_for_completion( const boost::system::error_code& ec, std::size_t total_transferred) { return transfer_all_t()(ec, total_transferred); } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/initiate_dispatch.hpp
// // detail/initiate_dispatch.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_INITIATE_DISPATCH_HPP #define BOOST_ASIO_DETAIL_INITIATE_DISPATCH_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/detail/work_dispatcher.hpp> #include <boost/asio/execution/allocator.hpp> #include <boost/asio/execution/blocking.hpp> #include <boost/asio/prefer.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class initiate_dispatch { public: template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< associated_executor_t<decay_t<CompletionHandler>> >::value >* = 0) const { associated_executor_t<decay_t<CompletionHandler>> ex( (get_associated_executor)(handler)); associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); boost::asio::prefer(ex, execution::allocator(alloc)).execute( boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler))); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< associated_executor_t<decay_t<CompletionHandler>> >::value >* = 0) const { associated_executor_t<decay_t<CompletionHandler>> ex( (get_associated_executor)(handler)); associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); ex.dispatch(boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler)), alloc); } }; template <typename Executor> class initiate_dispatch_with_executor { public: typedef Executor executor_type; explicit initiate_dispatch_with_executor(const Executor& ex) : ex_(ex) { } executor_type get_executor() const noexcept { return ex_; } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< !detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); boost::asio::prefer(ex_, execution::allocator(alloc)).execute( boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler))); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { typedef decay_t<CompletionHandler> handler_t; typedef associated_executor_t<handler_t, Executor> handler_ex_t; handler_ex_t handler_ex((get_associated_executor)(handler, ex_)); associated_allocator_t<handler_t> alloc( (get_associated_allocator)(handler)); boost::asio::prefer(ex_, execution::allocator(alloc)).execute( detail::work_dispatcher<handler_t, handler_ex_t>( static_cast<CompletionHandler&&>(handler), handler_ex)); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< !detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); ex_.dispatch(boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler)), alloc); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { typedef decay_t<CompletionHandler> handler_t; typedef associated_executor_t<handler_t, Executor> handler_ex_t; handler_ex_t handler_ex((get_associated_executor)(handler, ex_)); associated_allocator_t<handler_t> alloc( (get_associated_allocator)(handler)); ex_.dispatch(detail::work_dispatcher<handler_t, handler_ex_t>( static_cast<CompletionHandler&&>(handler), handler_ex), alloc); } private: Executor ex_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_INITIATE_DISPATCH_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_send_op.hpp
// // detail/reactive_socket_send_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SEND_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_SEND_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 ConstBufferSequence> class reactive_socket_send_op_base : public reactor_op { public: reactive_socket_send_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const ConstBufferSequence& buffers, socket_base::message_flags flags, func_type complete_func) : reactor_op(success_ec, &reactive_socket_send_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), flags_(flags) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_send_op_base* o( static_cast<reactive_socket_send_op_base*>(base)); typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; status result; if (bufs_type::is_single_buffer) { result = socket_ops::non_blocking_send1(o->socket_, bufs_type::first(o->buffers_).data(), bufs_type::first(o->buffers_).size(), o->flags_, o->ec_, o->bytes_transferred_) ? done : not_done; if (result == done) if ((o->state_ & socket_ops::stream_oriented) != 0) if (o->bytes_transferred_ < bufs_type::first(o->buffers_).size()) result = done_and_exhausted; } else { bufs_type bufs(o->buffers_); result = socket_ops::non_blocking_send(o->socket_, bufs.buffers(), bufs.count(), o->flags_, o->ec_, o->bytes_transferred_) ? done : not_done; if (result == done) if ((o->state_ & socket_ops::stream_oriented) != 0) if (o->bytes_transferred_ < bufs.total_size()) result = done_and_exhausted; } BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_send", o->ec_, o->bytes_transferred_)); return result; } private: socket_type socket_; socket_ops::state_type state_; ConstBufferSequence buffers_; socket_base::message_flags flags_; }; template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class reactive_socket_send_op : public reactive_socket_send_op_base<ConstBufferSequence> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_send_op); reactive_socket_send_op(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const ConstBufferSequence& buffers, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : reactive_socket_send_op_base<ConstBufferSequence>(success_ec, socket, state, buffers, flags, &reactive_socket_send_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_send_op* o(static_cast<reactive_socket_send_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_send_op* o(static_cast<reactive_socket_send_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_SEND_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_service.hpp
// // detail/io_uring_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_SERVICE_HPP #define BOOST_ASIO_DETAIL_IO_URING_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_IO_URING) #include <liburing.h> #include <boost/asio/detail/atomic_count.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/conditionally_enabled_mutex.hpp> #include <boost/asio/detail/io_uring_operation.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.hpp> #include <boost/asio/detail/scheduler_task.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> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class io_uring_service : public execution_context_service_base<io_uring_service>, 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, except_op = 2, max_ops = 3 }; class io_object; // An I/O queue stores operations that must run serially. class io_queue : operation { friend class io_uring_service; io_object* io_object_; op_queue<io_uring_operation> op_queue_; bool cancel_requested_; BOOST_ASIO_DECL io_queue(); void set_result(int r) { task_result_ = static_cast<unsigned>(r); } BOOST_ASIO_DECL operation* perform_io(int result); BOOST_ASIO_DECL static void do_complete(void* owner, operation* base, const boost::system::error_code& ec, std::size_t bytes_transferred); }; // Per I/O object state. class io_object { friend class io_uring_service; friend class object_pool_access; io_object* next_; io_object* prev_; mutex mutex_; io_uring_service* service_; io_queue queues_[max_ops]; bool shutdown_; BOOST_ASIO_DECL io_object(bool locking); }; // Per I/O object data. typedef io_object* per_io_object_data; // Constructor. BOOST_ASIO_DECL io_uring_service(boost::asio::execution_context& ctx); // Destructor. BOOST_ASIO_DECL ~io_uring_service(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Recreate internal state 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 an I/O object with io_uring. BOOST_ASIO_DECL void register_io_object(io_object*& io_obj); // Register an internal I/O object with io_uring. BOOST_ASIO_DECL void register_internal_io_object( io_object*& io_obj, int op_type, io_uring_operation* op); // Register buffers with io_uring. BOOST_ASIO_DECL void register_buffers(const ::iovec* v, unsigned n); // Unregister buffers from io_uring. BOOST_ASIO_DECL void unregister_buffers(); // Post an operation for immediate completion. void post_immediate_completion(operation* op, bool is_continuation); // Start a new operation. The operation will be prepared and submitted to the // io_uring when it is at the head of its I/O operation queue. BOOST_ASIO_DECL void start_op(int op_type, per_io_object_data& io_obj, io_uring_operation* op, bool is_continuation); // Cancel all operations associated with the given I/O object. The handlers // associated with the I/O object will be invoked with the operation_aborted // error. BOOST_ASIO_DECL void cancel_ops(per_io_object_data& io_obj); // Cancel all operations associated with the given I/O object and key. The // handlers associated with the object and key will be invoked with the // operation_aborted error. BOOST_ASIO_DECL void cancel_ops_by_key(per_io_object_data& io_obj, int op_type, void* cancellation_key); // Cancel any operations that are running against the I/O object and remove // its registration from the service. The service resources associated with // the I/O object must be released by calling cleanup_io_object. BOOST_ASIO_DECL void deregister_io_object(per_io_object_data& io_obj); // Perform any post-deregistration cleanup tasks associated with the I/O // object. BOOST_ASIO_DECL void cleanup_io_object(per_io_object_data& io_obj); // 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); // Wait on io_uring once until interrupted or events are ready to be // dispatched. BOOST_ASIO_DECL void run(long usec, op_queue<operation>& ops); // Interrupt the io_uring wait. BOOST_ASIO_DECL void interrupt(); private: // The hint to pass to io_uring_queue_init to size its data structures. enum { ring_size = 16384 }; // The number of operations to submit in a batch. enum { submit_batch_size = 128 }; // The number of operations to complete in a batch. enum { complete_batch_size = 128 }; // The type used for processing eventfd readiness notifications. class event_fd_read_op; // Initialise the ring. BOOST_ASIO_DECL void init_ring(); // Register the eventfd descriptor for readiness notifications. BOOST_ASIO_DECL void register_with_reactor(); // Allocate a new I/O object. BOOST_ASIO_DECL io_object* allocate_io_object(); // Free an existing I/O object. BOOST_ASIO_DECL void free_io_object(io_object* s); // Helper function to cancel all operations associated with the given I/O // object. This function must be called while the I/O object's mutex is held. // Returns true if there are operations for which cancellation is pending. BOOST_ASIO_DECL bool do_cancel_ops( per_io_object_data& io_obj, op_queue<operation>& ops); // 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 current timeout value. BOOST_ASIO_DECL __kernel_timespec get_timeout() const; // Get a new submission queue entry, flushing the queue if necessary. BOOST_ASIO_DECL ::io_uring_sqe* get_sqe(); // Submit pending submission queue entries. BOOST_ASIO_DECL void submit_sqes(); // Post an operation to submit the pending submission queue entries. BOOST_ASIO_DECL void post_submit_sqes_op(mutex::scoped_lock& lock); // Push an operation to submit the pending submission queue entries. BOOST_ASIO_DECL void push_submit_sqes_op(op_queue<operation>& ops); // Helper operation to submit pending submission queue entries. class submit_sqes_op : operation { friend class io_uring_service; io_uring_service* service_; BOOST_ASIO_DECL submit_sqes_op(io_uring_service* s); BOOST_ASIO_DECL static void do_complete(void* owner, operation* base, const boost::system::error_code& ec, std::size_t bytes_transferred); }; // The scheduler implementation used to post completions. scheduler& scheduler_; // Mutex to protect access to internal data. mutex mutex_; // The ring. ::io_uring ring_; // The count of unfinished work. atomic_count outstanding_work_; // The operation used to submit the pending submission queue entries. submit_sqes_op submit_sqes_op_; // The number of pending submission queue entries_. int pending_sqes_; // Whether there is a pending submission operation. bool pending_submit_sqes_op_; // Whether the service has been shut down. bool shutdown_; // The timer queues. timer_queue_set timer_queues_; // The timespec for the pending timeout operation. Must remain valid while the // operation is outstanding. __kernel_timespec timeout_; // Mutex to protect access to the registered I/O objects. mutex registration_mutex_; // Keep track of all registered I/O objects. object_pool<io_object> registered_io_objects_; // Helper class to do post-perform_io cleanup. struct perform_io_cleanup_on_block_exit; friend struct perform_io_cleanup_on_block_exit; // The reactor used to register for eventfd readiness. reactor& reactor_; // The per-descriptor reactor data used for the eventfd. reactor::per_descriptor_data reactor_data_; // The eventfd descriptor used to wait for readiness. int event_fd_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/io_uring_service.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/io_uring_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IO_URING) #endif // BOOST_ASIO_DETAIL_IO_URING_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactor_op_queue.hpp
// // detail/reactor_op_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_REACTOR_OP_QUEUE_HPP #define BOOST_ASIO_DETAIL_REACTOR_OP_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 <boost/asio/detail/hash_map.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Descriptor> class reactor_op_queue : private noncopyable { public: typedef Descriptor key_type; struct mapped_type : op_queue<reactor_op> { mapped_type() {} mapped_type(const mapped_type&) {} void operator=(const mapped_type&) {} }; typedef typename hash_map<key_type, mapped_type>::value_type value_type; typedef typename hash_map<key_type, mapped_type>::iterator iterator; // Constructor. reactor_op_queue() : operations_() { } // Obtain iterators to all registered descriptors. iterator begin() { return operations_.begin(); } iterator end() { return operations_.end(); } // Add a new operation to the queue. Returns true if this is the only // operation for the given descriptor, in which case the reactor's event // demultiplexing function call may need to be interrupted and restarted. bool enqueue_operation(Descriptor descriptor, reactor_op* op) { std::pair<iterator, bool> entry = operations_.insert(value_type(descriptor, mapped_type())); entry.first->second.push(op); return entry.second; } // Cancel all operations associated with the descriptor identified by the // supplied iterator. Any operations pending for the descriptor will be // cancelled. Returns true if any operations were cancelled, in which case // the reactor's event demultiplexing function may need to be interrupted and // restarted. bool cancel_operations(iterator i, op_queue<operation>& ops, const boost::system::error_code& ec = boost::asio::error::operation_aborted) { if (i != operations_.end()) { while (reactor_op* op = i->second.front()) { op->ec_ = ec; i->second.pop(); ops.push(op); } operations_.erase(i); return true; } return false; } // Cancel all operations associated with the descriptor. Any operations // pending for the descriptor will be cancelled. Returns true if any // operations were cancelled, in which case the reactor's event // demultiplexing function may need to be interrupted and restarted. bool cancel_operations(Descriptor descriptor, op_queue<operation>& ops, const boost::system::error_code& ec = boost::asio::error::operation_aborted) { return this->cancel_operations(operations_.find(descriptor), ops, ec); } // Cancel operations associated with the descriptor identified by the // supplied iterator, and the specified cancellation key. Any operations // pending for the descriptor with the key will be cancelled. Returns true if // any operations were cancelled, in which case the reactor's event // demultiplexing function may need to be interrupted and restarted. bool cancel_operations_by_key(iterator i, op_queue<operation>& ops, void* cancellation_key, const boost::system::error_code& ec = boost::asio::error::operation_aborted) { bool result = false; if (i != operations_.end()) { op_queue<reactor_op> other_ops; while (reactor_op* op = i->second.front()) { i->second.pop(); if (op->cancellation_key_ == cancellation_key) { op->ec_ = ec; ops.push(op); result = true; } else other_ops.push(op); } i->second.push(other_ops); if (i->second.empty()) operations_.erase(i); } return result; } // Cancel all operations associated with the descriptor. Any operations // pending for the descriptor will be cancelled. Returns true if any // operations were cancelled, in which case the reactor's event // demultiplexing function may need to be interrupted and restarted. bool cancel_operations_by_key(Descriptor descriptor, op_queue<operation>& ops, void* cancellation_key, const boost::system::error_code& ec = boost::asio::error::operation_aborted) { return this->cancel_operations_by_key( operations_.find(descriptor), ops, cancellation_key, ec); } // Whether there are no operations in the queue. bool empty() const { return operations_.empty(); } // Determine whether there are any operations associated with the descriptor. bool has_operation(Descriptor descriptor) const { return operations_.find(descriptor) != operations_.end(); } // Perform the operations corresponding to the descriptor identified by the // supplied iterator. Returns true if there are still unfinished operations // queued for the descriptor. bool perform_operations(iterator i, op_queue<operation>& ops) { if (i != operations_.end()) { while (reactor_op* op = i->second.front()) { if (op->perform()) { i->second.pop(); ops.push(op); } else { return true; } } operations_.erase(i); } return false; } // Perform the operations corresponding to the descriptor. Returns true if // there are still unfinished operations queued for the descriptor. bool perform_operations(Descriptor descriptor, op_queue<operation>& ops) { return this->perform_operations(operations_.find(descriptor), ops); } // Get all operations owned by the queue. void get_all_operations(op_queue<operation>& ops) { iterator i = operations_.begin(); while (i != operations_.end()) { iterator op_iter = i++; ops.push(op_iter->second); operations_.erase(op_iter); } } private: // The operations that are currently executing asynchronously. hash_map<key_type, mapped_type> operations_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_REACTOR_OP_QUEUE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_descriptor_read_at_op.hpp
// // detail/io_uring_descriptor_read_at_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_READ_AT_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_READ_AT_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/cstdint.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 MutableBufferSequence> class io_uring_descriptor_read_at_op_base : public io_uring_operation { public: io_uring_descriptor_read_at_op_base( const boost::system::error_code& success_ec, int descriptor, descriptor_ops::state_type state, uint64_t offset, const MutableBufferSequence& buffers, func_type complete_func) : io_uring_operation(success_ec, &io_uring_descriptor_read_at_op_base::do_prepare, &io_uring_descriptor_read_at_op_base::do_perform, complete_func), descriptor_(descriptor), state_(state), offset_(offset), buffers_(buffers), bufs_(buffers) { } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_descriptor_read_at_op_base* o( static_cast<io_uring_descriptor_read_at_op_base*>(base)); if ((o->state_ & descriptor_ops::internal_non_blocking) != 0) { ::io_uring_prep_poll_add(sqe, o->descriptor_, POLLIN); } else if (o->bufs_.is_single_buffer && o->bufs_.is_registered_buffer) { ::io_uring_prep_read_fixed(sqe, o->descriptor_, o->bufs_.buffers()->iov_base, o->bufs_.buffers()->iov_len, o->offset_, o->bufs_.registered_id().native_handle()); } else { ::io_uring_prep_readv(sqe, o->descriptor_, o->bufs_.buffers(), o->bufs_.count(), o->offset_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_descriptor_read_at_op_base* o( static_cast<io_uring_descriptor_read_at_op_base*>(base)); if ((o->state_ & descriptor_ops::internal_non_blocking) != 0) { if (o->bufs_.is_single_buffer) { return descriptor_ops::non_blocking_read_at1(o->descriptor_, o->offset_, o->bufs_.first(o->buffers_).data(), o->bufs_.first(o->buffers_).size(), o->ec_, o->bytes_transferred_); } else { return descriptor_ops::non_blocking_read_at(o->descriptor_, o->offset_, o->bufs_.buffers(), o->bufs_.count(), o->ec_, o->bytes_transferred_); } } else if (after_completion) { if (!o->ec_ && o->bytes_transferred_ == 0) o->ec_ = boost::asio::error::eof; } 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_; uint64_t offset_; MutableBufferSequence buffers_; buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class io_uring_descriptor_read_at_op : public io_uring_descriptor_read_at_op_base<MutableBufferSequence> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_descriptor_read_at_op); io_uring_descriptor_read_at_op(const boost::system::error_code& success_ec, int descriptor, descriptor_ops::state_type state, uint64_t offset, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : io_uring_descriptor_read_at_op_base<MutableBufferSequence>( success_ec, descriptor, state, offset, buffers, &io_uring_descriptor_read_at_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_read_at_op* o (static_cast<io_uring_descriptor_read_at_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_READ_AT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/descriptor_write_op.hpp
// // detail/descriptor_write_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP #define BOOST_ASIO_DETAIL_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_WINDOWS) && !defined(__CYGWIN__) #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/memory.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename ConstBufferSequence> class descriptor_write_op_base : public reactor_op { public: descriptor_write_op_base(const boost::system::error_code& success_ec, int descriptor, const ConstBufferSequence& buffers, func_type complete_func) : reactor_op(success_ec, &descriptor_write_op_base::do_perform, complete_func), descriptor_(descriptor), buffers_(buffers) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); descriptor_write_op_base* o(static_cast<descriptor_write_op_base*>(base)); typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; status result; if (bufs_type::is_single_buffer) { result = descriptor_ops::non_blocking_write1(o->descriptor_, bufs_type::first(o->buffers_).data(), bufs_type::first(o->buffers_).size(), o->ec_, o->bytes_transferred_) ? done : not_done; } else { bufs_type bufs(o->buffers_); result = descriptor_ops::non_blocking_write(o->descriptor_, bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_) ? done : not_done; } BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_write", o->ec_, o->bytes_transferred_)); return result; } private: int descriptor_; ConstBufferSequence buffers_; }; template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class descriptor_write_op : public descriptor_write_op_base<ConstBufferSequence> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(descriptor_write_op); descriptor_write_op(const boost::system::error_code& success_ec, int descriptor, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : descriptor_write_op_base<ConstBufferSequence>(success_ec, descriptor, buffers, &descriptor_write_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); descriptor_write_op* o(static_cast<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; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); descriptor_write_op* o(static_cast<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. 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 // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_tss_ptr.hpp
// // detail/null_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_NULL_TSS_PTR_HPP #define BOOST_ASIO_DETAIL_NULL_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/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T> class null_tss_ptr : private noncopyable { public: // Constructor. null_tss_ptr() : value_(0) { } // Destructor. ~null_tss_ptr() { } // Get the value. operator T*() const { return value_; } // Set the value. void operator=(T* value) { value_ = value; } private: T* value_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_HAS_THREADS) #endif // BOOST_ASIO_DETAIL_NULL_TSS_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/thread_info_base.hpp
// // detail/thread_info_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_THREAD_INFO_BASE_HPP #define BOOST_ASIO_DETAIL_THREAD_INFO_BASE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <climits> #include <cstddef> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #if !defined(BOOST_ASIO_NO_EXCEPTIONS) # include <exception> # include <boost/asio/multiple_exceptions.hpp> #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { #ifndef BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE # define BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE 2 #endif // BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE class thread_info_base : private noncopyable { public: struct default_tag { enum { cache_size = BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE, begin_mem_index = 0, end_mem_index = cache_size }; }; struct awaitable_frame_tag { enum { cache_size = BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE, begin_mem_index = default_tag::end_mem_index, end_mem_index = begin_mem_index + cache_size }; }; struct executor_function_tag { enum { cache_size = BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE, begin_mem_index = awaitable_frame_tag::end_mem_index, end_mem_index = begin_mem_index + cache_size }; }; struct cancellation_signal_tag { enum { cache_size = BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE, begin_mem_index = executor_function_tag::end_mem_index, end_mem_index = begin_mem_index + cache_size }; }; struct parallel_group_tag { enum { cache_size = BOOST_ASIO_RECYCLING_ALLOCATOR_CACHE_SIZE, begin_mem_index = cancellation_signal_tag::end_mem_index, end_mem_index = begin_mem_index + cache_size }; }; enum { max_mem_index = parallel_group_tag::end_mem_index }; thread_info_base() #if !defined(BOOST_ASIO_NO_EXCEPTIONS) : has_pending_exception_(0) #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) { for (int i = 0; i < max_mem_index; ++i) reusable_memory_[i] = 0; } ~thread_info_base() { for (int i = 0; i < max_mem_index; ++i) { // The following test for non-null pointers is technically redundant, but // it is significantly faster when using a tight io_context::poll() loop // in latency sensitive applications. if (reusable_memory_[i]) aligned_delete(reusable_memory_[i]); } } static void* allocate(thread_info_base* this_thread, std::size_t size, std::size_t align = BOOST_ASIO_DEFAULT_ALIGN) { return allocate(default_tag(), this_thread, size, align); } static void deallocate(thread_info_base* this_thread, void* pointer, std::size_t size) { deallocate(default_tag(), this_thread, pointer, size); } template <typename Purpose> static void* allocate(Purpose, thread_info_base* this_thread, std::size_t size, std::size_t align = BOOST_ASIO_DEFAULT_ALIGN) { std::size_t chunks = (size + chunk_size - 1) / chunk_size; if (this_thread) { for (int mem_index = Purpose::begin_mem_index; mem_index < Purpose::end_mem_index; ++mem_index) { if (this_thread->reusable_memory_[mem_index]) { void* const pointer = this_thread->reusable_memory_[mem_index]; unsigned char* const mem = static_cast<unsigned char*>(pointer); if (static_cast<std::size_t>(mem[0]) >= chunks && reinterpret_cast<std::size_t>(pointer) % align == 0) { this_thread->reusable_memory_[mem_index] = 0; mem[size] = mem[0]; return pointer; } } } for (int mem_index = Purpose::begin_mem_index; mem_index < Purpose::end_mem_index; ++mem_index) { if (this_thread->reusable_memory_[mem_index]) { void* const pointer = this_thread->reusable_memory_[mem_index]; this_thread->reusable_memory_[mem_index] = 0; aligned_delete(pointer); break; } } } void* const pointer = aligned_new(align, chunks * chunk_size + 1); unsigned char* const mem = static_cast<unsigned char*>(pointer); mem[size] = (chunks <= UCHAR_MAX) ? static_cast<unsigned char>(chunks) : 0; return pointer; } template <typename Purpose> static void deallocate(Purpose, thread_info_base* this_thread, void* pointer, std::size_t size) { if (size <= chunk_size * UCHAR_MAX) { if (this_thread) { for (int mem_index = Purpose::begin_mem_index; mem_index < Purpose::end_mem_index; ++mem_index) { if (this_thread->reusable_memory_[mem_index] == 0) { unsigned char* const mem = static_cast<unsigned char*>(pointer); mem[0] = mem[size]; this_thread->reusable_memory_[mem_index] = pointer; return; } } } } aligned_delete(pointer); } void capture_current_exception() { #if !defined(BOOST_ASIO_NO_EXCEPTIONS) switch (has_pending_exception_) { case 0: has_pending_exception_ = 1; pending_exception_ = std::current_exception(); break; case 1: has_pending_exception_ = 2; pending_exception_ = std::make_exception_ptr<multiple_exceptions>( multiple_exceptions(pending_exception_)); break; default: break; } #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) } void rethrow_pending_exception() { #if !defined(BOOST_ASIO_NO_EXCEPTIONS) if (has_pending_exception_ > 0) { has_pending_exception_ = 0; std::exception_ptr ex( static_cast<std::exception_ptr&&>( pending_exception_)); std::rethrow_exception(ex); } #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) } private: #if defined(BOOST_ASIO_HAS_IO_URING) enum { chunk_size = 8 }; #else // defined(BOOST_ASIO_HAS_IO_URING) enum { chunk_size = 4 }; #endif // defined(BOOST_ASIO_HAS_IO_URING) void* reusable_memory_[max_mem_index]; #if !defined(BOOST_ASIO_NO_EXCEPTIONS) int has_pending_exception_; std::exception_ptr pending_exception_; #endif // !defined(BOOST_ASIO_NO_EXCEPTIONS) }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_THREAD_INFO_BASE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/exception.hpp
// // detail/exception.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_EXCEPTION_HPP #define BOOST_ASIO_DETAIL_EXCEPTION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <exception> namespace boost { namespace asio { using std::exception_ptr; using std::current_exception; using std::rethrow_exception; } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_EXCEPTION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/scheduler_operation.hpp
// // detail/scheduler_operation.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP #define BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/system/error_code.hpp> #include <boost/asio/detail/handler_tracking.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class scheduler; // Base class for all operations. A function pointer is used instead of virtual // functions to avoid the associated overhead. class scheduler_operation BOOST_ASIO_INHERIT_TRACKED_HANDLER { public: typedef scheduler_operation operation_type; void complete(void* owner, const boost::system::error_code& ec, std::size_t bytes_transferred) { func_(owner, this, ec, bytes_transferred); } void destroy() { func_(0, this, boost::system::error_code(), 0); } protected: typedef void (*func_type)(void*, scheduler_operation*, const boost::system::error_code&, std::size_t); scheduler_operation(func_type func) : next_(0), func_(func), task_result_(0) { } // Prevents deletion through this type. ~scheduler_operation() { } private: friend class op_queue_access; scheduler_operation* next_; func_type func_; protected: friend class scheduler; unsigned int task_result_; // Passed into bytes transferred. }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_null_buffers_op.hpp
// // detail/reactive_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_REACTIVE_NULL_BUFFERS_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_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> #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/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class reactive_null_buffers_op : public reactor_op { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_null_buffers_op); reactive_null_buffers_op(const boost::system::error_code& success_ec, Handler& handler, const IoExecutor& io_ex) : reactor_op(success_ec, &reactive_null_buffers_op::do_perform, &reactive_null_buffers_op::do_complete), 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& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_null_buffers_op* o(static_cast<reactive_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_)); // 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_null_buffers_op* o(static_cast<reactive_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. immediate_handler_work<Handler, IoExecutor> w( static_cast<handler_work<Handler, IoExecutor>&&>( o->work_)); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. detail::binder2<Handler, 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_NULL_BUFFERS_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_socket_service.hpp
// // detail/null_socket_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_NULL_SOCKET_SERVICE_HPP #define BOOST_ASIO_DETAIL_NULL_SOCKET_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/buffer.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/post.hpp> #include <boost/asio/socket_base.hpp> #include <boost/asio/detail/bind_handler.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol> class null_socket_service : public execution_context_service_base<null_socket_service<Protocol>> { public: // The protocol type. typedef Protocol protocol_type; // The endpoint type. typedef typename Protocol::endpoint endpoint_type; // The native type of a socket. typedef int native_handle_type; // The implementation type of the socket. struct implementation_type { }; // Constructor. null_socket_service(execution_context& context) : execution_context_service_base<null_socket_service<Protocol>>(context) { } // Destroy all user-defined handler objects owned by the service. void shutdown() { } // Construct a new socket implementation. void construct(implementation_type&) { } // Move-construct a new socket implementation. void move_construct(implementation_type&, implementation_type&) { } // Move-assign from another socket implementation. void move_assign(implementation_type&, null_socket_service&, implementation_type&) { } // Move-construct a new socket implementation from another protocol type. template <typename Protocol1> void converting_move_construct(implementation_type&, null_socket_service<Protocol1>&, typename null_socket_service<Protocol1>::implementation_type&) { } // Destroy a socket implementation. void destroy(implementation_type&) { } // Open a new socket implementation. boost::system::error_code open(implementation_type&, const protocol_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Assign a native socket to a socket implementation. boost::system::error_code assign(implementation_type&, const protocol_type&, const native_handle_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Determine whether the socket is open. bool is_open(const implementation_type&) const { return false; } // Destroy a socket implementation. boost::system::error_code close(implementation_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Release ownership of the socket. native_handle_type release(implementation_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Get the native socket representation. native_handle_type native_handle(implementation_type&) { return 0; } // Cancel all operations associated with the socket. boost::system::error_code cancel(implementation_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Determine whether the socket is at the out-of-band data mark. bool at_mark(const implementation_type&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return false; } // Determine the number of bytes available for reading. std::size_t available(const implementation_type&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return 0; } // Place the socket into the state where it will listen for new connections. boost::system::error_code listen(implementation_type&, int, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Perform an IO control command on the socket. template <typename IO_Control_Command> boost::system::error_code io_control(implementation_type&, IO_Control_Command&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Gets the non-blocking mode of the socket. bool non_blocking(const implementation_type&) const { return false; } // Sets the non-blocking mode of the socket. boost::system::error_code non_blocking(implementation_type&, bool, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Gets the non-blocking mode of the native socket implementation. bool native_non_blocking(const implementation_type&) const { return false; } // Sets the non-blocking mode of the native socket implementation. boost::system::error_code native_non_blocking(implementation_type&, bool, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Disable sends or receives on the socket. boost::system::error_code shutdown(implementation_type&, socket_base::shutdown_type, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Bind the socket to the specified local endpoint. boost::system::error_code bind(implementation_type&, const endpoint_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Set a socket option. template <typename Option> boost::system::error_code set_option(implementation_type&, const Option&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Set a socket option. template <typename Option> boost::system::error_code get_option(const implementation_type&, Option&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return ec; } // Get the local endpoint. endpoint_type local_endpoint(const implementation_type&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return endpoint_type(); } // Get the remote endpoint. endpoint_type remote_endpoint(const implementation_type&, boost::system::error_code& ec) const { ec = boost::asio::error::operation_not_supported; return endpoint_type(); } // Send the given data to the peer. template <typename ConstBufferSequence> std::size_t send(implementation_type&, const ConstBufferSequence&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Wait until data can be sent without blocking. std::size_t send(implementation_type&, const null_buffers&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; 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(implementation_type&, const ConstBufferSequence&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Start an asynchronous wait until data can be sent without blocking. template <typename Handler, typename IoExecutor> void async_send(implementation_type&, const null_buffers&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Receive some data from the peer. Returns the number of bytes received. template <typename MutableBufferSequence> std::size_t receive(implementation_type&, const MutableBufferSequence&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Wait until data can be received without blocking. std::size_t receive(implementation_type&, const null_buffers&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; 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(implementation_type&, const MutableBufferSequence&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Wait until data can be received without blocking. template <typename Handler, typename IoExecutor> void async_receive(implementation_type&, const null_buffers&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Receive some data with associated flags. Returns the number of bytes // received. template <typename MutableBufferSequence> std::size_t receive_with_flags(implementation_type&, const MutableBufferSequence&, socket_base::message_flags, socket_base::message_flags&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Wait until data can be received without blocking. std::size_t receive_with_flags(implementation_type&, const null_buffers&, socket_base::message_flags, socket_base::message_flags&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; 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(implementation_type&, const MutableBufferSequence&, socket_base::message_flags, socket_base::message_flags&, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Wait until data can be received without blocking. template <typename Handler, typename IoExecutor> void async_receive_with_flags(implementation_type&, const null_buffers&, socket_base::message_flags, socket_base::message_flags&, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Send a datagram to the specified endpoint. Returns the number of bytes // sent. template <typename ConstBufferSequence> std::size_t send_to(implementation_type&, const ConstBufferSequence&, const endpoint_type&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Wait until data can be sent without blocking. std::size_t send_to(implementation_type&, const null_buffers&, const endpoint_type&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; 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_to(implementation_type&, const ConstBufferSequence&, const endpoint_type&, socket_base::message_flags, Handler& handler) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Start an asynchronous wait until data can be sent without blocking. template <typename Handler, typename IoExecutor> void async_send_to(implementation_type&, const null_buffers&, const endpoint_type&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Receive a datagram with the endpoint of the sender. Returns the number of // bytes received. template <typename MutableBufferSequence> std::size_t receive_from(implementation_type&, const MutableBufferSequence&, endpoint_type&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Wait until data can be received without blocking. std::size_t receive_from(implementation_type&, const null_buffers&, endpoint_type&, socket_base::message_flags, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return 0; } // Start an asynchronous receive. The buffer for the data being received and // the sender_endpoint object must both be valid for the lifetime of the // asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_receive_from(implementation_type&, const MutableBufferSequence&, endpoint_type&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Wait until data can be received without blocking. template <typename Handler, typename IoExecutor> void async_receive_from(implementation_type&, const null_buffers&, endpoint_type&, socket_base::message_flags, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; const std::size_t bytes_transferred = 0; boost::asio::post(io_ex, detail::bind_handler( handler, ec, bytes_transferred)); } // Accept a new connection. template <typename Socket> boost::system::error_code accept(implementation_type&, Socket&, endpoint_type*, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Start an asynchronous accept. The peer and peer_endpoint objects // must be valid until the accept's handler is invoked. template <typename Socket, typename Handler, typename IoExecutor> void async_accept(implementation_type&, Socket&, endpoint_type*, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; boost::asio::post(io_ex, detail::bind_handler(handler, ec)); } // Connect the socket to the specified endpoint. boost::system::error_code connect(implementation_type&, const endpoint_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Start an asynchronous connect. template <typename Handler, typename IoExecutor> void async_connect(implementation_type&, const endpoint_type&, Handler& handler, const IoExecutor& io_ex) { boost::system::error_code ec = boost::asio::error::operation_not_supported; boost::asio::post(io_ex, detail::bind_handler(handler, ec)); } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_NULL_SOCKET_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/mutex.hpp
// // detail/mutex.hpp // ~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_MUTEX_HPP #define BOOST_ASIO_DETAIL_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/null_mutex.hpp> #elif defined(BOOST_ASIO_WINDOWS) # include <boost/asio/detail/win_mutex.hpp> #elif defined(BOOST_ASIO_HAS_PTHREADS) # include <boost/asio/detail/posix_mutex.hpp> #else # include <boost/asio/detail/std_mutex.hpp> #endif namespace boost { namespace asio { namespace detail { #if !defined(BOOST_ASIO_HAS_THREADS) typedef null_mutex mutex; #elif defined(BOOST_ASIO_WINDOWS) typedef win_mutex mutex; #elif defined(BOOST_ASIO_HAS_PTHREADS) typedef posix_mutex mutex; #else typedef std_mutex mutex; #endif } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/descriptor_ops.hpp
// // detail/descriptor_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_DESCRIPTOR_OPS_HPP #define BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_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_RUNTIME) \ && !defined(__CYGWIN__) #include <cstddef> #include <boost/asio/error.hpp> #include <boost/system/error_code.hpp> #include <boost/asio/detail/cstdint.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { namespace descriptor_ops { // Descriptor state bits. enum { // The user wants a non-blocking descriptor. user_set_non_blocking = 1, // The descriptor has been set non-blocking. internal_non_blocking = 2, // Helper "state" used to determine whether the descriptor is non-blocking. non_blocking = user_set_non_blocking | internal_non_blocking, // The descriptor may have been dup()-ed. possible_dup = 4 }; typedef unsigned char state_type; inline void get_last_error( boost::system::error_code& ec, bool is_error_condition) { if (!is_error_condition) { boost::asio::error::clear(ec); } else { ec = boost::system::error_code(errno, boost::asio::error::get_system_category()); } } BOOST_ASIO_DECL int open(const char* path, int flags, boost::system::error_code& ec); BOOST_ASIO_DECL int open(const char* path, int flags, unsigned mode, boost::system::error_code& ec); BOOST_ASIO_DECL int close(int d, state_type& state, boost::system::error_code& ec); BOOST_ASIO_DECL bool set_user_non_blocking(int d, state_type& state, bool value, boost::system::error_code& ec); BOOST_ASIO_DECL bool set_internal_non_blocking(int d, state_type& state, bool value, boost::system::error_code& ec); typedef iovec buf; BOOST_ASIO_DECL std::size_t sync_read(int d, state_type state, buf* bufs, std::size_t count, bool all_empty, boost::system::error_code& ec); BOOST_ASIO_DECL std::size_t sync_read1(int d, state_type state, void* data, std::size_t size, boost::system::error_code& ec); BOOST_ASIO_DECL bool non_blocking_read(int d, buf* bufs, std::size_t count, boost::system::error_code& ec, std::size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_read1(int d, void* data, std::size_t size, boost::system::error_code& ec, std::size_t& bytes_transferred); BOOST_ASIO_DECL std::size_t sync_write(int d, state_type state, const buf* bufs, std::size_t count, bool all_empty, boost::system::error_code& ec); BOOST_ASIO_DECL std::size_t sync_write1(int d, state_type state, const void* data, std::size_t size, boost::system::error_code& ec); BOOST_ASIO_DECL bool non_blocking_write(int d, const buf* bufs, std::size_t count, boost::system::error_code& ec, std::size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_write1(int d, const void* data, std::size_t size, boost::system::error_code& ec, std::size_t& bytes_transferred); #if defined(BOOST_ASIO_HAS_FILE) BOOST_ASIO_DECL std::size_t sync_read_at(int d, state_type state, uint64_t offset, buf* bufs, std::size_t count, bool all_empty, boost::system::error_code& ec); BOOST_ASIO_DECL std::size_t sync_read_at1(int d, state_type state, uint64_t offset, void* data, std::size_t size, boost::system::error_code& ec); BOOST_ASIO_DECL bool non_blocking_read_at(int d, uint64_t offset, buf* bufs, std::size_t count, boost::system::error_code& ec, std::size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_read_at1(int d, uint64_t offset, void* data, std::size_t size, boost::system::error_code& ec, std::size_t& bytes_transferred); BOOST_ASIO_DECL std::size_t sync_write_at(int d, state_type state, uint64_t offset, const buf* bufs, std::size_t count, bool all_empty, boost::system::error_code& ec); BOOST_ASIO_DECL std::size_t sync_write_at1(int d, state_type state, uint64_t offset, const void* data, std::size_t size, boost::system::error_code& ec); BOOST_ASIO_DECL bool non_blocking_write_at(int d, uint64_t offset, const buf* bufs, std::size_t count, boost::system::error_code& ec, std::size_t& bytes_transferred); BOOST_ASIO_DECL bool non_blocking_write_at1(int d, uint64_t offset, const void* data, std::size_t size, boost::system::error_code& ec, std::size_t& bytes_transferred); #endif // defined(BOOST_ASIO_HAS_FILE) BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd, ioctl_arg_type* arg, boost::system::error_code& ec); BOOST_ASIO_DECL int fcntl(int d, int cmd, boost::system::error_code& ec); BOOST_ASIO_DECL int fcntl(int d, int cmd, long arg, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_read(int d, state_type state, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_write(int d, state_type state, boost::system::error_code& ec); BOOST_ASIO_DECL int poll_error(int d, state_type state, boost::system::error_code& ec); } // namespace descriptor_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/descriptor_ops.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // !defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_RUNTIME) // && !defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_OPS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_socket_connect_op.hpp
// // detail/win_iocp_socket_connect_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_CONNECT_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_CONNECT_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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 { class win_iocp_socket_connect_op_base : public reactor_op { public: win_iocp_socket_connect_op_base(socket_type socket, func_type complete_func) : reactor_op(boost::system::error_code(), &win_iocp_socket_connect_op_base::do_perform, complete_func), socket_(socket), connect_ex_(false) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); win_iocp_socket_connect_op_base* o( static_cast<win_iocp_socket_connect_op_base*>(base)); return socket_ops::non_blocking_connect( o->socket_, o->ec_) ? done : not_done; } socket_type socket_; bool connect_ex_; }; template <typename Handler, typename IoExecutor> class win_iocp_socket_connect_op : public win_iocp_socket_connect_op_base { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_connect_op); win_iocp_socket_connect_op(socket_type socket, Handler& handler, const IoExecutor& io_ex) : win_iocp_socket_connect_op_base(socket, &win_iocp_socket_connect_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const 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_connect_op* o( static_cast<win_iocp_socket_connect_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; if (owner) { if (o->connect_ex_) socket_ops::complete_iocp_connect(o->socket_, ec); else ec = o->ec_; } 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: 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_CONNECT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_recvfrom_op.hpp
// // detail/io_uring_socket_recvfrom_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECVFROM_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECVFROM_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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, typename Endpoint> class io_uring_socket_recvfrom_op_base : public io_uring_operation { public: io_uring_socket_recvfrom_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const MutableBufferSequence& buffers, Endpoint& endpoint, socket_base::message_flags flags, func_type complete_func) : io_uring_operation(success_ec, &io_uring_socket_recvfrom_op_base::do_prepare, &io_uring_socket_recvfrom_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), sender_endpoint_(endpoint), flags_(flags), bufs_(buffers), msghdr_() { msghdr_.msg_iov = bufs_.buffers(); msghdr_.msg_iovlen = static_cast<int>(bufs_.count()); msghdr_.msg_name = static_cast<sockaddr*>( static_cast<void*>(sender_endpoint_.data())); msghdr_.msg_namelen = sender_endpoint_.capacity(); } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recvfrom_op_base* o( static_cast<io_uring_socket_recvfrom_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0; ::io_uring_prep_poll_add(sqe, o->socket_, except_op ? POLLPRI : POLLIN); } else { ::io_uring_prep_recvmsg(sqe, o->socket_, &o->msghdr_, o->flags_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recvfrom_op_base* o( static_cast<io_uring_socket_recvfrom_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0; if (after_completion || !except_op) { std::size_t addr_len = o->sender_endpoint_.capacity(); bool result; if (o->bufs_.is_single_buffer) { result = socket_ops::non_blocking_recvfrom1(o->socket_, o->bufs_.first(o->buffers_).data(), o->bufs_.first(o->buffers_).size(), o->flags_, o->sender_endpoint_.data(), &addr_len, o->ec_, o->bytes_transferred_); } else { result = socket_ops::non_blocking_recvfrom(o->socket_, o->bufs_.buffers(), o->bufs_.count(), o->flags_, o->sender_endpoint_.data(), &addr_len, o->ec_, o->bytes_transferred_); } if (result && !o->ec_) o->sender_endpoint_.resize(addr_len); } } else if (after_completion && !o->ec_) o->sender_endpoint_.resize(o->msghdr_.msg_namelen); if (o->ec_ && o->ec_ == 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_; Endpoint& sender_endpoint_; socket_base::message_flags flags_; buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_; msghdr msghdr_; }; template <typename MutableBufferSequence, typename Endpoint, typename Handler, typename IoExecutor> class io_uring_socket_recvfrom_op : public io_uring_socket_recvfrom_op_base<MutableBufferSequence, Endpoint> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_recvfrom_op); io_uring_socket_recvfrom_op(const boost::system::error_code& success_ec, int socket, socket_ops::state_type state, const MutableBufferSequence& buffers, Endpoint& endpoint, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : io_uring_socket_recvfrom_op_base<MutableBufferSequence, Endpoint>( success_ec, socket, state, buffers, endpoint, flags, &io_uring_socket_recvfrom_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recvfrom_op* o (static_cast<io_uring_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; } } 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_RECVFROM_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/conditionally_enabled_event.hpp
// // detail/conditionally_enabled_event.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_HPP #define BOOST_ASIO_DETAIL_CONDITIONALLY_ENABLED_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 <boost/asio/detail/conditionally_enabled_mutex.hpp> #include <boost/asio/detail/event.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/null_event.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_event : private noncopyable { public: // Constructor. conditionally_enabled_event() { } // Destructor. ~conditionally_enabled_event() { } // Signal the event. (Retained for backward compatibility.) void signal(conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) event_.signal(lock); } // Signal all waiters. void signal_all(conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) event_.signal_all(lock); } // Unlock the mutex and signal one waiter. void unlock_and_signal_one( conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) event_.unlock_and_signal_one(lock); } // Unlock the mutex and signal one waiter who may destroy us. void unlock_and_signal_one_for_destruction( conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) event_.unlock_and_signal_one(lock); } // If there's a waiter, unlock the mutex and signal it. bool maybe_unlock_and_signal_one( conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) return event_.maybe_unlock_and_signal_one(lock); else return false; } // Reset the event. void clear(conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) event_.clear(lock); } // Wait for the event to become signalled. void wait(conditionally_enabled_mutex::scoped_lock& lock) { if (lock.mutex_.enabled_) event_.wait(lock); else null_event().wait(lock); } // Timed wait for the event to become signalled. bool wait_for_usec( conditionally_enabled_mutex::scoped_lock& lock, long usec) { if (lock.mutex_.enabled_) return event_.wait_for_usec(lock, usec); else return null_event().wait_for_usec(lock, usec); } private: boost::asio::detail::event event_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_CONDITIONALLY_ENABLED_EVENT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_service.hpp
// // detail/io_uring_socket_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_SOCKET_SERVICE_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_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_IO_URING) #include <boost/asio/buffer.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/noncopyable.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_accept_op.hpp> #include <boost/asio/detail/io_uring_socket_connect_op.hpp> #include <boost/asio/detail/io_uring_socket_recvfrom_op.hpp> #include <boost/asio/detail/io_uring_socket_sendto_op.hpp> #include <boost/asio/detail/io_uring_socket_service_base.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 { template <typename Protocol> class io_uring_socket_service : public execution_context_service_base<io_uring_socket_service<Protocol>>, public io_uring_socket_service_base { public: // The protocol type. typedef Protocol protocol_type; // The endpoint type. typedef typename Protocol::endpoint endpoint_type; // The native type of a socket. typedef socket_type native_handle_type; // The implementation type of the socket. struct implementation_type : io_uring_socket_service_base::base_implementation_type { // Default constructor. implementation_type() : protocol_(endpoint_type().protocol()) { } // The protocol associated with the socket. protocol_type protocol_; }; // Constructor. io_uring_socket_service(execution_context& context) : execution_context_service_base< io_uring_socket_service<Protocol>>(context), io_uring_socket_service_base(context) { } // Destroy all user-defined handler objects owned by the service. void shutdown() { this->base_shutdown(); } // Move-construct a new socket implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) noexcept { this->base_move_construct(impl, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); } // Move-assign from another socket implementation. void move_assign(implementation_type& impl, io_uring_socket_service_base& other_service, implementation_type& other_impl) { this->base_move_assign(impl, other_service, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); } // Move-construct a new socket implementation from another protocol type. template <typename Protocol1> void converting_move_construct(implementation_type& impl, io_uring_socket_service<Protocol1>&, typename io_uring_socket_service< Protocol1>::implementation_type& other_impl) { this->base_move_construct(impl, other_impl); impl.protocol_ = protocol_type(other_impl.protocol_); other_impl.protocol_ = typename Protocol1::endpoint().protocol(); } // Open a new socket implementation. boost::system::error_code open(implementation_type& impl, const protocol_type& protocol, boost::system::error_code& ec) { if (!do_open(impl, protocol.family(), protocol.type(), protocol.protocol(), ec)) impl.protocol_ = protocol; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Assign a native socket to a socket implementation. boost::system::error_code assign(implementation_type& impl, const protocol_type& protocol, const native_handle_type& native_socket, boost::system::error_code& ec) { if (!do_assign(impl, protocol.type(), native_socket, ec)) impl.protocol_ = protocol; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Get the native socket representation. native_handle_type native_handle(implementation_type& impl) { return impl.socket_; } // Bind the socket to the specified local endpoint. boost::system::error_code bind(implementation_type& impl, const endpoint_type& endpoint, boost::system::error_code& ec) { socket_ops::bind(impl.socket_, endpoint.data(), endpoint.size(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Set a socket option. template <typename Option> boost::system::error_code set_option(implementation_type& impl, const Option& option, boost::system::error_code& ec) { socket_ops::setsockopt(impl.socket_, impl.state_, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), option.size(impl.protocol_), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Set a socket option. template <typename Option> boost::system::error_code get_option(const implementation_type& impl, Option& option, boost::system::error_code& ec) const { std::size_t size = option.size(impl.protocol_); socket_ops::getsockopt(impl.socket_, impl.state_, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), &size, ec); if (!ec) option.resize(impl.protocol_, size); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Get the local endpoint. endpoint_type local_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; std::size_t addr_len = endpoint.capacity(); if (socket_ops::getsockname(impl.socket_, endpoint.data(), &addr_len, ec)) { BOOST_ASIO_ERROR_LOCATION(ec); return endpoint_type(); } endpoint.resize(addr_len); return endpoint; } // Get the remote endpoint. endpoint_type remote_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; std::size_t addr_len = endpoint.capacity(); if (socket_ops::getpeername(impl.socket_, endpoint.data(), &addr_len, false, ec)) { BOOST_ASIO_ERROR_LOCATION(ec); return endpoint_type(); } endpoint.resize(addr_len); return endpoint; } // Disable sends or receives on the socket. boost::system::error_code shutdown(base_implementation_type& impl, socket_base::shutdown_type what, boost::system::error_code& ec) { socket_ops::shutdown(impl.socket_, what, ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Send a datagram to the specified endpoint. Returns the number of bytes // sent. template <typename ConstBufferSequence> size_t send_to(implementation_type& impl, const ConstBufferSequence& buffers, const endpoint_type& destination, socket_base::message_flags flags, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_type; size_t n; if (bufs_type::is_single_buffer) { n = socket_ops::sync_sendto1(impl.socket_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), flags, destination.data(), destination.size(), ec); } else { bufs_type bufs(buffers); n = socket_ops::sync_sendto(impl.socket_, impl.state_, bufs.buffers(), bufs.count(), flags, destination.data(), destination.size(), ec); } BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be sent without blocking. size_t send_to(implementation_type& impl, const null_buffers&, const endpoint_type&, 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); BOOST_ASIO_ERROR_LOCATION(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_to(implementation_type& impl, const ConstBufferSequence& buffers, const endpoint_type& destination, 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_sendto_op<ConstBufferSequence, endpoint_type, 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, destination, 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_to")); start_op(impl, io_uring_service::write_op, p.p, is_continuation, false); p.v = p.p = 0; } // Start an asynchronous wait until data can be sent without blocking. template <typename Handler, typename IoExecutor> void async_send_to(implementation_type& impl, const null_buffers&, const endpoint_type&, 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_to(null_buffers)")); start_op(impl, io_uring_service::write_op, p.p, is_continuation, false); p.v = p.p = 0; } // Receive a datagram with the endpoint of the sender. Returns the number of // bytes received. template <typename MutableBufferSequence> size_t receive_from(implementation_type& impl, const MutableBufferSequence& buffers, endpoint_type& sender_endpoint, socket_base::message_flags flags, boost::system::error_code& ec) { typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; std::size_t addr_len = sender_endpoint.capacity(); std::size_t n; if (bufs_type::is_single_buffer) { n = socket_ops::sync_recvfrom1(impl.socket_, impl.state_, bufs_type::first(buffers).data(), bufs_type::first(buffers).size(), flags, sender_endpoint.data(), &addr_len, ec); } else { bufs_type bufs(buffers); n = socket_ops::sync_recvfrom(impl.socket_, impl.state_, bufs.buffers(), bufs.count(), flags, sender_endpoint.data(), &addr_len, ec); } if (!ec) sender_endpoint.resize(addr_len); BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be received without blocking. size_t receive_from(implementation_type& impl, const null_buffers&, endpoint_type& sender_endpoint, 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); // Reset endpoint since it can be given no sensible value at this time. sender_endpoint = endpoint_type(); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous receive. The buffer for the data being received and // the sender_endpoint object must both be valid for the lifetime of the // asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_receive_from(implementation_type& impl, const MutableBufferSequence& buffers, endpoint_type& sender_endpoint, 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_recvfrom_op<MutableBufferSequence, endpoint_type, 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, sender_endpoint, 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_from")); 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_from(implementation_type& impl, const null_buffers&, endpoint_type& sender_endpoint, 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_from(null_buffers)")); // Reset endpoint since it can be given no sensible value at this time. sender_endpoint = endpoint_type(); start_op(impl, op_type, p.p, is_continuation, false); p.v = p.p = 0; } // Accept a new connection. template <typename Socket> boost::system::error_code accept(implementation_type& impl, Socket& peer, endpoint_type* peer_endpoint, boost::system::error_code& ec) { // We cannot accept a socket that is already open. if (peer.is_open()) { ec = boost::asio::error::already_open; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } std::size_t addr_len = peer_endpoint ? peer_endpoint->capacity() : 0; socket_holder new_socket(socket_ops::sync_accept(impl.socket_, impl.state_, peer_endpoint ? peer_endpoint->data() : 0, peer_endpoint ? &addr_len : 0, ec)); // On success, assign new connection to peer socket object. if (new_socket.get() != invalid_socket) { if (peer_endpoint) peer_endpoint->resize(addr_len); peer.assign(impl.protocol_, new_socket.get(), ec); if (!ec) new_socket.release(); } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Start an asynchronous accept. The peer and peer_endpoint objects must be // valid until the accept's handler is invoked. template <typename Socket, typename Handler, typename IoExecutor> void async_accept(implementation_type& impl, Socket& peer, endpoint_type* peer_endpoint, 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_accept_op<Socket, Protocol, 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_, peer, impl.protocol_, peer_endpoint, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected() && !peer.is_open()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::read_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "socket", &impl, impl.socket_, "async_accept")); start_accept_op(impl, p.p, is_continuation, peer.is_open()); p.v = p.p = 0; } // Start an asynchronous accept. The peer_endpoint object must be valid until // the accept's handler is invoked. template <typename PeerIoExecutor, typename Handler, typename IoExecutor> void async_move_accept(implementation_type& impl, const PeerIoExecutor& peer_io_ex, endpoint_type* peer_endpoint, 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_move_accept_op<Protocol, PeerIoExecutor, 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_, peer_io_ex, impl.socket_, impl.state_, impl.protocol_, peer_endpoint, handler, io_ex); // Optionally register for per-operation cancellation. if (slot.is_connected()) { p.p->cancellation_key_ = &slot.template emplace<io_uring_op_cancellation>(&io_uring_service_, &impl.io_object_data_, io_uring_service::read_op); } BOOST_ASIO_HANDLER_CREATION((io_uring_service_.context(), *p.p, "socket", &impl, impl.socket_, "async_accept")); start_accept_op(impl, p.p, is_continuation, false); p.v = p.p = 0; } // Connect the socket to the specified endpoint. boost::system::error_code connect(implementation_type& impl, const endpoint_type& peer_endpoint, boost::system::error_code& ec) { socket_ops::sync_connect(impl.socket_, peer_endpoint.data(), peer_endpoint.size(), ec); return ec; } // Start an asynchronous connect. template <typename Handler, typename IoExecutor> void async_connect(implementation_type& impl, const endpoint_type& peer_endpoint, 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_connect_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(success_ec_, impl.socket_, peer_endpoint, 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_connect")); start_op(impl, io_uring_service::write_op, p.p, is_continuation, false); p.v = p.p = 0; } }; } // 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_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/socket_holder.hpp
// // detail/socket_holder.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_HOLDER_HPP #define BOOST_ASIO_DETAIL_SOCKET_HOLDER_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/socket_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Implement the resource acquisition is initialisation idiom for sockets. class socket_holder : private noncopyable { public: // Construct as an uninitialised socket. socket_holder() : socket_(invalid_socket) { } // Construct to take ownership of the specified socket. explicit socket_holder(socket_type s) : socket_(s) { } // Destructor. ~socket_holder() { if (socket_ != invalid_socket) { boost::system::error_code ec; socket_ops::state_type state = 0; socket_ops::close(socket_, state, true, ec); } } // Get the underlying socket. socket_type get() const { return socket_; } // Reset to an uninitialised socket. void reset() { if (socket_ != invalid_socket) { boost::system::error_code ec; socket_ops::state_type state = 0; socket_ops::close(socket_, state, true, ec); socket_ = invalid_socket; } } // Reset to take ownership of the specified socket. void reset(socket_type s) { reset(); socket_ = s; } // Release ownership of the socket. socket_type release() { socket_type tmp = socket_; socket_ = invalid_socket; return tmp; } private: // The underlying socket. socket_type socket_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SOCKET_HOLDER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_descriptor_read_op.hpp
// // detail/io_uring_descriptor_read_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_READ_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_READ_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 MutableBufferSequence> class io_uring_descriptor_read_op_base : public io_uring_operation { public: io_uring_descriptor_read_op_base(const boost::system::error_code& success_ec, int descriptor, descriptor_ops::state_type state, const MutableBufferSequence& buffers, func_type complete_func) : io_uring_operation(success_ec, &io_uring_descriptor_read_op_base::do_prepare, &io_uring_descriptor_read_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_read_op_base* o( static_cast<io_uring_descriptor_read_op_base*>(base)); if ((o->state_ & descriptor_ops::internal_non_blocking) != 0) { ::io_uring_prep_poll_add(sqe, o->descriptor_, POLLIN); } else if (o->bufs_.is_single_buffer && o->bufs_.is_registered_buffer) { ::io_uring_prep_read_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_readv(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_read_op_base* o( static_cast<io_uring_descriptor_read_op_base*>(base)); if ((o->state_ & descriptor_ops::internal_non_blocking) != 0) { if (o->bufs_.is_single_buffer) { return descriptor_ops::non_blocking_read1( 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_read( o->descriptor_, o->bufs_.buffers(), o->bufs_.count(), o->ec_, o->bytes_transferred_); } } else if (after_completion) { if (!o->ec_ && o->bytes_transferred_ == 0) o->ec_ = boost::asio::error::eof; } 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_; MutableBufferSequence buffers_; buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class io_uring_descriptor_read_op : public io_uring_descriptor_read_op_base<MutableBufferSequence> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_descriptor_read_op); io_uring_descriptor_read_op(const boost::system::error_code& success_ec, int descriptor, descriptor_ops::state_type state, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : io_uring_descriptor_read_op_base<MutableBufferSequence>(success_ec, descriptor, state, buffers, &io_uring_descriptor_read_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_read_op* o (static_cast<io_uring_descriptor_read_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_READ_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/descriptor_read_op.hpp
// // detail/descriptor_read_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_DESCRIPTOR_READ_OP_HPP #define BOOST_ASIO_DETAIL_DESCRIPTOR_READ_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) && !defined(__CYGWIN__) #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/memory.hpp> #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence> class descriptor_read_op_base : public reactor_op { public: descriptor_read_op_base(const boost::system::error_code& success_ec, int descriptor, const MutableBufferSequence& buffers, func_type complete_func) : reactor_op(success_ec, &descriptor_read_op_base::do_perform, complete_func), descriptor_(descriptor), buffers_(buffers) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); descriptor_read_op_base* o(static_cast<descriptor_read_op_base*>(base)); typedef buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_type; status result; if (bufs_type::is_single_buffer) { result = descriptor_ops::non_blocking_read1(o->descriptor_, bufs_type::first(o->buffers_).data(), bufs_type::first(o->buffers_).size(), o->ec_, o->bytes_transferred_) ? done : not_done; } else { bufs_type bufs(o->buffers_); result = descriptor_ops::non_blocking_read(o->descriptor_, bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_) ? done : not_done; } BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_read", o->ec_, o->bytes_transferred_)); return result; } private: int descriptor_; MutableBufferSequence buffers_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class descriptor_read_op : public descriptor_read_op_base<MutableBufferSequence> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(descriptor_read_op); descriptor_read_op(const boost::system::error_code& success_ec, int descriptor, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : descriptor_read_op_base<MutableBufferSequence>(success_ec, descriptor, buffers, &descriptor_read_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); descriptor_read_op* o(static_cast<descriptor_read_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); descriptor_read_op* o(static_cast<descriptor_read_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 // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_DESCRIPTOR_READ_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/std_global.hpp
// // detail/std_global.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_STD_GLOBAL_HPP #define BOOST_ASIO_DETAIL_STD_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 <exception> #include <mutex> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T> struct std_global_impl { // Helper function to perform initialisation. static void do_init() { instance_.ptr_ = new T; } // Destructor automatically cleans up the global. ~std_global_impl() { delete ptr_; } static std::once_flag init_once_; static std_global_impl instance_; T* ptr_; }; template <typename T> std::once_flag std_global_impl<T>::init_once_; template <typename T> std_global_impl<T> std_global_impl<T>::instance_; template <typename T> T& std_global() { std::call_once(std_global_impl<T>::init_once_, &std_global_impl<T>::do_init); return *std_global_impl<T>::instance_.ptr_; } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_STD_GLOBAL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_socket_recvfrom_op.hpp
// // detail/win_iocp_socket_recvfrom_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence, typename Endpoint, typename Handler, typename IoExecutor> class win_iocp_socket_recvfrom_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recvfrom_op); win_iocp_socket_recvfrom_op(Endpoint& endpoint, socket_ops::weak_cancel_token_type cancel_token, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_socket_recvfrom_op::do_complete), endpoint_(endpoint), endpoint_size_(static_cast<int>(endpoint.capacity())), cancel_token_(cancel_token), buffers_(buffers), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } int& endpoint_size() { return endpoint_size_; } static void do_complete(void* owner, operation* base, const 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_recvfrom_op* o( static_cast<win_iocp_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_)); #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_recvfrom(o->cancel_token_, ec); // Record the size of the endpoint returned by the operation. o->endpoint_.resize(o->endpoint_size_); 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: Endpoint& endpoint_; int endpoint_size_; socket_ops::weak_cancel_token_type cancel_token_; MutableBufferSequence buffers_; Handler handler_; handler_work<Handler, IoExecutor> work_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/base_from_cancellation_state.hpp
// // detail/base_from_cancellation_state.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_BASE_FROM_CANCELLATION_STATE_HPP #define BOOST_ASIO_DETAIL_BASE_FROM_CANCELLATION_STATE_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_cancellation_slot.hpp> #include <boost/asio/cancellation_state.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename = void> class base_from_cancellation_state { public: typedef cancellation_slot cancellation_slot_type; cancellation_slot_type get_cancellation_slot() const noexcept { return cancellation_state_.slot(); } cancellation_state get_cancellation_state() const noexcept { return cancellation_state_; } protected: explicit base_from_cancellation_state(const Handler& handler) : cancellation_state_( boost::asio::get_associated_cancellation_slot(handler)) { } template <typename Filter> base_from_cancellation_state(const Handler& handler, Filter filter) : cancellation_state_( boost::asio::get_associated_cancellation_slot(handler), filter, filter) { } template <typename InFilter, typename OutFilter> base_from_cancellation_state(const Handler& handler, InFilter&& in_filter, OutFilter&& out_filter) : cancellation_state_( boost::asio::get_associated_cancellation_slot(handler), static_cast<InFilter&&>(in_filter), static_cast<OutFilter&&>(out_filter)) { } void reset_cancellation_state(const Handler& handler) { cancellation_state_ = cancellation_state( boost::asio::get_associated_cancellation_slot(handler)); } template <typename Filter> void reset_cancellation_state(const Handler& handler, Filter filter) { cancellation_state_ = cancellation_state( boost::asio::get_associated_cancellation_slot(handler), filter, filter); } template <typename InFilter, typename OutFilter> void reset_cancellation_state(const Handler& handler, InFilter&& in_filter, OutFilter&& out_filter) { cancellation_state_ = cancellation_state( boost::asio::get_associated_cancellation_slot(handler), static_cast<InFilter&&>(in_filter), static_cast<OutFilter&&>(out_filter)); } cancellation_type_t cancelled() const noexcept { return cancellation_state_.cancelled(); } private: cancellation_state cancellation_state_; }; template <typename Handler> class base_from_cancellation_state<Handler, enable_if_t< is_same< typename associated_cancellation_slot< Handler, cancellation_slot >::asio_associated_cancellation_slot_is_unspecialised, void >::value > > { public: cancellation_state get_cancellation_state() const noexcept { return cancellation_state(); } protected: explicit base_from_cancellation_state(const Handler&) { } template <typename Filter> base_from_cancellation_state(const Handler&, Filter) { } template <typename InFilter, typename OutFilter> base_from_cancellation_state(const Handler&, InFilter&&, OutFilter&&) { } void reset_cancellation_state(const Handler&) { } template <typename Filter> void reset_cancellation_state(const Handler&, Filter) { } template <typename InFilter, typename OutFilter> void reset_cancellation_state(const Handler&, InFilter&&, OutFilter&&) { } constexpr cancellation_type_t cancelled() const noexcept { return cancellation_type::none; } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_BASE_FROM_CANCELLATION_STATE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/wait_op.hpp
// // detail/wait_op.hpp // ~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WAIT_OP_HPP #define BOOST_ASIO_DETAIL_WAIT_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 wait_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_; protected: wait_op(func_type func) : operation(func), cancellation_key_(0) { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_WAIT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/resolver_service_base.hpp
// // detail/resolver_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_RESOLVER_SERVICE_BASE_HPP #define BOOST_ASIO_DETAIL_RESOLVER_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> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/resolve_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/scoped_ptr.hpp> #include <boost/asio/detail/thread.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 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; // Constructor. BOOST_ASIO_DECL resolver_service_base(execution_context& context); // Destructor. BOOST_ASIO_DECL ~resolver_service_base(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void base_shutdown(); // Perform any fork-related housekeeping. BOOST_ASIO_DECL void base_notify_fork( execution_context::fork_event fork_ev); // Construct a new resolver implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Destroy a resolver implementation. BOOST_ASIO_DECL void destroy(implementation_type&); // Move-construct a new resolver implementation. BOOST_ASIO_DECL void move_construct(implementation_type& impl, implementation_type& other_impl); // Move-assign from another resolver implementation. BOOST_ASIO_DECL void move_assign(implementation_type& impl, resolver_service_base& other_service, implementation_type& other_impl); // Move-construct a new timer implementation. void converting_move_construct(implementation_type& impl, resolver_service_base&, implementation_type& other_impl) { move_construct(impl, other_impl); } // Move-assign from another timer implementation. void converting_move_assign(implementation_type& impl, resolver_service_base& other_service, implementation_type& other_impl) { move_assign(impl, other_service, other_impl); } // Cancel pending asynchronous operations. BOOST_ASIO_DECL void cancel(implementation_type& impl); protected: // Helper function to start an asynchronous resolve operation. BOOST_ASIO_DECL void start_resolve_op(resolve_op* op); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) // Helper class to perform exception-safe cleanup of addrinfo objects. class auto_addrinfo : private boost::asio::detail::noncopyable { public: explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai) : ai_(ai) { } ~auto_addrinfo() { if (ai_) socket_ops::freeaddrinfo(ai_); } operator boost::asio::detail::addrinfo_type*() { return ai_; } private: boost::asio::detail::addrinfo_type* ai_; }; #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) // Helper class to run the work scheduler in a thread. class work_scheduler_runner; // Start the work scheduler if it's not already running. BOOST_ASIO_DECL void start_work_thread(); // 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_; private: // Mutex to protect access to internal data. boost::asio::detail::mutex mutex_; // Private scheduler used for performing asynchronous host resolution. boost::asio::detail::scoped_ptr<scheduler_impl> work_scheduler_; // Thread used for running the work io_context's run loop. boost::asio::detail::scoped_ptr<boost::asio::detail::thread> work_thread_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/resolver_service_base.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_fenced_block.hpp
// // detail/null_fenced_block.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_NULL_FENCED_BLOCK_HPP #define BOOST_ASIO_DETAIL_NULL_FENCED_BLOCK_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 { class null_fenced_block : private noncopyable { public: enum half_or_full_t { half, full }; // Constructor. explicit null_fenced_block(half_or_full_t) { } // Destructor. ~null_fenced_block() { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_NULL_FENCED_BLOCK_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/wince_thread.hpp
// // detail/wince_thread.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WINCE_THREAD_HPP #define BOOST_ASIO_DETAIL_WINCE_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(UNDER_CE) #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 wince_thread_function(LPVOID arg); class wince_thread : private noncopyable { public: // Constructor. template <typename Function> wince_thread(Function f, unsigned int = 0) { scoped_ptr<func_base> arg(new func<Function>(f)); DWORD thread_id = 0; thread_ = ::CreateThread(0, 0, wince_thread_function, arg.get(), 0, &thread_id); if (!thread_) { DWORD last_error = ::GetLastError(); boost::system::error_code ec(last_error, boost::asio::error::get_system_category()); boost::asio::detail::throw_error(ec, "thread"); } arg.release(); } // Destructor. ~wince_thread() { ::CloseHandle(thread_); } // Wait for the thread to exit. void join() { ::WaitForSingleObject(thread_, INFINITE); } // Get number of CPUs. static std::size_t hardware_concurrency() { SYSTEM_INFO system_info; ::GetSystemInfo(&system_info); return system_info.dwNumberOfProcessors; } private: friend DWORD WINAPI wince_thread_function(LPVOID arg); class func_base { public: virtual ~func_base() {} virtual void run() = 0; }; template <typename Function> class func : public func_base { public: func(Function f) : f_(f) { } virtual void run() { f_(); } private: Function f_; }; ::HANDLE thread_; }; inline DWORD WINAPI wince_thread_function(LPVOID arg) { scoped_ptr<wince_thread::func_base> func( static_cast<wince_thread::func_base*>(arg)); func->run(); return 0; } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) #endif // BOOST_ASIO_DETAIL_WINCE_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/scheduler_task.hpp
// // detail/scheduler_task.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_SCHEDULER_TASK_HPP #define BOOST_ASIO_DETAIL_SCHEDULER_TASK_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class scheduler_operation; // Base class for all tasks that may be run by a scheduler. class scheduler_task { public: // Run the task once until interrupted or events are ready to be dispatched. virtual void run(long usec, op_queue<scheduler_operation>& ops) = 0; // Interrupt the task. virtual void interrupt() = 0; protected: // Prevent deletion through this type. ~scheduler_task() { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SCHEDULER_TASK_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/null_event.hpp
// // detail/null_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_NULL_EVENT_HPP #define BOOST_ASIO_DETAIL_NULL_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 <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class null_event : private noncopyable { public: // Constructor. null_event() { } // Destructor. ~null_event() { } // Signal the event. (Retained for backward compatibility.) template <typename Lock> void signal(Lock&) { } // Signal all waiters. template <typename Lock> void signal_all(Lock&) { } // Unlock the mutex and signal one waiter. template <typename Lock> void unlock_and_signal_one(Lock&) { } // Unlock the mutex and signal one waiter who may destroy us. template <typename Lock> void unlock_and_signal_one_for_destruction(Lock&) { } // If there's a waiter, unlock the mutex and signal it. template <typename Lock> bool maybe_unlock_and_signal_one(Lock&) { return false; } // Reset the event. template <typename Lock> void clear(Lock&) { } // Wait for the event to become signalled. template <typename Lock> void wait(Lock&) { do_wait(); } // Timed wait for the event to become signalled. template <typename Lock> bool wait_for_usec(Lock&, long usec) { do_wait_for_usec(usec); return true; } private: BOOST_ASIO_DECL static void do_wait(); BOOST_ASIO_DECL static void do_wait_for_usec(long usec); }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/null_event.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_NULL_EVENT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/scheduler.hpp
// // detail/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_SCHEDULER_HPP #define BOOST_ASIO_DETAIL_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/system/error_code.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/atomic_count.hpp> #include <boost/asio/detail/conditionally_enabled_event.hpp> #include <boost/asio/detail/conditionally_enabled_mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/scheduler_operation.hpp> #include <boost/asio/detail/scheduler_task.hpp> #include <boost/asio/detail/thread.hpp> #include <boost/asio/detail/thread_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct scheduler_thread_info; class scheduler : public execution_context_service_base<scheduler>, public thread_context { public: typedef scheduler_operation operation; // The type of a function used to obtain a task instance. typedef scheduler_task* (*get_task_func_type)( boost::asio::execution_context&); // Constructor. Specifies the number of concurrent threads that are likely to // run the scheduler. If set to 1 certain optimisation are performed. BOOST_ASIO_DECL scheduler(boost::asio::execution_context& ctx, int concurrency_hint = 0, bool own_thread = true, get_task_func_type get_task = &scheduler::get_default_task); // Destructor. BOOST_ASIO_DECL ~scheduler(); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Initialise the task, if required. BOOST_ASIO_DECL void init_task(); // Run the event loop until interrupted or no more work. BOOST_ASIO_DECL std::size_t run(boost::system::error_code& ec); // Run until interrupted or one operation is performed. BOOST_ASIO_DECL std::size_t run_one(boost::system::error_code& ec); // Run until timeout, interrupted, or one operation is performed. BOOST_ASIO_DECL std::size_t wait_one( long usec, boost::system::error_code& ec); // Poll for operations without blocking. BOOST_ASIO_DECL std::size_t poll(boost::system::error_code& ec); // Poll for one operation without blocking. BOOST_ASIO_DECL std::size_t poll_one(boost::system::error_code& ec); // Interrupt the event processing loop. BOOST_ASIO_DECL void stop(); // Determine whether the scheduler is stopped. BOOST_ASIO_DECL bool stopped() const; // Restart in preparation for a subsequent run invocation. BOOST_ASIO_DECL void restart(); // Notify that some work has started. void work_started() { ++outstanding_work_; } // Used to compensate for a forthcoming work_finished call. Must be called // from within a scheduler-owned thread. BOOST_ASIO_DECL void compensating_work_started(); // Notify that some work has finished. void work_finished() { if (--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. BOOST_ASIO_DECL void post_immediate_completion( operation* op, bool is_continuation); // Request invocation of the given operations and return immediately. Assumes // that work_started() has not yet been called for the operations. BOOST_ASIO_DECL void post_immediate_completions(std::size_t n, op_queue<operation>& ops, bool is_continuation); // 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(operation* op); // Request invocation of the given operations and return immediately. Assumes // that work_started() was previously called for each operation. BOOST_ASIO_DECL void post_deferred_completions(op_queue<operation>& ops); // Enqueue the given operation following a failed attempt to dispatch the // operation for immediate invocation. BOOST_ASIO_DECL void do_dispatch(operation* op); // Process unfinished operations as part of a shutdownoperation. Assumes that // work_started() was previously called for the operations. BOOST_ASIO_DECL void abandon_operations(op_queue<operation>& ops); // Get the concurrency hint that was used to initialise the scheduler. int concurrency_hint() const { return concurrency_hint_; } private: // The mutex type used by this scheduler. typedef conditionally_enabled_mutex mutex; // The event type used by this scheduler. typedef conditionally_enabled_event event; // Structure containing thread-specific data. typedef scheduler_thread_info thread_info; // Run at most one operation. May block. BOOST_ASIO_DECL std::size_t do_run_one(mutex::scoped_lock& lock, thread_info& this_thread, const boost::system::error_code& ec); // Run at most one operation with a timeout. May block. BOOST_ASIO_DECL std::size_t do_wait_one(mutex::scoped_lock& lock, thread_info& this_thread, long usec, const boost::system::error_code& ec); // Poll for at most one operation. BOOST_ASIO_DECL std::size_t do_poll_one(mutex::scoped_lock& lock, thread_info& this_thread, const boost::system::error_code& ec); // Stop the task and all idle threads. BOOST_ASIO_DECL void stop_all_threads(mutex::scoped_lock& lock); // Wake a single idle thread, or the task, and always unlock the mutex. BOOST_ASIO_DECL void wake_one_thread_and_unlock( mutex::scoped_lock& lock); // Get the default task. BOOST_ASIO_DECL static scheduler_task* get_default_task( boost::asio::execution_context& ctx); // Helper class to run the scheduler in its own thread. class thread_function; friend class thread_function; // Helper class to perform task-related operations on block exit. struct task_cleanup; friend struct task_cleanup; // Helper class to call work-related operations on block exit. struct work_cleanup; friend struct work_cleanup; // Whether to optimise for single-threaded use cases. const bool one_thread_; // Mutex to protect access to internal data. mutable mutex mutex_; // Event to wake up blocked threads. event wakeup_event_; // The task to be run by this service. scheduler_task* task_; // The function used to get the task. get_task_func_type get_task_; // Operation object to represent the position of the task in the queue. struct task_operation : operation { task_operation() : operation(0) {} } task_operation_; // Whether the task has been interrupted. bool task_interrupted_; // The count of unfinished work. atomic_count outstanding_work_; // The queue of handlers that are ready to be delivered. op_queue<operation> op_queue_; // Flag to indicate that the dispatcher has been stopped. bool stopped_; // Flag to indicate that the dispatcher has been shut down. bool shutdown_; // The concurrency hint used to initialise the scheduler. const int concurrency_hint_; // The thread that is running the scheduler. boost::asio::detail::thread* thread_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/scheduler.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_SCHEDULER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/handler_type_requirements.hpp
// // detail/handler_type_requirements.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_TYPE_REQUIREMENTS_HPP #define BOOST_ASIO_DETAIL_HANDLER_TYPE_REQUIREMENTS_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> // Older versions of gcc have difficulty compiling the sizeof expressions where // we test the handler type requirements. We'll disable checking of handler type // requirements for those compilers, but otherwise enable it by default. #if !defined(BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS) # if !defined(__GNUC__) || (__GNUC__ >= 4) # define BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS 1 # endif // !defined(__GNUC__) || (__GNUC__ >= 4) #endif // !defined(BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS) // With C++0x we can use a combination of enhanced SFINAE and static_assert to // generate better template error messages. As this technique is not yet widely // portable, we'll only enable it for tested compilers. #if !defined(BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT) # if defined(__GNUC__) # if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4) # if defined(__GXX_EXPERIMENTAL_CXX0X__) # define BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT 1 # endif // defined(__GXX_EXPERIMENTAL_CXX0X__) # endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ > 4) # endif // defined(__GNUC__) # if defined(BOOST_ASIO_MSVC) # if (_MSC_VER >= 1600) # define BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT 1 # endif // (_MSC_VER >= 1600) # endif // defined(BOOST_ASIO_MSVC) # if defined(__clang__) # if __has_feature(__cxx_static_assert__) # define BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT 1 # endif // __has_feature(cxx_static_assert) # endif // defined(__clang__) #endif // !defined(BOOST_ASIO_DISABLE_HANDLER_TYPE_REQUIREMENTS) #if defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS) # include <boost/asio/async_result.hpp> #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS) namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS) # if defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT) template <typename Handler> auto zero_arg_copyable_handler_test(Handler h, void*) -> decltype( sizeof(Handler(static_cast<const Handler&>(h))), (static_cast<Handler&&>(h)()), char(0)); template <typename Handler> char (&zero_arg_copyable_handler_test(Handler, ...))[2]; template <typename Handler, typename Arg1> auto one_arg_handler_test(Handler h, Arg1* a1) -> decltype( sizeof(Handler(static_cast<Handler&&>(h))), (static_cast<Handler&&>(h)(*a1)), char(0)); template <typename Handler> char (&one_arg_handler_test(Handler h, ...))[2]; template <typename Handler, typename Arg1, typename Arg2> auto two_arg_handler_test(Handler h, Arg1* a1, Arg2* a2) -> decltype( sizeof(Handler(static_cast<Handler&&>(h))), (static_cast<Handler&&>(h)(*a1, *a2)), char(0)); template <typename Handler> char (&two_arg_handler_test(Handler, ...))[2]; template <typename Handler, typename Arg1, typename Arg2> auto two_arg_move_handler_test(Handler h, Arg1* a1, Arg2* a2) -> decltype( sizeof(Handler(static_cast<Handler&&>(h))), (static_cast<Handler&&>(h)( *a1, static_cast<Arg2&&>(*a2))), char(0)); template <typename Handler> char (&two_arg_move_handler_test(Handler, ...))[2]; # define BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT(expr, msg) \ static_assert(expr, msg); # else // defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT) # define BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT(expr, msg) # endif // defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS_ASSERT) template <typename T> T& lvref(); template <typename T> T& lvref(T); template <typename T> const T& clvref(); template <typename T> const T& clvref(T); template <typename T> T rvref(); template <typename T> T rvref(T); template <typename T> T rorlvref(); template <typename T> char argbyv(T); template <int> struct handler_type_requirements { }; #define BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void()) asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::zero_arg_copyable_handler_test( \ boost::asio::detail::clvref< \ asio_true_handler_type>(), 0)) == 1, \ "CompletionHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::clvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()(), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_READ_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, std::size_t)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const std::size_t*>(0))) == 1, \ "ReadHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const std::size_t>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_WRITE_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, std::size_t)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const std::size_t*>(0))) == 1, \ "WriteHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const std::size_t>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_ACCEPT_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::one_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0))) == 1, \ "AcceptHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_MOVE_ACCEPT_HANDLER_CHECK( \ handler_type, handler, socket_type) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, socket_type)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_move_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<socket_type*>(0))) == 1, \ "MoveAcceptHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::rvref<socket_type>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_CONNECT_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::one_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0))) == 1, \ "ConnectHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_RANGE_CONNECT_HANDLER_CHECK( \ handler_type, handler, endpoint_type) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, endpoint_type)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const endpoint_type*>(0))) == 1, \ "RangeConnectHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const endpoint_type>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_ITERATOR_CONNECT_HANDLER_CHECK( \ handler_type, handler, iter_type) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, iter_type)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const iter_type*>(0))) == 1, \ "IteratorConnectHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const iter_type>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_RESOLVE_HANDLER_CHECK( \ handler_type, handler, range_type) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, range_type)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const range_type*>(0))) == 1, \ "ResolveHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const range_type>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_WAIT_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::one_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0))) == 1, \ "WaitHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_SIGNAL_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, int)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const int*>(0))) == 1, \ "SignalHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const int>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_HANDSHAKE_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::one_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0))) == 1, \ "HandshakeHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code, std::size_t)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::two_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0), \ static_cast<const std::size_t*>(0))) == 1, \ "BufferedHandshakeHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>(), \ boost::asio::detail::lvref<const std::size_t>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_SHUTDOWN_HANDLER_CHECK( \ handler_type, handler) \ \ typedef BOOST_ASIO_HANDLER_TYPE(handler_type, \ void(boost::system::error_code)) \ asio_true_handler_type; \ \ BOOST_ASIO_HANDLER_TYPE_REQUIREMENTS_ASSERT( \ sizeof(boost::asio::detail::one_arg_handler_test( \ boost::asio::detail::rvref< \ asio_true_handler_type>(), \ static_cast<const boost::system::error_code*>(0))) == 1, \ "ShutdownHandler type requirements not met") \ \ typedef boost::asio::detail::handler_type_requirements< \ sizeof( \ boost::asio::detail::argbyv( \ boost::asio::detail::rvref< \ asio_true_handler_type>())) + \ sizeof( \ boost::asio::detail::rorlvref< \ asio_true_handler_type>()( \ boost::asio::detail::lvref<const boost::system::error_code>()), \ char(0))> BOOST_ASIO_UNUSED_TYPEDEF #else // !defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS) #define BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_READ_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_WRITE_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_ACCEPT_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_MOVE_ACCEPT_HANDLER_CHECK( \ handler_type, handler, socket_type) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_CONNECT_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_RANGE_CONNECT_HANDLER_CHECK( \ handler_type, handler, iter_type) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_ITERATOR_CONNECT_HANDLER_CHECK( \ handler_type, handler, iter_type) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_RESOLVE_HANDLER_CHECK( \ handler_type, handler, iter_type) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_WAIT_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_SIGNAL_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_HANDSHAKE_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #define BOOST_ASIO_SHUTDOWN_HANDLER_CHECK( \ handler_type, handler) \ typedef int BOOST_ASIO_UNUSED_TYPEDEF #endif // !defined(BOOST_ASIO_ENABLE_HANDLER_TYPE_REQUIREMENTS) } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_HANDLER_TYPE_REQUIREMENTS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/handler_cont_helpers.hpp
// // detail/handler_cont_helpers.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_HANDLER_CONT_HELPERS_HPP #define BOOST_ASIO_DETAIL_HANDLER_CONT_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/handler_continuation_hook.hpp> #include <boost/asio/detail/push_options.hpp> // Calls to asio_handler_is_continuation must be made from a namespace that // does not contain overloads of this function. This namespace is defined here // for that purpose. namespace boost_asio_handler_cont_helpers { template <typename Context> inline bool is_continuation(Context& context) { #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS) return false; #else using boost::asio::asio_handler_is_continuation; return asio_handler_is_continuation( boost::asio::detail::addressof(context)); #endif } } // namespace boost_asio_handler_cont_helpers #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_HANDLER_CONT_HELPERS_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/executor_op.hpp
// // detail/executor_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_EXECUTOR_OP_HPP #define BOOST_ASIO_DETAIL_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/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/scheduler_operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename Alloc, typename Operation = scheduler_operation> class executor_op : public Operation { public: BOOST_ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(executor_op); template <typename H> executor_op(H&& h, const Alloc& allocator) : Operation(&executor_op::do_complete), handler_(static_cast<H&&>(h)), allocator_(allocator) { } static void do_complete(void* owner, Operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); executor_op* o(static_cast<executor_op*>(base)); Alloc allocator(o->allocator_); ptr p = { detail::addressof(allocator), o, o }; BOOST_ASIO_HANDLER_COMPLETION((*o)); // Make a copy of the handler so that the memory can be deallocated before // the upcall is made. Even if we're not about to make an upcall, a // sub-object of the handler may be the true owner of the memory associated // with the handler. Consequently, a local copy of the handler is required // to ensure that any owning sub-object remains valid until after we have // deallocated the memory here. Handler handler(static_cast<Handler&&>(o->handler_)); p.reset(); // Make the upcall if required. if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN(()); static_cast<Handler&&>(handler)(); BOOST_ASIO_HANDLER_INVOCATION_END; } } private: Handler handler_; Alloc allocator_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_EXECUTOR_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_ssocket_service.hpp
// // detail/winrt_ssocket_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_SSOCKET_SERVICE_HPP #define BOOST_ASIO_DETAIL_WINRT_SSOCKET_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/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/winrt_socket_connect_op.hpp> #include <boost/asio/detail/winrt_ssocket_service_base.hpp> #include <boost/asio/detail/winrt_utils.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol> class winrt_ssocket_service : public execution_context_service_base<winrt_ssocket_service<Protocol>>, public winrt_ssocket_service_base { public: // The protocol type. typedef Protocol protocol_type; // The endpoint type. typedef typename Protocol::endpoint endpoint_type; // The native type of a socket. typedef Windows::Networking::Sockets::StreamSocket^ native_handle_type; // The implementation type of the socket. struct implementation_type : base_implementation_type { // Default constructor. implementation_type() : base_implementation_type(), protocol_(endpoint_type().protocol()) { } // The protocol associated with the socket. protocol_type protocol_; }; // Constructor. winrt_ssocket_service(execution_context& context) : execution_context_service_base<winrt_ssocket_service<Protocol>>(context), winrt_ssocket_service_base(context) { } // Destroy all user-defined handler objects owned by the service. void shutdown() { this->base_shutdown(); } // Move-construct a new socket implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) noexcept { this->base_move_construct(impl, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); } // Move-assign from another socket implementation. void move_assign(implementation_type& impl, winrt_ssocket_service& other_service, implementation_type& other_impl) { this->base_move_assign(impl, other_service, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); } // Move-construct a new socket implementation from another protocol type. template <typename Protocol1> void converting_move_construct(implementation_type& impl, winrt_ssocket_service<Protocol1>&, typename winrt_ssocket_service< Protocol1>::implementation_type& other_impl) { this->base_move_construct(impl, other_impl); impl.protocol_ = protocol_type(other_impl.protocol_); other_impl.protocol_ = typename Protocol1::endpoint().protocol(); } // Open a new socket implementation. boost::system::error_code open(implementation_type& impl, const protocol_type& protocol, boost::system::error_code& ec) { if (is_open(impl)) { ec = boost::asio::error::already_open; return ec; } try { impl.socket_ = ref new Windows::Networking::Sockets::StreamSocket; impl.protocol_ = protocol; ec = boost::system::error_code(); } catch (Platform::Exception^ e) { ec = boost::system::error_code(e->HResult, boost::system::system_category()); } return ec; } // Assign a native socket to a socket implementation. boost::system::error_code assign(implementation_type& impl, const protocol_type& protocol, const native_handle_type& native_socket, boost::system::error_code& ec) { if (is_open(impl)) { ec = boost::asio::error::already_open; return ec; } impl.socket_ = native_socket; impl.protocol_ = protocol; ec = boost::system::error_code(); return ec; } // Bind the socket to the specified local endpoint. boost::system::error_code bind(implementation_type&, const endpoint_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Get the local endpoint. endpoint_type local_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; endpoint.resize(do_get_endpoint(impl, true, endpoint.data(), endpoint.size(), ec)); return endpoint; } // Get the remote endpoint. endpoint_type remote_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; endpoint.resize(do_get_endpoint(impl, false, endpoint.data(), endpoint.size(), ec)); return endpoint; } // Disable sends or receives on the socket. boost::system::error_code shutdown(implementation_type&, socket_base::shutdown_type, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; return ec; } // Set a socket option. template <typename Option> boost::system::error_code set_option(implementation_type& impl, const Option& option, boost::system::error_code& ec) { return do_set_option(impl, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), option.size(impl.protocol_), ec); } // Get a socket option. template <typename Option> boost::system::error_code get_option(const implementation_type& impl, Option& option, boost::system::error_code& ec) const { std::size_t size = option.size(impl.protocol_); do_get_option(impl, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), &size, ec); if (!ec) option.resize(impl.protocol_, size); return ec; } // Connect the socket to the specified endpoint. boost::system::error_code connect(implementation_type& impl, const endpoint_type& peer_endpoint, boost::system::error_code& ec) { return do_connect(impl, peer_endpoint.data(), ec); } // Start an asynchronous connect. template <typename Handler, typename IoExecutor> void async_connect(implementation_type& impl, const endpoint_type& peer_endpoint, 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_socket_connect_op<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); BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "socket", &impl, 0, "async_connect")); start_connect_op(impl, peer_endpoint.data(), p.p, is_continuation); 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_WINRT_SSOCKET_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/deadline_timer_service.hpp
// // detail/deadline_timer_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP #define BOOST_ASIO_DETAIL_DEADLINE_TIMER_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 <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/detail/bind_handler.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/timer_queue.hpp> #include <boost/asio/detail/timer_queue_ptime.hpp> #include <boost/asio/detail/timer_scheduler.hpp> #include <boost/asio/detail/wait_handler.hpp> #include <boost/asio/detail/wait_op.hpp> #if defined(BOOST_ASIO_WINDOWS_RUNTIME) # include <chrono> # include <thread> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Time_Traits> class deadline_timer_service : public execution_context_service_base<deadline_timer_service<Time_Traits>> { public: // The time type. typedef typename Time_Traits::time_type time_type; // The duration type. typedef typename Time_Traits::duration_type duration_type; // The implementation type of the timer. This type is dependent on the // underlying implementation of the timer service. struct implementation_type : private boost::asio::detail::noncopyable { time_type expiry; bool might_have_pending_waits; typename timer_queue<Time_Traits>::per_timer_data timer_data; }; // Constructor. deadline_timer_service(execution_context& context) : execution_context_service_base< deadline_timer_service<Time_Traits>>(context), scheduler_(boost::asio::use_service<timer_scheduler>(context)) { scheduler_.init_task(); scheduler_.add_timer_queue(timer_queue_); } // Destructor. ~deadline_timer_service() { scheduler_.remove_timer_queue(timer_queue_); } // Destroy all user-defined handler objects owned by the service. void shutdown() { } // Construct a new timer implementation. void construct(implementation_type& impl) { impl.expiry = time_type(); impl.might_have_pending_waits = false; } // Destroy a timer implementation. void destroy(implementation_type& impl) { boost::system::error_code ec; cancel(impl, ec); } // Move-construct a new timer implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) { scheduler_.move_timer(timer_queue_, impl.timer_data, other_impl.timer_data); impl.expiry = other_impl.expiry; other_impl.expiry = time_type(); impl.might_have_pending_waits = other_impl.might_have_pending_waits; other_impl.might_have_pending_waits = false; } // Move-assign from another timer implementation. void move_assign(implementation_type& impl, deadline_timer_service& other_service, implementation_type& other_impl) { if (this != &other_service) if (impl.might_have_pending_waits) scheduler_.cancel_timer(timer_queue_, impl.timer_data); other_service.scheduler_.move_timer(other_service.timer_queue_, impl.timer_data, other_impl.timer_data); impl.expiry = other_impl.expiry; other_impl.expiry = time_type(); impl.might_have_pending_waits = other_impl.might_have_pending_waits; other_impl.might_have_pending_waits = false; } // Move-construct a new timer implementation. void converting_move_construct(implementation_type& impl, deadline_timer_service&, implementation_type& other_impl) { move_construct(impl, other_impl); } // Move-assign from another timer implementation. void converting_move_assign(implementation_type& impl, deadline_timer_service& other_service, implementation_type& other_impl) { move_assign(impl, other_service, other_impl); } // Cancel any asynchronous wait operations associated with the timer. std::size_t cancel(implementation_type& impl, boost::system::error_code& ec) { if (!impl.might_have_pending_waits) { ec = boost::system::error_code(); return 0; } BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "deadline_timer", &impl, 0, "cancel")); std::size_t count = scheduler_.cancel_timer(timer_queue_, impl.timer_data); impl.might_have_pending_waits = false; ec = boost::system::error_code(); return count; } // Cancels one asynchronous wait operation associated with the timer. std::size_t cancel_one(implementation_type& impl, boost::system::error_code& ec) { if (!impl.might_have_pending_waits) { ec = boost::system::error_code(); return 0; } BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(), "deadline_timer", &impl, 0, "cancel_one")); std::size_t count = scheduler_.cancel_timer( timer_queue_, impl.timer_data, 1); if (count == 0) impl.might_have_pending_waits = false; ec = boost::system::error_code(); return count; } // Get the expiry time for the timer as an absolute time. time_type expiry(const implementation_type& impl) const { return impl.expiry; } // Get the expiry time for the timer as an absolute time. time_type expires_at(const implementation_type& impl) const { return impl.expiry; } // Get the expiry time for the timer relative to now. duration_type expires_from_now(const implementation_type& impl) const { return Time_Traits::subtract(this->expiry(impl), Time_Traits::now()); } // Set the expiry time for the timer as an absolute time. std::size_t expires_at(implementation_type& impl, const time_type& expiry_time, boost::system::error_code& ec) { std::size_t count = cancel(impl, ec); impl.expiry = expiry_time; ec = boost::system::error_code(); return count; } // Set the expiry time for the timer relative to now. std::size_t expires_after(implementation_type& impl, const duration_type& expiry_time, boost::system::error_code& ec) { return expires_at(impl, Time_Traits::add(Time_Traits::now(), expiry_time), ec); } // Set the expiry time for the timer relative to now. std::size_t expires_from_now(implementation_type& impl, const duration_type& expiry_time, boost::system::error_code& ec) { return expires_at(impl, Time_Traits::add(Time_Traits::now(), expiry_time), ec); } // Perform a blocking wait on the timer. void wait(implementation_type& impl, boost::system::error_code& ec) { time_type now = Time_Traits::now(); ec = boost::system::error_code(); while (Time_Traits::less_than(now, impl.expiry) && !ec) { this->do_wait(Time_Traits::to_posix_duration( Time_Traits::subtract(impl.expiry, now)), ec); now = Time_Traits::now(); } } // Start an asynchronous wait on the timer. template <typename Handler, typename IoExecutor> void async_wait(implementation_type& impl, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef wait_handler<Handler, IoExecutor> op; typename op::ptr p = { 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<op_cancellation>(this, &impl.timer_data); } impl.might_have_pending_waits = true; BOOST_ASIO_HANDLER_CREATION((scheduler_.context(), *p.p, "deadline_timer", &impl, 0, "async_wait")); scheduler_.schedule_timer(timer_queue_, impl.expiry, impl.timer_data, p.p); p.v = p.p = 0; } private: // Helper function to wait given a duration type. The duration type should // either be of type boost::posix_time::time_duration, or implement the // required subset of its interface. template <typename Duration> void do_wait(const Duration& timeout, boost::system::error_code& ec) { #if defined(BOOST_ASIO_WINDOWS_RUNTIME) std::this_thread::sleep_for( std::chrono::seconds(timeout.total_seconds()) + std::chrono::microseconds(timeout.total_microseconds())); ec = boost::system::error_code(); #else // defined(BOOST_ASIO_WINDOWS_RUNTIME) ::timeval tv; tv.tv_sec = timeout.total_seconds(); tv.tv_usec = timeout.total_microseconds() % 1000000; socket_ops::select(0, 0, 0, 0, &tv, ec); #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) } // Helper class used to implement per-operation cancellation. class op_cancellation { public: op_cancellation(deadline_timer_service* s, typename timer_queue<Time_Traits>::per_timer_data* p) : service_(s), timer_data_(p) { } void operator()(cancellation_type_t type) { if (!!(type & (cancellation_type::terminal | cancellation_type::partial | cancellation_type::total))) { service_->scheduler_.cancel_timer_by_key( service_->timer_queue_, timer_data_, this); } } private: deadline_timer_service* service_; typename timer_queue<Time_Traits>::per_timer_data* timer_data_; }; // The queue of timers. timer_queue<Time_Traits> timer_queue_; // The object that schedules and executes timers. Usually a reactor. timer_scheduler& scheduler_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_DEADLINE_TIMER_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/cstddef.hpp
// // detail/cstddef.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_CSTDDEF_HPP #define BOOST_ASIO_DETAIL_CSTDDEF_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> namespace boost { namespace asio { using std::nullptr_t; } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_CSTDDEF_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/strand_service.hpp
// // detail/strand_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_STRAND_SERVICE_HPP #define BOOST_ASIO_DETAIL_STRAND_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 <boost/asio/io_context.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/op_queue.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/scoped_ptr.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Default service implementation for a strand. class strand_service : public boost::asio::detail::service_base<strand_service> { private: // Helper class to re-post the strand on exit. struct on_do_complete_exit; // Helper class to re-post the strand on exit. struct on_dispatch_exit; public: // The underlying implementation of a strand. class strand_impl : public operation { public: strand_impl(); private: // Only this service will have access to the internal values. friend class strand_service; friend struct on_do_complete_exit; friend struct on_dispatch_exit; // Mutex to protect access to internal data. boost::asio::detail::mutex mutex_; // Indicates whether the strand is currently "locked" by a handler. This // means that there is a handler upcall in progress, or that the strand // itself has been scheduled in order to invoke some pending handlers. bool locked_; // The handlers that are waiting on the strand but should not be run until // after the next time the strand is scheduled. This queue must only be // modified while the mutex is locked. op_queue<operation> waiting_queue_; // The handlers that are ready to be run. Logically speaking, these are the // handlers that hold the strand's lock. The ready queue is only modified // from within the strand and so may be accessed without locking the mutex. op_queue<operation> ready_queue_; }; typedef strand_impl* implementation_type; // Construct a new strand service for the specified io_context. BOOST_ASIO_DECL explicit strand_service(boost::asio::io_context& io_context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new strand implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Request the io_context to invoke the given handler. template <typename Handler> void dispatch(implementation_type& impl, Handler& handler); // Request the io_context to invoke the given handler and return immediately. template <typename Handler> void post(implementation_type& impl, Handler& handler); // Determine whether the strand is running in the current thread. BOOST_ASIO_DECL bool running_in_this_thread( const implementation_type& impl) const; private: // Helper function to dispatch a handler. BOOST_ASIO_DECL void do_dispatch(implementation_type& impl, operation* op); // Helper function to post a handler. BOOST_ASIO_DECL void do_post(implementation_type& impl, operation* op, bool is_continuation); BOOST_ASIO_DECL static void do_complete(void* owner, operation* base, const boost::system::error_code& ec, std::size_t bytes_transferred); // The io_context used to obtain an I/O executor. io_context& io_context_; // The io_context implementation used to post completions. io_context_impl& io_context_impl_; // Mutex to protect access to the array of implementations. boost::asio::detail::mutex mutex_; // Number of implementations shared between all strand objects. #if defined(BOOST_ASIO_STRAND_IMPLEMENTATIONS) enum { num_implementations = BOOST_ASIO_STRAND_IMPLEMENTATIONS }; #else // defined(BOOST_ASIO_STRAND_IMPLEMENTATIONS) enum { num_implementations = 193 }; #endif // defined(BOOST_ASIO_STRAND_IMPLEMENTATIONS) // Pool of implementations. scoped_ptr<strand_impl> implementations_[num_implementations]; // Extra value used when hashing to prevent recycled memory locations from // getting the same strand implementation. std::size_t salt_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/detail/impl/strand_service.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/strand_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_DETAIL_STRAND_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_handle_service.hpp
// // detail/win_iocp_handle_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_SERVICE_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_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) #include <boost/asio/associated_cancellation_slot.hpp> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/buffer_sequence_adapter.hpp> #include <boost/asio/detail/cstdint.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/win_iocp_handle_read_op.hpp> #include <boost/asio/detail/win_iocp_handle_write_op.hpp> #include <boost/asio/detail/win_iocp_io_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class win_iocp_handle_service : public execution_context_service_base<win_iocp_handle_service> { public: // The native type of a stream handle. typedef HANDLE native_handle_type; // The implementation type of the stream handle. class implementation_type { public: // Default constructor. implementation_type() : handle_(INVALID_HANDLE_VALUE), safe_cancellation_thread_id_(0), next_(0), prev_(0) { } private: // Only this service will have access to the internal values. friend class win_iocp_handle_service; // The native stream handle representation. native_handle_type handle_; // The ID of the thread from which it is safe to cancel asynchronous // operations. 0 means no asynchronous operations have been started yet. // ~0 means asynchronous operations have been started from more than one // thread, and cancellation is not supported for the handle. DWORD safe_cancellation_thread_id_; // Pointers to adjacent handle implementations in linked list. implementation_type* next_; implementation_type* prev_; }; BOOST_ASIO_DECL win_iocp_handle_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new handle implementation. BOOST_ASIO_DECL void construct(implementation_type& impl); // Move-construct a new handle implementation. BOOST_ASIO_DECL void move_construct(implementation_type& impl, implementation_type& other_impl); // Move-assign from another handle implementation. BOOST_ASIO_DECL void move_assign(implementation_type& impl, win_iocp_handle_service& other_service, implementation_type& other_impl); // Destroy a handle implementation. BOOST_ASIO_DECL void destroy(implementation_type& impl); // Assign a native handle to a handle implementation. BOOST_ASIO_DECL boost::system::error_code assign(implementation_type& impl, const native_handle_type& handle, boost::system::error_code& ec); // Determine whether the handle is open. bool is_open(const implementation_type& impl) const { return impl.handle_ != INVALID_HANDLE_VALUE; } // Destroy a handle implementation. BOOST_ASIO_DECL boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec); // Release ownership of a handle. BOOST_ASIO_DECL native_handle_type release(implementation_type& impl, boost::system::error_code& ec); // Get the native handle representation. native_handle_type native_handle(const implementation_type& impl) const { return impl.handle_; } // Cancel all operations associated with the handle. BOOST_ASIO_DECL boost::system::error_code cancel(implementation_type& impl, 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 write_some_at(impl, 0, buffers, ec); } // Write the given data at the specified offset. Returns the number of bytes // written. template <typename ConstBufferSequence> size_t write_some_at(implementation_type& impl, uint64_t offset, const ConstBufferSequence& buffers, boost::system::error_code& ec) { boost::asio::const_buffer buffer = buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::first(buffers); return do_write(impl, offset, buffer, ec); } // Start an asynchronous write. The data being written must be valid for the // lifetime of the asynchronous operation. template <typename ConstBufferSequence, typename Handler, typename IoExecutor> void async_write_some(implementation_type& impl, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef win_iocp_handle_write_op< ConstBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; operation* o = p.p = new (p.v) op(buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl, reinterpret_cast<uintmax_t>(impl.handle_), "async_write_some")); // Optionally register for per-operation cancellation. if (slot.is_connected()) o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o); start_write_op(impl, 0, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::first(buffers), o); p.v = p.p = 0; } // Start an asynchronous write at a specified offset. The data being written // must be valid for the lifetime of the asynchronous operation. template <typename ConstBufferSequence, typename Handler, typename IoExecutor> void async_write_some_at(implementation_type& impl, uint64_t offset, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef win_iocp_handle_write_op< ConstBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; operation* o = p.p = new (p.v) op(buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl, reinterpret_cast<uintmax_t>(impl.handle_), "async_write_some_at")); // Optionally register for per-operation cancellation. if (slot.is_connected()) o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o); start_write_op(impl, offset, buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence>::first(buffers), o); p.v = p.p = 0; } // Read some data. Returns the number of bytes received. template <typename MutableBufferSequence> size_t read_some(implementation_type& impl, const MutableBufferSequence& buffers, boost::system::error_code& ec) { return read_some_at(impl, 0, buffers, ec); } // Read some data at a specified offset. Returns the number of bytes received. template <typename MutableBufferSequence> size_t read_some_at(implementation_type& impl, uint64_t offset, const MutableBufferSequence& buffers, boost::system::error_code& ec) { boost::asio::mutable_buffer buffer = buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::first(buffers); return do_read(impl, offset, buffer, ec); } // Start an asynchronous read. The buffer for the data being received must be // valid for the lifetime of the asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef win_iocp_handle_read_op< MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; operation* o = p.p = new (p.v) op(buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl, reinterpret_cast<uintmax_t>(impl.handle_), "async_read_some")); // Optionally register for per-operation cancellation. if (slot.is_connected()) o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o); start_read_op(impl, 0, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::first(buffers), o); p.v = p.p = 0; } // Start an asynchronous read at a specified offset. The buffer for the data // being received must be valid for the lifetime of the asynchronous // operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some_at(implementation_type& impl, uint64_t offset, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { associated_cancellation_slot_t<Handler> slot = boost::asio::get_associated_cancellation_slot(handler); // Allocate and construct an operation to wrap the handler. typedef win_iocp_handle_read_op< MutableBufferSequence, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; operation* o = p.p = new (p.v) op(buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((iocp_service_.context(), *p.p, "handle", &impl, reinterpret_cast<uintmax_t>(impl.handle_), "async_read_some_at")); // Optionally register for per-operation cancellation. if (slot.is_connected()) o = &slot.template emplace<iocp_op_cancellation>(impl.handle_, o); start_read_op(impl, offset, buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::first(buffers), o); p.v = p.p = 0; } private: // Prevent the use of the null_buffers type with this service. size_t write_some(implementation_type& impl, const null_buffers& buffers, boost::system::error_code& ec); size_t write_some_at(implementation_type& impl, uint64_t offset, const null_buffers& buffers, boost::system::error_code& ec); template <typename Handler, typename IoExecutor> void async_write_some(implementation_type& impl, const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex); template <typename Handler, typename IoExecutor> void async_write_some_at(implementation_type& impl, uint64_t offset, const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex); size_t read_some(implementation_type& impl, const null_buffers& buffers, boost::system::error_code& ec); size_t read_some_at(implementation_type& impl, uint64_t offset, const null_buffers& buffers, boost::system::error_code& ec); template <typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex); template <typename Handler, typename IoExecutor> void async_read_some_at(implementation_type& impl, uint64_t offset, const null_buffers& buffers, Handler& handler, const IoExecutor& io_ex); // Helper class for waiting for synchronous operations to complete. class overlapped_wrapper; // Helper function to perform a synchronous write operation. BOOST_ASIO_DECL size_t do_write(implementation_type& impl, uint64_t offset, const boost::asio::const_buffer& buffer, boost::system::error_code& ec); // Helper function to start a write operation. BOOST_ASIO_DECL void start_write_op(implementation_type& impl, uint64_t offset, const boost::asio::const_buffer& buffer, operation* op); // Helper function to perform a synchronous write operation. BOOST_ASIO_DECL size_t do_read(implementation_type& impl, uint64_t offset, const boost::asio::mutable_buffer& buffer, boost::system::error_code& ec); // Helper function to start a read operation. BOOST_ASIO_DECL void start_read_op(implementation_type& impl, uint64_t offset, const boost::asio::mutable_buffer& buffer, operation* op); // Update the ID of the thread from which cancellation is safe. BOOST_ASIO_DECL void update_cancellation_thread_id(implementation_type& impl); // Helper function to close a handle when the associated object is being // destroyed. BOOST_ASIO_DECL void close_for_destruction(implementation_type& impl); // The type of a NtSetInformationFile function pointer. typedef LONG (NTAPI *nt_set_info_fn)(HANDLE, ULONG_PTR*, void*, ULONG, ULONG); // Helper function to get the NtSetInformationFile function pointer. If no // NtSetInformationFile pointer has been obtained yet, one is obtained using // GetProcAddress and the pointer is cached. Returns a null pointer if // NtSetInformationFile is not available. 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(HANDLE h, operation* target) : operation(&iocp_op_cancellation::do_complete), handle_(h), 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))) { ::CancelIoEx(handle_, this); } #else // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) (void)type; #endif // defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600) } private: HANDLE handle_; operation* target_; }; // The IOCP service used for running asynchronous operations and dispatching // handlers. win_iocp_io_context& iocp_service_; // Pointer to NtSetInformationFile implementation. void* nt_set_info_; // Mutex to protect access to the linked list of implementations. mutex mutex_; // The head of a linked list of all implementations. implementation_type* impl_list_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/win_iocp_handle_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/timer_queue_base.hpp
// // detail/timer_queue_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_TIMER_QUEUE_BASE_HPP #define BOOST_ASIO_DETAIL_TIMER_QUEUE_BASE_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/op_queue.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class timer_queue_base : private noncopyable { public: // Constructor. timer_queue_base() : next_(0) {} // Destructor. virtual ~timer_queue_base() {} // Whether there are no timers in the queue. virtual bool empty() const = 0; // Get the time to wait until the next timer. virtual long wait_duration_msec(long max_duration) const = 0; // Get the time to wait until the next timer. virtual long wait_duration_usec(long max_duration) const = 0; // Dequeue all ready timers. virtual void get_ready_timers(op_queue<operation>& ops) = 0; // Dequeue all timers. virtual void get_all_timers(op_queue<operation>& ops) = 0; private: friend class timer_queue_set; // Next timer queue in the set. timer_queue_base* next_; }; template <typename Time_Traits> class timer_queue; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_BASE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_connect_op.hpp
// // detail/io_uring_socket_connect_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_CONNECT_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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_ops.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol> class io_uring_socket_connect_op_base : public io_uring_operation { public: io_uring_socket_connect_op_base(const boost::system::error_code& success_ec, socket_type socket, const typename Protocol::endpoint& endpoint, func_type complete_func) : io_uring_operation(success_ec, &io_uring_socket_connect_op_base::do_prepare, &io_uring_socket_connect_op_base::do_perform, complete_func), socket_(socket), endpoint_(endpoint) { } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_connect_op_base* o( static_cast<io_uring_socket_connect_op_base*>(base)); ::io_uring_prep_connect(sqe, o->socket_, static_cast<sockaddr*>(o->endpoint_.data()), static_cast<socklen_t>(o->endpoint_.size())); } static bool do_perform(io_uring_operation*, bool after_completion) { return after_completion; } private: socket_type socket_; typename Protocol::endpoint endpoint_; }; template <typename Protocol, typename Handler, typename IoExecutor> class io_uring_socket_connect_op : public io_uring_socket_connect_op_base<Protocol> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_connect_op); io_uring_socket_connect_op(const boost::system::error_code& success_ec, socket_type socket, const typename Protocol::endpoint& endpoint, Handler& handler, const IoExecutor& io_ex) : io_uring_socket_connect_op_base<Protocol>(success_ec, socket, endpoint, &io_uring_socket_connect_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_connect_op* o (static_cast<io_uring_socket_connect_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::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_; }; } // 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_CONNECT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/dev_poll_reactor.hpp
// // detail/dev_poll_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_DEV_POLL_REACTOR_HPP #define BOOST_ASIO_DETAIL_DEV_POLL_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_DEV_POLL) #include <cstddef> #include <vector> #include <sys/devpoll.h> #include <boost/asio/detail/hash_map.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> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class dev_poll_reactor : public execution_context_service_base<dev_poll_reactor>, public scheduler_task { public: enum op_types { read_op = 0, write_op = 1, connect_op = 1, except_op = 2, max_ops = 3 }; // Per-descriptor data. struct per_descriptor_data { }; // Constructor. BOOST_ASIO_DECL dev_poll_reactor(boost::asio::execution_context& ctx); // Destructor. BOOST_ASIO_DECL ~dev_poll_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, 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); // 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&, 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, &dev_poll_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&); // 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 /dev/poll 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: // Create the /dev/poll file descriptor. Throws an exception if the descriptor // cannot be created. BOOST_ASIO_DECL static int do_dev_poll_create(); // 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 /dev/poll DP_POLL operation. The timeout // value is returned as a number of milliseconds. A return value of -1 // indicates that the poll should block indefinitely. BOOST_ASIO_DECL int get_timeout(int msec); // Cancel all operations associated with the given descriptor. The do_cancel // function of the handler objects will be invoked. This function does not // acquire the dev_poll_reactor's mutex. BOOST_ASIO_DECL void cancel_ops_unlocked(socket_type descriptor, const boost::system::error_code& ec); // Add a pending event entry for the given descriptor. BOOST_ASIO_DECL ::pollfd& add_pending_event_change(int descriptor); // The scheduler implementation used to post completions. scheduler& scheduler_; // Mutex to protect access to internal data. boost::asio::detail::mutex mutex_; // The /dev/poll file descriptor. int dev_poll_fd_; // Vector of /dev/poll events waiting to be written to the descriptor. std::vector< ::pollfd> pending_event_changes_; // Hash map to associate a descriptor with a pending event change index. hash_map<int, std::size_t> pending_event_change_index_; // The interrupter is used to break a blocking DP_POLL operation. select_interrupter interrupter_; // The queues of read, write and except operations. reactor_op_queue<socket_type> op_queue_[max_ops]; // The timer queues. timer_queue_set timer_queues_; // 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/dev_poll_reactor.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/dev_poll_reactor.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_DEV_POLL) #endif // BOOST_ASIO_DETAIL_DEV_POLL_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_socket_recv_op.hpp
// // detail/winrt_socket_recv_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WINRT_SOCKET_RECV_OP_HPP #define BOOST_ASIO_DETAIL_WINRT_SOCKET_RECV_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/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/winrt_async_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class winrt_socket_recv_op : public winrt_async_op<Windows::Storage::Streams::IBuffer^> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(winrt_socket_recv_op); winrt_socket_recv_op(const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : winrt_async_op<Windows::Storage::Streams::IBuffer^>( &winrt_socket_recv_op::do_complete), buffers_(buffers), 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_socket_recv_op* o(static_cast<winrt_socket_recv_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) std::size_t bytes_transferred = o->result_ ? o->result_->Length : 0; if (bytes_transferred == 0 && !o->ec_ && !buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::all_empty(o->buffers_)) { o->ec_ = boost::asio::error::eof; } // 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_, 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: MutableBufferSequence buffers_; 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_SOCKET_RECV_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_handle_read_op.hpp
// // detail/win_iocp_handle_read_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_READ_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_READ_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/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class win_iocp_handle_read_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_handle_read_op); win_iocp_handle_read_op(const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_handle_read_op::do_complete), buffers_(buffers), 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_handle_read_op* o(static_cast<win_iocp_handle_read_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) if (owner) { // Check whether buffers are still valid. buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence>::validate(o->buffers_); } #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. if (ec.value() == ERROR_HANDLE_EOF) ec = boost::asio::error::eof; 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: MutableBufferSequence buffers_; 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_HANDLE_READ_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/concurrency_hint.hpp
// // detail/concurrency_hint.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_CONCURRENCY_HINT_HPP #define BOOST_ASIO_DETAIL_CONCURRENCY_HINT_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> // The concurrency hint ID and mask are used to identify when a "well-known" // concurrency hint value has been passed to the io_context. #define BOOST_ASIO_CONCURRENCY_HINT_ID 0xA5100000u #define BOOST_ASIO_CONCURRENCY_HINT_ID_MASK 0xFFFF0000u // If set, this bit indicates that the scheduler should perform locking. #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER 0x1u // If set, this bit indicates that the reactor should perform locking when // managing descriptor registrations. #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION 0x2u // If set, this bit indicates that the reactor should perform locking for I/O. #define BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO 0x4u // Helper macro to determine if we have a special concurrency hint. #define BOOST_ASIO_CONCURRENCY_HINT_IS_SPECIAL(hint) \ ((static_cast<unsigned>(hint) \ & BOOST_ASIO_CONCURRENCY_HINT_ID_MASK) \ == BOOST_ASIO_CONCURRENCY_HINT_ID) // Helper macro to determine if locking is enabled for a given facility. #define BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(facility, hint) \ (((static_cast<unsigned>(hint) \ & (BOOST_ASIO_CONCURRENCY_HINT_ID_MASK \ | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_ ## facility)) \ ^ BOOST_ASIO_CONCURRENCY_HINT_ID) != 0) // This special concurrency hint disables locking in both the scheduler and // reactor I/O. This hint has the following restrictions: // // - Care must be taken to ensure that all operations on the io_context and any // of its associated I/O objects (such as sockets and timers) occur in only // one thread at a time. // // - Asynchronous resolve operations fail with operation_not_supported. // // - If a signal_set is used with the io_context, signal_set objects cannot be // used with any other io_context in the program. #define BOOST_ASIO_CONCURRENCY_HINT_UNSAFE \ static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID) // This special concurrency hint disables locking in the reactor I/O. This hint // has the following restrictions: // // - Care must be taken to ensure that run functions on the io_context, and all // operations on the io_context's associated I/O objects (such as sockets and // timers), occur in only one thread at a time. #define BOOST_ASIO_CONCURRENCY_HINT_UNSAFE_IO \ static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID \ | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \ | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION) // The special concurrency hint provides full thread safety. #define BOOST_ASIO_CONCURRENCY_HINT_SAFE \ static_cast<int>(BOOST_ASIO_CONCURRENCY_HINT_ID \ | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_SCHEDULER \ | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_REGISTRATION \ | BOOST_ASIO_CONCURRENCY_HINT_LOCKING_REACTOR_IO) // This #define may be overridden at compile time to specify a program-wide // default concurrency hint, used by the zero-argument io_context constructor. #if !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT) # define BOOST_ASIO_CONCURRENCY_HINT_DEFAULT -1 #endif // !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT) // This #define may be overridden at compile time to specify a program-wide // concurrency hint, used by the one-argument io_context constructor when // passed a value of 1. #if !defined(BOOST_ASIO_CONCURRENCY_HINT_1) # define BOOST_ASIO_CONCURRENCY_HINT_1 1 #endif // !defined(BOOST_ASIO_CONCURRENCY_HINT_DEFAULT) #endif // BOOST_ASIO_DETAIL_CONCURRENCY_HINT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/composed_work.hpp
// // detail/composed_work.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_COMPOSED_WORK_HPP #define BOOST_ASIO_DETAIL_COMPOSED_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/detail/type_traits.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution/outstanding_work.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/is_executor.hpp> #include <boost/asio/system_executor.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Executor, typename = void> class composed_work_guard { public: typedef decay_t< prefer_result_t<Executor, execution::outstanding_work_t::tracked_t> > executor_type; composed_work_guard(const Executor& ex) : executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } void reset() { } executor_type get_executor() const noexcept { return executor_; } private: executor_type executor_; }; template <> struct composed_work_guard<system_executor> { public: typedef system_executor executor_type; composed_work_guard(const system_executor&) { } void reset() { } executor_type get_executor() const noexcept { return system_executor(); } }; #if !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename Executor> struct composed_work_guard<Executor, enable_if_t< !execution::is_executor<Executor>::value > > : executor_work_guard<Executor> { composed_work_guard(const Executor& ex) : executor_work_guard<Executor>(ex) { } }; #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename> struct composed_io_executors; template <> struct composed_io_executors<void()> { composed_io_executors() noexcept : head_(system_executor()) { } typedef system_executor head_type; system_executor head_; }; inline composed_io_executors<void()> make_composed_io_executors() { return composed_io_executors<void()>(); } template <typename Head> struct composed_io_executors<void(Head)> { explicit composed_io_executors(const Head& ex) noexcept : head_(ex) { } typedef Head head_type; Head head_; }; template <typename Head> inline composed_io_executors<void(Head)> make_composed_io_executors(const Head& head) { return composed_io_executors<void(Head)>(head); } template <typename Head, typename... Tail> struct composed_io_executors<void(Head, Tail...)> { explicit composed_io_executors(const Head& head, const Tail&... tail) noexcept : head_(head), tail_(tail...) { } void reset() { head_.reset(); tail_.reset(); } typedef Head head_type; Head head_; composed_io_executors<void(Tail...)> tail_; }; template <typename Head, typename... Tail> inline composed_io_executors<void(Head, Tail...)> make_composed_io_executors(const Head& head, const Tail&... tail) { return composed_io_executors<void(Head, Tail...)>(head, tail...); } template <typename> struct composed_work; template <> struct composed_work<void()> { typedef composed_io_executors<void()> executors_type; composed_work(const executors_type&) noexcept : head_(system_executor()) { } void reset() { head_.reset(); } typedef system_executor head_type; composed_work_guard<system_executor> head_; }; template <typename Head> struct composed_work<void(Head)> { typedef composed_io_executors<void(Head)> executors_type; explicit composed_work(const executors_type& ex) noexcept : head_(ex.head_) { } void reset() { head_.reset(); } typedef Head head_type; composed_work_guard<Head> head_; }; template <typename Head, typename... Tail> struct composed_work<void(Head, Tail...)> { typedef composed_io_executors<void(Head, Tail...)> executors_type; explicit composed_work(const executors_type& ex) noexcept : head_(ex.head_), tail_(ex.tail_) { } void reset() { head_.reset(); tail_.reset(); } typedef Head head_type; composed_work_guard<Head> head_; composed_work<void(Tail...)> tail_; }; template <typename IoObject> inline typename IoObject::executor_type get_composed_io_executor(IoObject& io_object, enable_if_t< !is_executor<IoObject>::value >* = 0, enable_if_t< !execution::is_executor<IoObject>::value >* = 0) { return io_object.get_executor(); } template <typename Executor> inline const Executor& get_composed_io_executor(const Executor& ex, enable_if_t< is_executor<Executor>::value || execution::is_executor<Executor>::value >* = 0) { return ex; } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_COMPOSED_WORK_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_connect_op.hpp
// // detail/reactive_socket_connect_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_REACTIVE_SOCKET_CONNECT_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_SOCKET_CONNECT_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/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 { class reactive_socket_connect_op_base : public reactor_op { public: reactive_socket_connect_op_base(const boost::system::error_code& success_ec, socket_type socket, func_type complete_func) : reactor_op(success_ec, &reactive_socket_connect_op_base::do_perform, complete_func), socket_(socket) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_connect_op_base* o( static_cast<reactive_socket_connect_op_base*>(base)); status result = socket_ops::non_blocking_connect( o->socket_, o->ec_) ? done : not_done; BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_connect", o->ec_)); return result; } private: socket_type socket_; }; template <typename Handler, typename IoExecutor> class reactive_socket_connect_op : public reactive_socket_connect_op_base { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_connect_op); reactive_socket_connect_op(const boost::system::error_code& success_ec, socket_type socket, Handler& handler, const IoExecutor& io_ex) : reactive_socket_connect_op_base(success_ec, socket, &reactive_socket_connect_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_connect_op* o (static_cast<reactive_socket_connect_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::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; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_connect_op* o (static_cast<reactive_socket_connect_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::binder1<Handler, boost::system::error_code> handler(o->handler_, o->ec_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); 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_CONNECT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_accept_op.hpp
// // detail/reactive_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_REACTIVE_SOCKET_ACCEPT_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_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> #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_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 reactive_socket_accept_op_base : public reactor_op { public: reactive_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) : reactor_op(success_ec, &reactive_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 status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_accept_op_base* o( static_cast<reactive_socket_accept_op_base*>(base)); socket_type new_socket = invalid_socket; status result = socket_ops::non_blocking_accept(o->socket_, o->state_, o->peer_endpoint_ ? o->peer_endpoint_->data() : 0, o->peer_endpoint_ ? &o->addrlen_ : 0, o->ec_, new_socket) ? done : not_done; o->new_socket_.reset(new_socket); BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_accept", o->ec_)); return result; } 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_; std::size_t addrlen_; }; template <typename Socket, typename Protocol, typename Handler, typename IoExecutor> class reactive_socket_accept_op : public reactive_socket_accept_op_base<Socket, Protocol> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_accept_op); reactive_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) : reactive_socket_accept_op_base<Socket, Protocol>( success_ec, socket, state, peer, protocol, peer_endpoint, &reactive_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); reactive_socket_accept_op* o(static_cast<reactive_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; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_accept_op* o(static_cast<reactive_socket_accept_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; // On success, assign new connection to peer socket object. o->do_assign(); 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::binder1<Handler, boost::system::error_code> handler(o->handler_, o->ec_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); w.complete(handler, handler.handler_, io_ex); BOOST_ASIO_HANDLER_INVOCATION_END; } private: Handler handler_; handler_work<Handler, IoExecutor> work_; }; template <typename Protocol, typename PeerIoExecutor, typename Handler, typename IoExecutor> class reactive_socket_move_accept_op : private Protocol::socket::template rebind_executor<PeerIoExecutor>::other, public reactive_socket_accept_op_base< typename Protocol::socket::template rebind_executor<PeerIoExecutor>::other, Protocol> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_move_accept_op); reactive_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), reactive_socket_accept_op_base<peer_socket_type, Protocol>( success_ec, socket, state, *this, protocol, peer_endpoint, &reactive_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); reactive_socket_move_accept_op* o( static_cast<reactive_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; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_move_accept_op* o( static_cast<reactive_socket_move_accept_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; // On success, assign new connection to peer socket object. o->do_assign(); 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::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(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "...")); w.complete(handler, handler.handler_, io_ex); 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 // BOOST_ASIO_DETAIL_REACTIVE_SOCKET_ACCEPT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_object_impl.hpp
// // io_object_impl.hpp // ~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IO_OBJECT_IMPL_HPP #define BOOST_ASIO_DETAIL_IO_OBJECT_IMPL_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <new> #include <boost/asio/detail/config.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/execution/executor.hpp> #include <boost/asio/execution/context.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/query.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename IoObjectService, typename Executor = io_context::executor_type> class io_object_impl { public: // The type of the service that will be used to provide I/O operations. typedef IoObjectService service_type; // The underlying implementation type of I/O object. typedef typename service_type::implementation_type implementation_type; // The type of the executor associated with the object. typedef Executor executor_type; // Construct an I/O object using an executor. explicit io_object_impl(int, const executor_type& ex) : service_(&boost::asio::use_service<IoObjectService>( io_object_impl::get_context(ex))), executor_(ex) { service_->construct(implementation_); } // Construct an I/O object using an execution context. template <typename ExecutionContext> explicit io_object_impl(int, int, ExecutionContext& context) : service_(&boost::asio::use_service<IoObjectService>(context)), executor_(context.get_executor()) { service_->construct(implementation_); } // Move-construct an I/O object. io_object_impl(io_object_impl&& other) : service_(&other.get_service()), executor_(other.get_executor()) { service_->move_construct(implementation_, other.implementation_); } // Perform converting move-construction of an I/O object on the same service. template <typename Executor1> io_object_impl(io_object_impl<IoObjectService, Executor1>&& other) : service_(&other.get_service()), executor_(other.get_executor()) { service_->move_construct(implementation_, other.get_implementation()); } // Perform converting move-construction of an I/O object on another service. template <typename IoObjectService1, typename Executor1> io_object_impl(io_object_impl<IoObjectService1, Executor1>&& other) : service_(&boost::asio::use_service<IoObjectService>( io_object_impl::get_context(other.get_executor()))), executor_(other.get_executor()) { service_->converting_move_construct(implementation_, other.get_service(), other.get_implementation()); } // Destructor. ~io_object_impl() { service_->destroy(implementation_); } // Move-assign an I/O object. io_object_impl& operator=(io_object_impl&& other) { if (this != &other) { service_->move_assign(implementation_, *other.service_, other.implementation_); executor_.~executor_type(); new (&executor_) executor_type(other.executor_); service_ = other.service_; } return *this; } // Get the executor associated with the object. const executor_type& get_executor() noexcept { return executor_; } // Get the service associated with the I/O object. service_type& get_service() { return *service_; } // Get the service associated with the I/O object. const service_type& get_service() const { return *service_; } // Get the underlying implementation of the I/O object. implementation_type& get_implementation() { return implementation_; } // Get the underlying implementation of the I/O object. const implementation_type& get_implementation() const { return implementation_; } private: // Helper function to get an executor's context. template <typename T> static execution_context& get_context(const T& t, enable_if_t<execution::is_executor<T>::value>* = 0) { return boost::asio::query(t, execution::context); } // Helper function to get an executor's context. template <typename T> static execution_context& get_context(const T& t, enable_if_t<!execution::is_executor<T>::value>* = 0) { return t.context(); } // Disallow copying and copy assignment. io_object_impl(const io_object_impl&); io_object_impl& operator=(const io_object_impl&); // The service associated with the I/O object. service_type* service_; // The underlying implementation of the I/O object. implementation_type implementation_; // The associated executor. executor_type executor_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IO_OBJECT_IMPL_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_serial_port_service.hpp
// // detail/posix_serial_port_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_POSIX_SERIAL_PORT_SERVICE_HPP #define BOOST_ASIO_DETAIL_POSIX_SERIAL_PORT_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_SERIAL_PORT) #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #include <string> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/serial_port_base.hpp> #include <boost/asio/detail/descriptor_ops.hpp> #if defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # include <boost/asio/detail/io_uring_descriptor_service.hpp> #else // defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) # include <boost/asio/detail/reactive_descriptor_service.hpp> #endif // defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Extend a descriptor_service to provide serial port support. class posix_serial_port_service : public execution_context_service_base<posix_serial_port_service> { public: #if defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) typedef io_uring_descriptor_service descriptor_service; #else // defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) typedef reactive_descriptor_service descriptor_service; #endif // defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT) // The native type of a serial port. typedef descriptor_service::native_handle_type native_handle_type; // The implementation type of the serial port. typedef descriptor_service::implementation_type implementation_type; BOOST_ASIO_DECL posix_serial_port_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new serial port implementation. void construct(implementation_type& impl) { descriptor_service_.construct(impl); } // Move-construct a new serial port implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) { descriptor_service_.move_construct(impl, other_impl); } // Move-assign from another serial port implementation. void move_assign(implementation_type& impl, posix_serial_port_service& other_service, implementation_type& other_impl) { descriptor_service_.move_assign(impl, other_service.descriptor_service_, other_impl); } // Destroy a serial port implementation. void destroy(implementation_type& impl) { descriptor_service_.destroy(impl); } // Open the serial port using the specified device name. BOOST_ASIO_DECL boost::system::error_code open(implementation_type& impl, const std::string& device, boost::system::error_code& ec); // Assign a native descriptor to a serial port 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); } // Determine whether the serial port is open. bool is_open(const implementation_type& impl) const { return descriptor_service_.is_open(impl); } // Destroy a serial port implementation. boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec) { return descriptor_service_.close(impl, ec); } // Get the native serial port representation. native_handle_type native_handle(implementation_type& impl) { return descriptor_service_.native_handle(impl); } // Cancel all operations associated with the serial port. boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec) { return descriptor_service_.cancel(impl, ec); } // Set an option on the serial port. template <typename SettableSerialPortOption> boost::system::error_code set_option(implementation_type& impl, const SettableSerialPortOption& option, boost::system::error_code& ec) { return do_set_option(impl, &posix_serial_port_service::store_option<SettableSerialPortOption>, &option, ec); } // Get an option from the serial port. template <typename GettableSerialPortOption> boost::system::error_code get_option(const implementation_type& impl, GettableSerialPortOption& option, boost::system::error_code& ec) const { return do_get_option(impl, &posix_serial_port_service::load_option<GettableSerialPortOption>, &option, ec); } // Send a break sequence to the serial port. boost::system::error_code send_break(implementation_type& impl, boost::system::error_code& ec) { int result = ::tcsendbreak(descriptor_service_.native_handle(impl), 0); descriptor_ops::get_last_error(ec, result < 0); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Write the given data. Returns the number of bytes sent. 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); } // Read some data. Returns the number of bytes received. 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 received must be // valid for the lifetime of the asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { descriptor_service_.async_read_some(impl, buffers, handler, io_ex); } private: // Function pointer type for storing a serial port option. typedef boost::system::error_code (*store_function_type)( const void*, termios&, boost::system::error_code&); // Helper function template to store a serial port option. template <typename SettableSerialPortOption> static boost::system::error_code store_option(const void* option, termios& storage, boost::system::error_code& ec) { static_cast<const SettableSerialPortOption*>(option)->store(storage, ec); return ec; } // Helper function to set a serial port option. BOOST_ASIO_DECL boost::system::error_code do_set_option( implementation_type& impl, store_function_type store, const void* option, boost::system::error_code& ec); // Function pointer type for loading a serial port option. typedef boost::system::error_code (*load_function_type)( void*, const termios&, boost::system::error_code&); // Helper function template to load a serial port option. template <typename GettableSerialPortOption> static boost::system::error_code load_option(void* option, const termios& storage, boost::system::error_code& ec) { static_cast<GettableSerialPortOption*>(option)->load(storage, ec); return ec; } // Helper function to get a serial port option. BOOST_ASIO_DECL boost::system::error_code do_get_option( const implementation_type& impl, load_function_type load, void* option, boost::system::error_code& ec) const; // The implementation used for initiating asynchronous operations. descriptor_service descriptor_service_; }; } // 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_serial_port_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT) #endif // BOOST_ASIO_DETAIL_POSIX_SERIAL_PORT_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/thread_group.hpp
// // detail/thread_group.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_THREAD_GROUP_HPP #define BOOST_ASIO_DETAIL_THREAD_GROUP_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/scoped_ptr.hpp> #include <boost/asio/detail/thread.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class thread_group { public: // Constructor initialises an empty thread group. thread_group() : first_(0) { } // Destructor joins any remaining threads in the group. ~thread_group() { join(); } // Create a new thread in the group. template <typename Function> void create_thread(Function f) { first_ = new item(f, first_); } // Create new threads in the group. template <typename Function> void create_threads(Function f, std::size_t num_threads) { for (std::size_t i = 0; i < num_threads; ++i) create_thread(f); } // Wait for all threads in the group to exit. void join() { while (first_) { first_->thread_.join(); item* tmp = first_; first_ = first_->next_; delete tmp; } } // Test whether the group is empty. bool empty() const { return first_ == 0; } private: // Structure used to track a single thread in the group. struct item { template <typename Function> explicit item(Function f, item* next) : thread_(f), next_(next) { } boost::asio::detail::thread thread_; item* next_; }; // The first thread in the group. item* first_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_THREAD_GROUP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_null_buffers_op.hpp
// // detail/io_uring_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_IO_URING_NULL_BUFFERS_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_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> #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/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class io_uring_null_buffers_op : public io_uring_operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_null_buffers_op); io_uring_null_buffers_op(const boost::system::error_code& success_ec, int descriptor, int poll_flags, Handler& handler, const IoExecutor& io_ex) : io_uring_operation(success_ec, &io_uring_null_buffers_op::do_prepare, &io_uring_null_buffers_op::do_perform, &io_uring_null_buffers_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex), descriptor_(descriptor), poll_flags_(poll_flags) { } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_null_buffers_op* o(static_cast<io_uring_null_buffers_op*>(base)); ::io_uring_prep_poll_add(sqe, o->descriptor_, o->poll_flags_); } static bool do_perform(io_uring_operation*, bool after_completion) { return after_completion; } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_null_buffers_op* o(static_cast<io_uring_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_)); 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_; int descriptor_; int poll_flags_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IO_URING_NULL_BUFFERS_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/bind_handler.hpp
// // detail/bind_handler.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_BIND_HANDLER_HPP #define BOOST_ASIO_DETAIL_BIND_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/associator.hpp> #include <boost/asio/detail/handler_cont_helpers.hpp> #include <boost/asio/detail/type_traits.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler> class binder0 { public: template <typename T> binder0(int, T&& handler) : handler_(static_cast<T&&>(handler)) { } binder0(Handler& handler) : handler_(static_cast<Handler&&>(handler)) { } binder0(const binder0& other) : handler_(other.handler_) { } binder0(binder0&& other) : handler_(static_cast<Handler&&>(other.handler_)) { } void operator()() { static_cast<Handler&&>(handler_)(); } void operator()() const { handler_(); } //private: Handler handler_; }; template <typename Handler> inline bool asio_handler_is_continuation( binder0<Handler>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler> inline binder0<decay_t<Handler>> bind_handler( Handler&& handler) { return binder0<decay_t<Handler>>( 0, static_cast<Handler&&>(handler)); } template <typename Handler, typename Arg1> class binder1 { public: template <typename T> binder1(int, T&& handler, const Arg1& arg1) : handler_(static_cast<T&&>(handler)), arg1_(arg1) { } binder1(Handler& handler, const Arg1& arg1) : handler_(static_cast<Handler&&>(handler)), arg1_(arg1) { } binder1(const binder1& other) : handler_(other.handler_), arg1_(other.arg1_) { } binder1(binder1&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<const Arg1&>(arg1_)); } void operator()() const { handler_(arg1_); } //private: Handler handler_; Arg1 arg1_; }; template <typename Handler, typename Arg1> inline bool asio_handler_is_continuation( binder1<Handler, Arg1>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler, typename Arg1> inline binder1<decay_t<Handler>, Arg1> bind_handler( Handler&& handler, const Arg1& arg1) { return binder1<decay_t<Handler>, Arg1>(0, static_cast<Handler&&>(handler), arg1); } template <typename Handler, typename Arg1, typename Arg2> class binder2 { public: template <typename T> binder2(int, T&& handler, const Arg1& arg1, const Arg2& arg2) : handler_(static_cast<T&&>(handler)), arg1_(arg1), arg2_(arg2) { } binder2(Handler& handler, const Arg1& arg1, const Arg2& arg2) : handler_(static_cast<Handler&&>(handler)), arg1_(arg1), arg2_(arg2) { } binder2(const binder2& other) : handler_(other.handler_), arg1_(other.arg1_), arg2_(other.arg2_) { } binder2(binder2&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)), arg2_(static_cast<Arg2&&>(other.arg2_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<const Arg1&>(arg1_), static_cast<const Arg2&>(arg2_)); } void operator()() const { handler_(arg1_, arg2_); } //private: Handler handler_; Arg1 arg1_; Arg2 arg2_; }; template <typename Handler, typename Arg1, typename Arg2> inline bool asio_handler_is_continuation( binder2<Handler, Arg1, Arg2>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler, typename Arg1, typename Arg2> inline binder2<decay_t<Handler>, Arg1, Arg2> bind_handler( Handler&& handler, const Arg1& arg1, const Arg2& arg2) { return binder2<decay_t<Handler>, Arg1, Arg2>(0, static_cast<Handler&&>(handler), arg1, arg2); } template <typename Handler, typename Arg1, typename Arg2, typename Arg3> class binder3 { public: template <typename T> binder3(int, T&& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) : handler_(static_cast<T&&>(handler)), arg1_(arg1), arg2_(arg2), arg3_(arg3) { } binder3(Handler& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) : handler_(static_cast<Handler&&>(handler)), arg1_(arg1), arg2_(arg2), arg3_(arg3) { } binder3(const binder3& other) : handler_(other.handler_), arg1_(other.arg1_), arg2_(other.arg2_), arg3_(other.arg3_) { } binder3(binder3&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)), arg2_(static_cast<Arg2&&>(other.arg2_)), arg3_(static_cast<Arg3&&>(other.arg3_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<const Arg1&>(arg1_), static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_)); } void operator()() const { handler_(arg1_, arg2_, arg3_); } //private: Handler handler_; Arg1 arg1_; Arg2 arg2_; Arg3 arg3_; }; template <typename Handler, typename Arg1, typename Arg2, typename Arg3> inline bool asio_handler_is_continuation( binder3<Handler, Arg1, Arg2, Arg3>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler, typename Arg1, typename Arg2, typename Arg3> inline binder3<decay_t<Handler>, Arg1, Arg2, Arg3> bind_handler( Handler&& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) { return binder3<decay_t<Handler>, Arg1, Arg2, Arg3>(0, static_cast<Handler&&>(handler), arg1, arg2, arg3); } template <typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4> class binder4 { public: template <typename T> binder4(int, T&& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) : handler_(static_cast<T&&>(handler)), arg1_(arg1), arg2_(arg2), arg3_(arg3), arg4_(arg4) { } binder4(Handler& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) : handler_(static_cast<Handler&&>(handler)), arg1_(arg1), arg2_(arg2), arg3_(arg3), arg4_(arg4) { } binder4(const binder4& other) : handler_(other.handler_), arg1_(other.arg1_), arg2_(other.arg2_), arg3_(other.arg3_), arg4_(other.arg4_) { } binder4(binder4&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)), arg2_(static_cast<Arg2&&>(other.arg2_)), arg3_(static_cast<Arg3&&>(other.arg3_)), arg4_(static_cast<Arg4&&>(other.arg4_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<const Arg1&>(arg1_), static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_), static_cast<const Arg4&>(arg4_)); } void operator()() const { handler_(arg1_, arg2_, arg3_, arg4_); } //private: Handler handler_; Arg1 arg1_; Arg2 arg2_; Arg3 arg3_; Arg4 arg4_; }; template <typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4> inline bool asio_handler_is_continuation( binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4> inline binder4<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4> bind_handler(Handler&& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) { return binder4<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4>(0, static_cast<Handler&&>(handler), arg1, arg2, arg3, arg4); } template <typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> class binder5 { public: template <typename T> binder5(int, T&& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) : handler_(static_cast<T&&>(handler)), arg1_(arg1), arg2_(arg2), arg3_(arg3), arg4_(arg4), arg5_(arg5) { } binder5(Handler& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) : handler_(static_cast<Handler&&>(handler)), arg1_(arg1), arg2_(arg2), arg3_(arg3), arg4_(arg4), arg5_(arg5) { } binder5(const binder5& other) : handler_(other.handler_), arg1_(other.arg1_), arg2_(other.arg2_), arg3_(other.arg3_), arg4_(other.arg4_), arg5_(other.arg5_) { } binder5(binder5&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)), arg2_(static_cast<Arg2&&>(other.arg2_)), arg3_(static_cast<Arg3&&>(other.arg3_)), arg4_(static_cast<Arg4&&>(other.arg4_)), arg5_(static_cast<Arg5&&>(other.arg5_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<const Arg1&>(arg1_), static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_), static_cast<const Arg4&>(arg4_), static_cast<const Arg5&>(arg5_)); } void operator()() const { handler_(arg1_, arg2_, arg3_, arg4_, arg5_); } //private: Handler handler_; Arg1 arg1_; Arg2 arg2_; Arg3 arg3_; Arg4 arg4_; Arg5 arg5_; }; template <typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> inline bool asio_handler_is_continuation( binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> inline binder5<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4, Arg5> bind_handler(Handler&& handler, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) { return binder5<decay_t<Handler>, Arg1, Arg2, Arg3, Arg4, Arg5>(0, static_cast<Handler&&>(handler), arg1, arg2, arg3, arg4, arg5); } template <typename Handler, typename Arg1> class move_binder1 { public: move_binder1(int, Handler&& handler, Arg1&& arg1) : handler_(static_cast<Handler&&>(handler)), arg1_(static_cast<Arg1&&>(arg1)) { } move_binder1(move_binder1&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<Arg1&&>(arg1_)); } //private: Handler handler_; Arg1 arg1_; }; template <typename Handler, typename Arg1> inline bool asio_handler_is_continuation( move_binder1<Handler, Arg1>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } template <typename Handler, typename Arg1, typename Arg2> class move_binder2 { public: move_binder2(int, Handler&& handler, const Arg1& arg1, Arg2&& arg2) : handler_(static_cast<Handler&&>(handler)), arg1_(arg1), arg2_(static_cast<Arg2&&>(arg2)) { } move_binder2(move_binder2&& other) : handler_(static_cast<Handler&&>(other.handler_)), arg1_(static_cast<Arg1&&>(other.arg1_)), arg2_(static_cast<Arg2&&>(other.arg2_)) { } void operator()() { static_cast<Handler&&>(handler_)( static_cast<const Arg1&>(arg1_), static_cast<Arg2&&>(arg2_)); } //private: Handler handler_; Arg1 arg1_; Arg2 arg2_; }; template <typename Handler, typename Arg1, typename Arg2> inline bool asio_handler_is_continuation( move_binder2<Handler, Arg1, Arg2>* this_handler) { return boost_asio_handler_cont_helpers::is_continuation( this_handler->handler_); } } // namespace detail template <template <typename, typename> class Associator, typename Handler, typename DefaultCandidate> struct associator<Associator, detail::binder0<Handler>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::binder0<Handler>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::binder0<Handler>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename DefaultCandidate> struct associator<Associator, detail::binder1<Handler, Arg1>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::binder1<Handler, Arg1>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::binder1<Handler, Arg1>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename Arg2, typename DefaultCandidate> struct associator<Associator, detail::binder2<Handler, Arg1, Arg2>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::binder2<Handler, Arg1, Arg2>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::binder2<Handler, Arg1, Arg2>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename Arg2, typename Arg3, typename DefaultCandidate> struct associator<Associator, detail::binder3<Handler, Arg1, Arg2, Arg3>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::binder3<Handler, Arg1, Arg2, Arg3>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::binder3<Handler, Arg1, Arg2, Arg3>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename DefaultCandidate> struct associator<Associator, detail::binder4<Handler, Arg1, Arg2, Arg3, Arg4>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::binder4<Handler, Arg1, Arg2, Arg3, Arg4>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::binder4<Handler, Arg1, Arg2, Arg3, Arg4>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename DefaultCandidate> struct associator<Associator, detail::binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get( const detail::binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename DefaultCandidate> struct associator<Associator, detail::move_binder1<Handler, Arg1>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::move_binder1<Handler, Arg1>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::move_binder1<Handler, Arg1>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; template <template <typename, typename> class Associator, typename Handler, typename Arg1, typename Arg2, typename DefaultCandidate> struct associator<Associator, detail::move_binder2<Handler, Arg1, Arg2>, DefaultCandidate> : Associator<Handler, DefaultCandidate> { static typename Associator<Handler, DefaultCandidate>::type get( const detail::move_binder2<Handler, Arg1, Arg2>& h) noexcept { return Associator<Handler, DefaultCandidate>::get(h.handler_); } static auto get(const detail::move_binder2<Handler, Arg1, Arg2>& h, const DefaultCandidate& c) noexcept -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c)) { return Associator<Handler, DefaultCandidate>::get(h.handler_, c); } }; } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_BIND_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/buffered_stream_storage.hpp
// // detail/buffered_stream_storage.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_BUFFERED_STREAM_STORAGE_HPP #define BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_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/assert.hpp> #include <cstddef> #include <cstring> #include <vector> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class buffered_stream_storage { public: // The type of the bytes stored in the buffer. typedef unsigned char byte_type; // The type used for offsets into the buffer. typedef std::size_t size_type; // Constructor. explicit buffered_stream_storage(std::size_t buffer_capacity) : begin_offset_(0), end_offset_(0), buffer_(buffer_capacity) { } /// Clear the buffer. void clear() { begin_offset_ = 0; end_offset_ = 0; } // Return a pointer to the beginning of the unread data. mutable_buffer data() { return boost::asio::buffer(buffer_) + begin_offset_; } // Return a pointer to the beginning of the unread data. const_buffer data() const { return boost::asio::buffer(buffer_) + begin_offset_; } // Is there no unread data in the buffer. bool empty() const { return begin_offset_ == end_offset_; } // Return the amount of unread data the is in the buffer. size_type size() const { return end_offset_ - begin_offset_; } // Resize the buffer to the specified length. void resize(size_type length) { BOOST_ASIO_ASSERT(length <= capacity()); if (begin_offset_ + length <= capacity()) { end_offset_ = begin_offset_ + length; } else { using namespace std; // For memmove. memmove(&buffer_[0], &buffer_[0] + begin_offset_, size()); end_offset_ = length; begin_offset_ = 0; } } // Return the maximum size for data in the buffer. size_type capacity() const { return buffer_.size(); } // Consume multiple bytes from the beginning of the buffer. void consume(size_type count) { BOOST_ASIO_ASSERT(begin_offset_ + count <= end_offset_); begin_offset_ += count; if (empty()) clear(); } private: // The offset to the beginning of the unread data. size_type begin_offset_; // The offset to the end of the unread data. size_type end_offset_; // The data in the buffer. std::vector<byte_type> buffer_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_BUFFERED_STREAM_STORAGE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_socket_send_op.hpp
// // detail/win_iocp_socket_send_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SEND_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_SEND_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/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class win_iocp_socket_send_op : public operation { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_send_op); win_iocp_socket_send_op(socket_ops::weak_cancel_token_type cancel_token, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : operation(&win_iocp_socket_send_op::do_complete), cancel_token_(cancel_token), buffers_(buffers), 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_send_op* o(static_cast<win_iocp_socket_send_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::const_buffer, ConstBufferSequence>::validate(o->buffers_); } #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) socket_ops::complete_iocp_send(o->cancel_token_, ec); 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_; ConstBufferSequence buffers_; 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_SEND_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/timer_queue_ptime.hpp
// // detail/timer_queue_ptime.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP #define BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_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_DATE_TIME) #include <boost/asio/time_traits.hpp> #include <boost/asio/detail/timer_queue.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct forwarding_posix_time_traits : time_traits<boost::posix_time::ptime> {}; // Template specialisation for the commonly used instantation. template <> class timer_queue<time_traits<boost::posix_time::ptime>> : public timer_queue_base { public: // The time type. typedef boost::posix_time::ptime time_type; // The duration type. typedef boost::posix_time::time_duration duration_type; // Per-timer data. typedef timer_queue<forwarding_posix_time_traits>::per_timer_data per_timer_data; // Constructor. BOOST_ASIO_DECL timer_queue(); // Destructor. BOOST_ASIO_DECL virtual ~timer_queue(); // Add a new timer to the queue. Returns true if this is the timer that is // earliest in the queue, in which case the reactor's event demultiplexing // function call may need to be interrupted and restarted. BOOST_ASIO_DECL bool enqueue_timer(const time_type& time, per_timer_data& timer, wait_op* op); // Whether there are no timers in the queue. BOOST_ASIO_DECL virtual bool empty() const; // Get the time for the timer that is earliest in the queue. BOOST_ASIO_DECL virtual long wait_duration_msec(long max_duration) const; // Get the time for the timer that is earliest in the queue. BOOST_ASIO_DECL virtual long wait_duration_usec(long max_duration) const; // Dequeue all timers not later than the current time. BOOST_ASIO_DECL virtual void get_ready_timers(op_queue<operation>& ops); // Dequeue all timers. BOOST_ASIO_DECL virtual void get_all_timers(op_queue<operation>& ops); // Cancel and dequeue operations for the given timer. BOOST_ASIO_DECL std::size_t cancel_timer( per_timer_data& timer, op_queue<operation>& ops, std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)()); // Cancel and dequeue operations for the given timer and key. BOOST_ASIO_DECL void cancel_timer_by_key(per_timer_data* timer, op_queue<operation>& ops, void* cancellation_key); // Move operations from one timer to another, empty timer. BOOST_ASIO_DECL void move_timer(per_timer_data& target, per_timer_data& source); private: timer_queue<forwarding_posix_time_traits> impl_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/timer_queue_ptime.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/noncopyable.hpp
// // detail/noncopyable.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_NONCOPYABLE_HPP #define BOOST_ASIO_DETAIL_NONCOPYABLE_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 { class noncopyable { protected: noncopyable() {} ~noncopyable() {} private: noncopyable(const noncopyable&); const noncopyable& operator=(const noncopyable&); }; } // namespace detail using boost::asio::detail::noncopyable; } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_NONCOPYABLE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_send_op.hpp
// // detail/io_uring_socket_send_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IO_URING_SOCKET_SEND_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_SEND_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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 ConstBufferSequence> class io_uring_socket_send_op_base : public io_uring_operation { public: io_uring_socket_send_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const ConstBufferSequence& buffers, socket_base::message_flags flags, func_type complete_func) : io_uring_operation(success_ec, &io_uring_socket_send_op_base::do_prepare, &io_uring_socket_send_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), flags_(flags), bufs_(buffers), msghdr_() { msghdr_.msg_iov = bufs_.buffers(); msghdr_.msg_iovlen = static_cast<int>(bufs_.count()); } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_send_op_base* o( static_cast<io_uring_socket_send_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { ::io_uring_prep_poll_add(sqe, o->socket_, POLLOUT); } else if (o->bufs_.is_single_buffer && o->bufs_.is_registered_buffer && o->flags_ == 0) { ::io_uring_prep_write_fixed(sqe, o->socket_, o->bufs_.buffers()->iov_base, o->bufs_.buffers()->iov_len, 0, o->bufs_.registered_id().native_handle()); } else { ::io_uring_prep_sendmsg(sqe, o->socket_, &o->msghdr_, o->flags_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_send_op_base* o( static_cast<io_uring_socket_send_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { if (o->bufs_.is_single_buffer) { return socket_ops::non_blocking_send1(o->socket_, o->bufs_.first(o->buffers_).data(), o->bufs_.first(o->buffers_).size(), o->flags_, o->ec_, o->bytes_transferred_); } else { return socket_ops::non_blocking_send(o->socket_, o->bufs_.buffers(), o->bufs_.count(), o->flags_, o->ec_, o->bytes_transferred_); } } if (o->ec_ && o->ec_ == 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_; ConstBufferSequence buffers_; socket_base::message_flags flags_; buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_; msghdr msghdr_; }; template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class io_uring_socket_send_op : public io_uring_socket_send_op_base<ConstBufferSequence> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_send_op); io_uring_socket_send_op(const boost::system::error_code& success_ec, int socket, socket_ops::state_type state, const ConstBufferSequence& buffers, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : io_uring_socket_send_op_base<ConstBufferSequence>(success_ec, socket, state, buffers, flags, &io_uring_socket_send_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_send_op* o (static_cast<io_uring_socket_send_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_SEND_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/op_queue.hpp
// // detail/op_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_OP_QUEUE_HPP #define BOOST_ASIO_DETAIL_OP_QUEUE_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 Operation> class op_queue; class op_queue_access { public: template <typename Operation> static Operation* next(Operation* o) { return static_cast<Operation*>(o->next_); } template <typename Operation1, typename Operation2> static void next(Operation1*& o1, Operation2* o2) { o1->next_ = o2; } template <typename Operation> static void destroy(Operation* o) { o->destroy(); } template <typename Operation> static Operation*& front(op_queue<Operation>& q) { return q.front_; } template <typename Operation> static Operation*& back(op_queue<Operation>& q) { return q.back_; } }; template <typename Operation> class op_queue : private noncopyable { public: // Constructor. op_queue() : front_(0), back_(0) { } // Destructor destroys all operations. ~op_queue() { while (Operation* op = front_) { pop(); op_queue_access::destroy(op); } } // Get the operation at the front of the queue. Operation* front() { return front_; } // Pop an operation from the front of the queue. void pop() { if (front_) { Operation* tmp = front_; front_ = op_queue_access::next(front_); if (front_ == 0) back_ = 0; op_queue_access::next(tmp, static_cast<Operation*>(0)); } } // Push an operation on to the back of the queue. void push(Operation* h) { op_queue_access::next(h, static_cast<Operation*>(0)); if (back_) { op_queue_access::next(back_, h); back_ = h; } else { front_ = back_ = h; } } // Push all operations from another queue on to the back of the queue. The // source queue may contain operations of a derived type. template <typename OtherOperation> void push(op_queue<OtherOperation>& q) { if (Operation* other_front = op_queue_access::front(q)) { if (back_) op_queue_access::next(back_, other_front); else front_ = other_front; back_ = op_queue_access::back(q); op_queue_access::front(q) = 0; op_queue_access::back(q) = 0; } } // Whether the queue is empty. bool empty() const { return front_ == 0; } // Test whether an operation is already enqueued. bool is_enqueued(Operation* o) const { return op_queue_access::next(o) != 0 || back_ == o; } private: friend class op_queue_access; // The front of the queue. Operation* front_; // The back of the queue. Operation* back_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_OP_QUEUE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_wait_op.hpp
// // detail/win_iocp_wait_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_WAIT_OP_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_WAIT_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/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_wait_op : public reactor_op { public: BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_wait_op); win_iocp_wait_op(socket_ops::weak_cancel_token_type cancel_token, Handler& handler, const IoExecutor& io_ex) : reactor_op(boost::system::error_code(), &win_iocp_wait_op::do_perform, &win_iocp_wait_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_wait_op* o(static_cast<win_iocp_wait_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::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: 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_WAIT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_wait_op.hpp
// // detail/reactive_wait_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_REACTIVE_WAIT_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_WAIT_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/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/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class reactive_wait_op : public reactor_op { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_wait_op); reactive_wait_op(const boost::system::error_code& success_ec, Handler& handler, const IoExecutor& io_ex) : reactor_op(success_ec, &reactive_wait_op::do_perform, &reactive_wait_op::do_complete), 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& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_wait_op* o(static_cast<reactive_wait_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_)); // 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; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_wait_op* o(static_cast<reactive_wait_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_)); // 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(); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_)); 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_WAIT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/signal_op.hpp
// // detail/signal_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_SIGNAL_OP_HPP #define BOOST_ASIO_DETAIL_SIGNAL_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 signal_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 signal number to be passed to the completion handler. int signal_number_; protected: signal_op(func_type func) : operation(func), cancellation_key_(0), signal_number_(0) { } }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_SIGNAL_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winsock_init.hpp
// // detail/winsock_init.hpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WINSOCK_INIT_HPP #define BOOST_ASIO_DETAIL_WINSOCK_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 <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class winsock_init_base { protected: // Structure to track result of initialisation and number of uses. POD is used // to ensure that the values are zero-initialised prior to any code being run. struct data { long init_count_; long result_; }; BOOST_ASIO_DECL static void startup(data& d, unsigned char major, unsigned char minor); BOOST_ASIO_DECL static void manual_startup(data& d); BOOST_ASIO_DECL static void cleanup(data& d); BOOST_ASIO_DECL static void manual_cleanup(data& d); BOOST_ASIO_DECL static void throw_on_error(data& d); }; template <int Major = 2, int Minor = 2> class winsock_init : private winsock_init_base { public: winsock_init(bool allow_throw = true) { startup(data_, Major, Minor); if (allow_throw) throw_on_error(data_); } winsock_init(const winsock_init&) { startup(data_, Major, Minor); throw_on_error(data_); } ~winsock_init() { cleanup(data_); } // This class may be used to indicate that user code will manage Winsock // initialisation and cleanup. This may be required in the case of a DLL, for // example, where it is not safe to initialise Winsock from global object // constructors. // // To prevent asio from initialising Winsock, the object must be constructed // before any Asio's own global objects. With MSVC, this may be accomplished // by adding the following code to the DLL: // // #pragma warning(push) // #pragma warning(disable:4073) // #pragma init_seg(lib) // boost::asio::detail::winsock_init<>::manual manual_winsock_init; // #pragma warning(pop) class manual { public: manual() { manual_startup(data_); } manual(const manual&) { manual_startup(data_); } ~manual() { manual_cleanup(data_); } }; private: friend class manual; static data data_; }; template <int Major, int Minor> winsock_init_base::data winsock_init<Major, Minor>::data_; // Static variable to ensure that winsock is initialised before main, and // therefore before any other threads can get started. static const winsock_init<>& winsock_init_instance = winsock_init<>(false); } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/detail/impl/winsock_init.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_WINSOCK_INIT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/resolve_op.hpp
// // detail/resolve_op.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_RESOLVE_OP_HPP #define BOOST_ASIO_DETAIL_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> #include <boost/asio/error.hpp> #include <boost/asio/detail/operation.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class resolve_op : public operation { public: // The error code to be passed to the completion handler. boost::system::error_code ec_; protected: resolve_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_RESOLVE_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/posix_signal_blocker.hpp
// // detail/posix_signal_blocker.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP #define BOOST_ASIO_DETAIL_POSIX_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_PTHREADS) #include <csignal> #include <pthread.h> #include <signal.h> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class posix_signal_blocker : private noncopyable { public: // Constructor blocks all signals for the calling thread. posix_signal_blocker() : blocked_(false) { sigset_t new_mask; sigfillset(&new_mask); blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0); } // Destructor restores the previous signal mask. ~posix_signal_blocker() { if (blocked_) pthread_sigmask(SIG_SETMASK, &old_mask_, 0); } // Block all signals for the calling thread. void block() { if (!blocked_) { sigset_t new_mask; sigfillset(&new_mask); blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0); } } // Restore the previous signal mask. void unblock() { if (blocked_) blocked_ = (pthread_sigmask(SIG_SETMASK, &old_mask_, 0) != 0); } private: // Have signals been blocked. bool blocked_; // The previous signal mask. sigset_t old_mask_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_PTHREADS) #endif // BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/utility.hpp
// // detail/utility.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_UTILITY_HPP #define BOOST_ASIO_DETAIL_UTILITY_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <utility> namespace boost { namespace asio { namespace detail { #if defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE) using std::index_sequence; using std::index_sequence_for; using std::make_index_sequence; #else // defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE) template <std::size_t...> struct index_sequence { }; template <typename T, typename U> struct join_index_sequences; template <std::size_t... I, std::size_t... J> struct join_index_sequences<index_sequence<I...>, index_sequence<J...>> { using type = index_sequence<I..., J...>; }; template <std::size_t First, std::size_t Last> struct index_pack : join_index_sequences< typename index_pack<First, First + (Last - First + 1) / 2 - 1>::type, typename index_pack<First + (Last - First + 1) / 2, Last>::type > { }; template <std::size_t N> struct index_pack<N, N> { using type = index_sequence<N>; }; template <std::size_t Begin, std::size_t End> struct index_range : index_pack<Begin, End - 1> { }; template <std::size_t N> struct index_range<N, N> { using type = index_sequence<>; }; template <typename... T> using index_sequence_for = typename index_range<0, sizeof...(T)>::type; template <std::size_t N> using make_index_sequence = typename index_range<0, N>::type; #endif // defined(BOOST_ASIO_HAS_STD_INDEX_SEQUENCE) } // namespace detail } // namespace asio } // namespace boost #endif // BOOST_ASIO_DETAIL_UTILITY_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/initiate_defer.hpp
// // detail/initiate_defer.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_INITIATE_DEFER_HPP #define BOOST_ASIO_DETAIL_INITIATE_DEFER_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/detail/work_dispatcher.hpp> #include <boost/asio/execution/allocator.hpp> #include <boost/asio/execution/blocking.hpp> #include <boost/asio/execution/relationship.hpp> #include <boost/asio/prefer.hpp> #include <boost/asio/require.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class initiate_defer { public: template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< associated_executor_t<decay_t<CompletionHandler>> >::value >* = 0) const { associated_executor_t<decay_t<CompletionHandler>> ex( (get_associated_executor)(handler)); associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); boost::asio::prefer( boost::asio::require(ex, execution::blocking.never), execution::relationship.continuation, execution::allocator(alloc) ).execute( boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler))); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< associated_executor_t<decay_t<CompletionHandler>> >::value >* = 0) const { associated_executor_t<decay_t<CompletionHandler>> ex( (get_associated_executor)(handler)); associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); ex.defer(boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler)), alloc); } }; template <typename Executor> class initiate_defer_with_executor { public: typedef Executor executor_type; explicit initiate_defer_with_executor(const Executor& ex) : ex_(ex) { } executor_type get_executor() const noexcept { return ex_; } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< !detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); boost::asio::prefer( boost::asio::require(ex_, execution::blocking.never), execution::relationship.continuation, execution::allocator(alloc) ).execute( boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler))); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { typedef decay_t<CompletionHandler> handler_t; typedef associated_executor_t<handler_t, Executor> handler_ex_t; handler_ex_t handler_ex((get_associated_executor)(handler, ex_)); associated_allocator_t<handler_t> alloc( (get_associated_allocator)(handler)); boost::asio::prefer( boost::asio::require(ex_, execution::blocking.never), execution::relationship.continuation, execution::allocator(alloc) ).execute( detail::work_dispatcher<handler_t, handler_ex_t>( static_cast<CompletionHandler&&>(handler), handler_ex)); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< !detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { associated_allocator_t<decay_t<CompletionHandler>> alloc( (get_associated_allocator)(handler)); ex_.defer(boost::asio::detail::bind_handler( static_cast<CompletionHandler&&>(handler)), alloc); } template <typename CompletionHandler> void operator()(CompletionHandler&& handler, enable_if_t< !execution::is_executor< conditional_t<true, executor_type, CompletionHandler> >::value >* = 0, enable_if_t< detail::is_work_dispatcher_required< decay_t<CompletionHandler>, Executor >::value >* = 0) const { typedef decay_t<CompletionHandler> handler_t; typedef associated_executor_t<handler_t, Executor> handler_ex_t; handler_ex_t handler_ex((get_associated_executor)(handler, ex_)); associated_allocator_t<handler_t> alloc( (get_associated_allocator)(handler)); ex_.defer(detail::work_dispatcher<handler_t, handler_ex_t>( static_cast<CompletionHandler&&>(handler), handler_ex), alloc); } private: Executor ex_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_INITIATE_DEFER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_serial_port_service.hpp
// // detail/win_iocp_serial_port_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2008 Rep Invariant Systems, Inc. ([email protected]) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SERIAL_PORT_SERVICE_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SERIAL_PORT_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_SERIAL_PORT) #include <string> #include <boost/asio/error.hpp> #include <boost/asio/execution_context.hpp> #include <boost/asio/detail/win_iocp_handle_service.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { // Extend win_iocp_handle_service to provide serial port support. class win_iocp_serial_port_service : public execution_context_service_base<win_iocp_serial_port_service> { public: // The native type of a serial port. typedef win_iocp_handle_service::native_handle_type native_handle_type; // The implementation type of the serial port. typedef win_iocp_handle_service::implementation_type implementation_type; // Constructor. BOOST_ASIO_DECL win_iocp_serial_port_service(execution_context& context); // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown(); // Construct a new serial port implementation. void construct(implementation_type& impl) { handle_service_.construct(impl); } // Move-construct a new serial port implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) { handle_service_.move_construct(impl, other_impl); } // Move-assign from another serial port implementation. void move_assign(implementation_type& impl, win_iocp_serial_port_service& other_service, implementation_type& other_impl) { handle_service_.move_assign(impl, other_service.handle_service_, other_impl); } // Destroy a serial port implementation. void destroy(implementation_type& impl) { handle_service_.destroy(impl); } // Open the serial port using the specified device name. BOOST_ASIO_DECL boost::system::error_code open(implementation_type& impl, const std::string& device, boost::system::error_code& ec); // Assign a native handle to a serial port implementation. boost::system::error_code assign(implementation_type& impl, const native_handle_type& handle, boost::system::error_code& ec) { return handle_service_.assign(impl, handle, ec); } // Determine whether the serial port is open. bool is_open(const implementation_type& impl) const { return handle_service_.is_open(impl); } // Destroy a serial port implementation. boost::system::error_code close(implementation_type& impl, boost::system::error_code& ec) { return handle_service_.close(impl, ec); } // Get the native serial port representation. native_handle_type native_handle(implementation_type& impl) { return handle_service_.native_handle(impl); } // Cancel all operations associated with the handle. boost::system::error_code cancel(implementation_type& impl, boost::system::error_code& ec) { return handle_service_.cancel(impl, ec); } // Set an option on the serial port. template <typename SettableSerialPortOption> boost::system::error_code set_option(implementation_type& impl, const SettableSerialPortOption& option, boost::system::error_code& ec) { return do_set_option(impl, &win_iocp_serial_port_service::store_option<SettableSerialPortOption>, &option, ec); } // Get an option from the serial port. template <typename GettableSerialPortOption> boost::system::error_code get_option(const implementation_type& impl, GettableSerialPortOption& option, boost::system::error_code& ec) const { return do_get_option(impl, &win_iocp_serial_port_service::load_option<GettableSerialPortOption>, &option, ec); } // Send a break sequence to the serial port. boost::system::error_code send_break(implementation_type&, boost::system::error_code& ec) { ec = boost::asio::error::operation_not_supported; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Write the given data. Returns the number of bytes sent. template <typename ConstBufferSequence> size_t write_some(implementation_type& impl, const ConstBufferSequence& buffers, boost::system::error_code& ec) { return handle_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) { handle_service_.async_write_some(impl, buffers, handler, io_ex); } // Read some data. Returns the number of bytes received. template <typename MutableBufferSequence> size_t read_some(implementation_type& impl, const MutableBufferSequence& buffers, boost::system::error_code& ec) { return handle_service_.read_some(impl, buffers, ec); } // Start an asynchronous read. The buffer for the data being received must be // valid for the lifetime of the asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_read_some(implementation_type& impl, const MutableBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) { handle_service_.async_read_some(impl, buffers, handler, io_ex); } private: // Function pointer type for storing a serial port option. typedef boost::system::error_code (*store_function_type)( const void*, ::DCB&, boost::system::error_code&); // Helper function template to store a serial port option. template <typename SettableSerialPortOption> static boost::system::error_code store_option(const void* option, ::DCB& storage, boost::system::error_code& ec) { static_cast<const SettableSerialPortOption*>(option)->store(storage, ec); return ec; } // Helper function to set a serial port option. BOOST_ASIO_DECL boost::system::error_code do_set_option( implementation_type& impl, store_function_type store, const void* option, boost::system::error_code& ec); // Function pointer type for loading a serial port option. typedef boost::system::error_code (*load_function_type)( void*, const ::DCB&, boost::system::error_code&); // Helper function template to load a serial port option. template <typename GettableSerialPortOption> static boost::system::error_code load_option(void* option, const ::DCB& storage, boost::system::error_code& ec) { static_cast<GettableSerialPortOption*>(option)->load(storage, ec); return ec; } // Helper function to get a serial port option. BOOST_ASIO_DECL boost::system::error_code do_get_option( const implementation_type& impl, load_function_type load, void* option, boost::system::error_code& ec) const; // The implementation used for initiating asynchronous operations. win_iocp_handle_service handle_service_; }; } // 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_serial_port_service.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_HAS_IOCP) && defined(BOOST_ASIO_HAS_SERIAL_PORT) #endif // BOOST_ASIO_DETAIL_WIN_IOCP_SERIAL_PORT_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/keyword_tss_ptr.hpp
// // detail/keyword_tss_ptr.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_KEYWORD_TSS_PTR_HPP #define BOOST_ASIO_DETAIL_KEYWORD_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_THREAD_KEYWORD_EXTENSION) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename T> class keyword_tss_ptr : private noncopyable { public: // Constructor. keyword_tss_ptr() { } // Destructor. ~keyword_tss_ptr() { } // Get the value. operator T*() const { return value_; } // Set the value. void operator=(T* value) { value_ = value; } private: static BOOST_ASIO_THREAD_KEYWORD T* value_; }; template <typename T> BOOST_ASIO_THREAD_KEYWORD T* keyword_tss_ptr<T>::value_; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_THREAD_KEYWORD_EXTENSION) #endif // BOOST_ASIO_DETAIL_KEYWORD_TSS_PTR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_sendto_op.hpp
// // detail/io_uring_socket_sendto_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IO_URING_SOCKET_SENDTO_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_SENDTO_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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 ConstBufferSequence, typename Endpoint> class io_uring_socket_sendto_op_base : public io_uring_operation { public: io_uring_socket_sendto_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const ConstBufferSequence& buffers, const Endpoint& endpoint, socket_base::message_flags flags, func_type complete_func) : io_uring_operation(success_ec, &io_uring_socket_sendto_op_base::do_prepare, &io_uring_socket_sendto_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), destination_(endpoint), flags_(flags), bufs_(buffers), msghdr_() { msghdr_.msg_iov = bufs_.buffers(); msghdr_.msg_iovlen = static_cast<int>(bufs_.count()); msghdr_.msg_name = static_cast<sockaddr*>( static_cast<void*>(destination_.data())); msghdr_.msg_namelen = destination_.size(); } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_sendto_op_base* o( static_cast<io_uring_socket_sendto_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { ::io_uring_prep_poll_add(sqe, o->socket_, POLLOUT); } else { ::io_uring_prep_sendmsg(sqe, o->socket_, &o->msghdr_, o->flags_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_sendto_op_base* o( static_cast<io_uring_socket_sendto_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { if (o->bufs_.is_single_buffer) { return socket_ops::non_blocking_sendto1(o->socket_, o->bufs_.first(o->buffers_).data(), o->bufs_.first(o->buffers_).size(), o->flags_, o->destination_.data(), o->destination_.size(), o->ec_, o->bytes_transferred_); } else { return socket_ops::non_blocking_sendto(o->socket_, o->bufs_.buffers(), o->bufs_.count(), o->flags_, o->destination_.data(), o->destination_.size(), o->ec_, o->bytes_transferred_); } } if (o->ec_ && o->ec_ == 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_; ConstBufferSequence buffers_; Endpoint destination_; socket_base::message_flags flags_; buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_; msghdr msghdr_; }; template <typename ConstBufferSequence, typename Endpoint, typename Handler, typename IoExecutor> class io_uring_socket_sendto_op : public io_uring_socket_sendto_op_base<ConstBufferSequence, Endpoint> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_sendto_op); io_uring_socket_sendto_op(const boost::system::error_code& success_ec, int socket, socket_ops::state_type state, const ConstBufferSequence& buffers, const Endpoint& endpoint, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : io_uring_socket_sendto_op_base<ConstBufferSequence, Endpoint>( success_ec, socket, state, buffers, endpoint, flags, &io_uring_socket_sendto_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_sendto_op* o (static_cast<io_uring_socket_sendto_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_SENDTO_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/local_free_on_block_exit.hpp
// // detail/local_free_on_block_exit.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_LOCAL_FREE_ON_BLOCK_EXIT_HPP #define BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_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__) #if !defined(BOOST_ASIO_WINDOWS_APP) #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 { class local_free_on_block_exit : private noncopyable { public: // Constructor blocks all signals for the calling thread. explicit local_free_on_block_exit(void* p) : p_(p) { } // Destructor restores the previous signal mask. ~local_free_on_block_exit() { ::LocalFree(p_); } private: void* p_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // !defined(BOOST_ASIO_WINDOWS_APP) #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) #endif // BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/resolve_endpoint_op.hpp
// // detail/resolve_endpoint_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_RESOLVER_ENDPOINT_OP_HPP #define BOOST_ASIO_DETAIL_RESOLVER_ENDPOINT_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/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/resolve_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/error.hpp> #include <boost/asio/ip/basic_resolver_results.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, typename Handler, typename IoExecutor> class resolve_endpoint_op : public resolve_op { public: BOOST_ASIO_DEFINE_HANDLER_PTR(resolve_endpoint_op); typedef typename Protocol::endpoint endpoint_type; typedef boost::asio::ip::basic_resolver_results<Protocol> results_type; #if defined(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context scheduler_impl; #else typedef class scheduler scheduler_impl; #endif resolve_endpoint_op(socket_ops::weak_cancel_token_type cancel_token, const endpoint_type& endpoint, scheduler_impl& sched, Handler& handler, const IoExecutor& io_ex) : resolve_op(&resolve_endpoint_op::do_complete), cancel_token_(cancel_token), endpoint_(endpoint), scheduler_(sched), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); resolve_endpoint_op* o(static_cast<resolve_endpoint_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; if (owner && owner != &o->scheduler_) { // The operation is being run on the worker io_context. Time to perform // the resolver operation. // Perform the blocking endpoint resolution operation. char host_name[NI_MAXHOST] = ""; char service_name[NI_MAXSERV] = ""; socket_ops::background_getnameinfo(o->cancel_token_, o->endpoint_.data(), o->endpoint_.size(), host_name, NI_MAXHOST, service_name, NI_MAXSERV, o->endpoint_.protocol().type(), o->ec_); o->results_ = results_type::create(o->endpoint_, host_name, service_name); // Pass operation back to main io_context for completion. o->scheduler_.post_deferred_completion(o); p.v = p.p = 0; } else { // The operation has been returned to the main io_context. The completion // handler is ready to be delivered. 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_)); // 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_, o->results_); p.h = boost::asio::detail::addressof(handler.handler_); p.reset(); 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: socket_ops::weak_cancel_token_type cancel_token_; endpoint_type endpoint_; scheduler_impl& scheduler_; Handler handler_; handler_work<Handler, IoExecutor> work_; results_type results_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_RESOLVER_ENDPOINT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/non_const_lvalue.hpp
// // detail/non_const_lvalue.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_NON_CONST_LVALUE_HPP #define BOOST_ASIO_DETAIL_NON_CONST_LVALUE_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 { template <typename T> struct non_const_lvalue { explicit non_const_lvalue(T& t) : value(static_cast<conditional_t< is_same<T, decay_t<T>>::value, decay_t<T>&, T&&>>(t)) { } conditional_t<is_same<T, decay_t<T>>::value, decay_t<T>&, decay_t<T>> value; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_NON_CONST_LVALUE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_descriptor_write_at_op.hpp
// // detail/io_uring_descriptor_write_at_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_AT_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_DESCRIPTOR_WRITE_AT_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_at_op_base : public io_uring_operation { public: io_uring_descriptor_write_at_op_base( const boost::system::error_code& success_ec, int descriptor, descriptor_ops::state_type state, uint64_t offset, const ConstBufferSequence& buffers, func_type complete_func) : io_uring_operation(success_ec, &io_uring_descriptor_write_at_op_base::do_prepare, &io_uring_descriptor_write_at_op_base::do_perform, complete_func), descriptor_(descriptor), state_(state), offset_(offset), 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_at_op_base* o( static_cast<io_uring_descriptor_write_at_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, o->offset_, o->bufs_.registered_id().native_handle()); } else { ::io_uring_prep_writev(sqe, o->descriptor_, o->bufs_.buffers(), o->bufs_.count(), o->offset_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_descriptor_write_at_op_base* o( static_cast<io_uring_descriptor_write_at_op_base*>(base)); if ((o->state_ & descriptor_ops::internal_non_blocking) != 0) { if (o->bufs_.is_single_buffer) { return descriptor_ops::non_blocking_write_at1(o->descriptor_, o->offset_, o->bufs_.first(o->buffers_).data(), o->bufs_.first(o->buffers_).size(), o->ec_, o->bytes_transferred_); } else { return descriptor_ops::non_blocking_write_at(o->descriptor_, o->offset_, 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_; uint64_t offset_; ConstBufferSequence buffers_; buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs_; }; template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class io_uring_descriptor_write_at_op : public io_uring_descriptor_write_at_op_base<ConstBufferSequence> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_descriptor_write_at_op); io_uring_descriptor_write_at_op(const boost::system::error_code& success_ec, int descriptor, descriptor_ops::state_type state, uint64_t offset, const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : io_uring_descriptor_write_at_op_base<ConstBufferSequence>( success_ec, descriptor, state, offset, buffers, &io_uring_descriptor_write_at_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_at_op* o (static_cast<io_uring_descriptor_write_at_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_AT_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_iocp_socket_service.hpp
// // detail/win_iocp_socket_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_SOCKET_SERVICE_HPP #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_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) #include <cstring> #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_accept_op.hpp> #include <boost/asio/detail/win_iocp_socket_connect_op.hpp> #include <boost/asio/detail/win_iocp_socket_recvfrom_op.hpp> #include <boost/asio/detail/win_iocp_socket_send_op.hpp> #include <boost/asio/detail/win_iocp_socket_service_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Protocol> class win_iocp_socket_service : public execution_context_service_base<win_iocp_socket_service<Protocol>>, public win_iocp_socket_service_base { public: // The protocol type. typedef Protocol protocol_type; // The endpoint type. typedef typename Protocol::endpoint endpoint_type; // The native type of a socket. class native_handle_type { public: native_handle_type(socket_type s) : socket_(s), have_remote_endpoint_(false) { } native_handle_type(socket_type s, const endpoint_type& ep) : socket_(s), have_remote_endpoint_(true), remote_endpoint_(ep) { } void operator=(socket_type s) { socket_ = s; have_remote_endpoint_ = false; remote_endpoint_ = endpoint_type(); } operator socket_type() const { return socket_; } bool have_remote_endpoint() const { return have_remote_endpoint_; } endpoint_type remote_endpoint() const { return remote_endpoint_; } private: socket_type socket_; bool have_remote_endpoint_; endpoint_type remote_endpoint_; }; // The implementation type of the socket. struct implementation_type : win_iocp_socket_service_base::base_implementation_type { // Default constructor. implementation_type() : protocol_(endpoint_type().protocol()), have_remote_endpoint_(false), remote_endpoint_() { } // The protocol associated with the socket. protocol_type protocol_; // Whether we have a cached remote endpoint. bool have_remote_endpoint_; // A cached remote endpoint. endpoint_type remote_endpoint_; }; // Constructor. win_iocp_socket_service(execution_context& context) : execution_context_service_base< win_iocp_socket_service<Protocol>>(context), win_iocp_socket_service_base(context) { } // Destroy all user-defined handler objects owned by the service. void shutdown() { this->base_shutdown(); } // Move-construct a new socket implementation. void move_construct(implementation_type& impl, implementation_type& other_impl) noexcept { this->base_move_construct(impl, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); impl.have_remote_endpoint_ = other_impl.have_remote_endpoint_; other_impl.have_remote_endpoint_ = false; impl.remote_endpoint_ = other_impl.remote_endpoint_; other_impl.remote_endpoint_ = endpoint_type(); } // Move-assign from another socket implementation. void move_assign(implementation_type& impl, win_iocp_socket_service_base& other_service, implementation_type& other_impl) { this->base_move_assign(impl, other_service, other_impl); impl.protocol_ = other_impl.protocol_; other_impl.protocol_ = endpoint_type().protocol(); impl.have_remote_endpoint_ = other_impl.have_remote_endpoint_; other_impl.have_remote_endpoint_ = false; impl.remote_endpoint_ = other_impl.remote_endpoint_; other_impl.remote_endpoint_ = endpoint_type(); } // Move-construct a new socket implementation from another protocol type. template <typename Protocol1> void converting_move_construct(implementation_type& impl, win_iocp_socket_service<Protocol1>&, typename win_iocp_socket_service< Protocol1>::implementation_type& other_impl) { this->base_move_construct(impl, other_impl); impl.protocol_ = protocol_type(other_impl.protocol_); other_impl.protocol_ = typename Protocol1::endpoint().protocol(); impl.have_remote_endpoint_ = other_impl.have_remote_endpoint_; other_impl.have_remote_endpoint_ = false; impl.remote_endpoint_ = other_impl.remote_endpoint_; other_impl.remote_endpoint_ = typename Protocol1::endpoint(); } // Open a new socket implementation. boost::system::error_code open(implementation_type& impl, const protocol_type& protocol, boost::system::error_code& ec) { if (!do_open(impl, protocol.family(), protocol.type(), protocol.protocol(), ec)) { impl.protocol_ = protocol; impl.have_remote_endpoint_ = false; impl.remote_endpoint_ = endpoint_type(); } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Assign a native socket to a socket implementation. boost::system::error_code assign(implementation_type& impl, const protocol_type& protocol, const native_handle_type& native_socket, boost::system::error_code& ec) { if (!do_assign(impl, protocol.type(), native_socket, ec)) { impl.protocol_ = protocol; impl.have_remote_endpoint_ = native_socket.have_remote_endpoint(); impl.remote_endpoint_ = native_socket.remote_endpoint(); } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Get the native socket representation. native_handle_type native_handle(implementation_type& impl) { if (impl.have_remote_endpoint_) return native_handle_type(impl.socket_, impl.remote_endpoint_); return native_handle_type(impl.socket_); } // Bind the socket to the specified local endpoint. boost::system::error_code bind(implementation_type& impl, const endpoint_type& endpoint, boost::system::error_code& ec) { socket_ops::bind(impl.socket_, endpoint.data(), endpoint.size(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Set a socket option. template <typename Option> boost::system::error_code set_option(implementation_type& impl, const Option& option, boost::system::error_code& ec) { socket_ops::setsockopt(impl.socket_, impl.state_, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), option.size(impl.protocol_), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Set a socket option. template <typename Option> boost::system::error_code get_option(const implementation_type& impl, Option& option, boost::system::error_code& ec) const { std::size_t size = option.size(impl.protocol_); socket_ops::getsockopt(impl.socket_, impl.state_, option.level(impl.protocol_), option.name(impl.protocol_), option.data(impl.protocol_), &size, ec); if (!ec) option.resize(impl.protocol_, size); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Get the local endpoint. endpoint_type local_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint; std::size_t addr_len = endpoint.capacity(); if (socket_ops::getsockname(impl.socket_, endpoint.data(), &addr_len, ec)) { BOOST_ASIO_ERROR_LOCATION(ec); return endpoint_type(); } endpoint.resize(addr_len); return endpoint; } // Get the remote endpoint. endpoint_type remote_endpoint(const implementation_type& impl, boost::system::error_code& ec) const { endpoint_type endpoint = impl.remote_endpoint_; std::size_t addr_len = endpoint.capacity(); if (socket_ops::getpeername(impl.socket_, endpoint.data(), &addr_len, impl.have_remote_endpoint_, ec)) { BOOST_ASIO_ERROR_LOCATION(ec); return endpoint_type(); } endpoint.resize(addr_len); return endpoint; } // Disable sends or receives on the socket. boost::system::error_code shutdown(base_implementation_type& impl, socket_base::shutdown_type what, boost::system::error_code& ec) { socket_ops::shutdown(impl.socket_, what, ec); return ec; } // Send a datagram to the specified endpoint. Returns the number of bytes // sent. template <typename ConstBufferSequence> size_t send_to(implementation_type& impl, const ConstBufferSequence& buffers, const endpoint_type& destination, socket_base::message_flags flags, boost::system::error_code& ec) { buffer_sequence_adapter<boost::asio::const_buffer, ConstBufferSequence> bufs(buffers); size_t n = socket_ops::sync_sendto(impl.socket_, impl.state_, bufs.buffers(), bufs.count(), flags, destination.data(), destination.size(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be sent without blocking. size_t send_to(implementation_type& impl, const null_buffers&, const endpoint_type&, 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); BOOST_ASIO_ERROR_LOCATION(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_to(implementation_type& impl, const ConstBufferSequence& buffers, const endpoint_type& destination, 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_to")); 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_to_op(impl, bufs.buffers(), bufs.count(), destination.data(), static_cast<int>(destination.size()), flags, 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_to(implementation_type& impl, const null_buffers&, const endpoint_type&, 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 }; reactor_op* o = 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_to(null_buffers)")); start_reactor_op(impl, select_reactor::write_op, o); p.v = p.p = 0; } // Receive a datagram with the endpoint of the sender. Returns the number of // bytes received. template <typename MutableBufferSequence> size_t receive_from(implementation_type& impl, const MutableBufferSequence& buffers, endpoint_type& sender_endpoint, socket_base::message_flags flags, boost::system::error_code& ec) { buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs(buffers); std::size_t addr_len = sender_endpoint.capacity(); std::size_t n = socket_ops::sync_recvfrom(impl.socket_, impl.state_, bufs.buffers(), bufs.count(), flags, sender_endpoint.data(), &addr_len, ec); if (!ec) sender_endpoint.resize(addr_len); BOOST_ASIO_ERROR_LOCATION(ec); return n; } // Wait until data can be received without blocking. size_t receive_from(implementation_type& impl, const null_buffers&, endpoint_type& sender_endpoint, 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); // Reset endpoint since it can be given no sensible value at this time. sender_endpoint = endpoint_type(); BOOST_ASIO_ERROR_LOCATION(ec); return 0; } // Start an asynchronous receive. The buffer for the data being received and // the sender_endpoint object must both be valid for the lifetime of the // asynchronous operation. template <typename MutableBufferSequence, typename Handler, typename IoExecutor> void async_receive_from(implementation_type& impl, const MutableBufferSequence& buffers, endpoint_type& sender_endp, 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_recvfrom_op<MutableBufferSequence, endpoint_type, 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(sender_endp, impl.cancel_token_, buffers, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_receive_from")); 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_from_op(impl, bufs.buffers(), bufs.count(), sender_endp.data(), flags, &p.p->endpoint_size(), o); p.v = p.p = 0; } // Wait until data can be received without blocking. template <typename Handler, typename IoExecutor> void async_receive_from(implementation_type& impl, const null_buffers&, endpoint_type& sender_endpoint, 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_from(null_buffers)")); // Reset endpoint since it can be given no sensible value at this time. sender_endpoint = endpoint_type(); // 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); } } // Accept a new connection. template <typename Socket> boost::system::error_code accept(implementation_type& impl, Socket& peer, endpoint_type* peer_endpoint, boost::system::error_code& ec) { // We cannot accept a socket that is already open. if (peer.is_open()) { ec = boost::asio::error::already_open; BOOST_ASIO_ERROR_LOCATION(ec); return ec; } std::size_t addr_len = peer_endpoint ? peer_endpoint->capacity() : 0; socket_holder new_socket(socket_ops::sync_accept(impl.socket_, impl.state_, peer_endpoint ? peer_endpoint->data() : 0, peer_endpoint ? &addr_len : 0, ec)); // On success, assign new connection to peer socket object. if (new_socket.get() != invalid_socket) { if (peer_endpoint) peer_endpoint->resize(addr_len); peer.assign(impl.protocol_, new_socket.get(), ec); if (!ec) new_socket.release(); } BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Start an asynchronous accept. The peer and peer_endpoint objects // must be valid until the accept's handler is invoked. template <typename Socket, typename Handler, typename IoExecutor> void async_accept(implementation_type& impl, Socket& peer, endpoint_type* peer_endpoint, 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_accept_op<Socket, protocol_type, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; bool enable_connection_aborted = (impl.state_ & socket_ops::enable_connection_aborted) != 0; operation* o = p.p = new (p.v) op(*this, impl.socket_, peer, impl.protocol_, peer_endpoint, enable_connection_aborted, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_accept")); // Optionally register for per-operation cancellation. if (slot.is_connected()) { accept_op_cancellation* c = &slot.template emplace<accept_op_cancellation>(impl.socket_, o); p.p->enable_cancellation(c->get_cancel_requested(), c); o = c; } start_accept_op(impl, peer.is_open(), p.p->new_socket(), impl.protocol_.family(), impl.protocol_.type(), impl.protocol_.protocol(), p.p->output_buffer(), p.p->address_length(), o); p.v = p.p = 0; } // Start an asynchronous accept. The peer and peer_endpoint objects // must be valid until the accept's handler is invoked. template <typename PeerIoExecutor, typename Handler, typename IoExecutor> void async_move_accept(implementation_type& impl, const PeerIoExecutor& peer_io_ex, endpoint_type* peer_endpoint, 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_move_accept_op< protocol_type, PeerIoExecutor, Handler, IoExecutor> op; typename op::ptr p = { boost::asio::detail::addressof(handler), op::ptr::allocate(handler), 0 }; bool enable_connection_aborted = (impl.state_ & socket_ops::enable_connection_aborted) != 0; operation* o = p.p = new (p.v) op(*this, impl.socket_, impl.protocol_, peer_io_ex, peer_endpoint, enable_connection_aborted, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_accept")); // Optionally register for per-operation cancellation. if (slot.is_connected()) { accept_op_cancellation* c = &slot.template emplace<accept_op_cancellation>(impl.socket_, o); p.p->enable_cancellation(c->get_cancel_requested(), c); o = c; } start_accept_op(impl, false, p.p->new_socket(), impl.protocol_.family(), impl.protocol_.type(), impl.protocol_.protocol(), p.p->output_buffer(), p.p->address_length(), o); p.v = p.p = 0; } // Connect the socket to the specified endpoint. boost::system::error_code connect(implementation_type& impl, const endpoint_type& peer_endpoint, boost::system::error_code& ec) { socket_ops::sync_connect(impl.socket_, peer_endpoint.data(), peer_endpoint.size(), ec); BOOST_ASIO_ERROR_LOCATION(ec); return ec; } // Start an asynchronous connect. template <typename Handler, typename IoExecutor> void async_connect(implementation_type& impl, const endpoint_type& peer_endpoint, 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_connect_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.socket_, handler, io_ex); BOOST_ASIO_HANDLER_CREATION((context_, *p.p, "socket", &impl, impl.socket_, "async_connect")); // 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_connect_op(impl, impl.protocol_.family(), impl.protocol_.type(), peer_endpoint.data(), static_cast<int>(peer_endpoint.size()), 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); } } }; } // 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_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/signal_handler.hpp
// // detail/signal_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_SIGNAL_HANDLER_HPP #define BOOST_ASIO_DETAIL_SIGNAL_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/signal_op.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Handler, typename IoExecutor> class signal_handler : public signal_op { public: BOOST_ASIO_DEFINE_HANDLER_PTR(signal_handler); signal_handler(Handler& h, const IoExecutor& io_ex) : signal_op(&signal_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. signal_handler* h(static_cast<signal_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::binder2<Handler, boost::system::error_code, int> handler(h->handler_, h->ec_, h->signal_number_); 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 // BOOST_ASIO_DETAIL_SIGNAL_HANDLER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/pipe_select_interrupter.hpp
// // detail/pipe_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_PIPE_SELECT_INTERRUPTER_HPP #define BOOST_ASIO_DETAIL_PIPE_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) #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) #if !defined(__CYGWIN__) #if !defined(__SYMBIAN32__) #if !defined(BOOST_ASIO_HAS_EVENTFD) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class pipe_select_interrupter { public: // Constructor. BOOST_ASIO_DECL pipe_select_interrupter(); // Destructor. BOOST_ASIO_DECL ~pipe_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 // byte 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 // byte may be written to this to wake up the select which is waiting for the // other end to become readable. 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/pipe_select_interrupter.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // !defined(BOOST_ASIO_HAS_EVENTFD) #endif // !defined(__SYMBIAN32__) #endif // !defined(__CYGWIN__) #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // !defined(BOOST_ASIO_WINDOWS) #endif // BOOST_ASIO_DETAIL_PIPE_SELECT_INTERRUPTER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/resolve_query_op.hpp
// // detail/resolve_query_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_RESOLVE_QUERY_OP_HPP #define BOOST_ASIO_DETAIL_RESOLVE_QUERY_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/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/resolve_op.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/error.hpp> #include <boost/asio/ip/basic_resolver_query.hpp> #include <boost/asio/ip/basic_resolver_results.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, typename Handler, typename IoExecutor> class resolve_query_op : public resolve_op { public: BOOST_ASIO_DEFINE_HANDLER_PTR(resolve_query_op); typedef boost::asio::ip::basic_resolver_query<Protocol> query_type; typedef boost::asio::ip::basic_resolver_results<Protocol> results_type; #if defined(BOOST_ASIO_HAS_IOCP) typedef class win_iocp_io_context scheduler_impl; #else typedef class scheduler scheduler_impl; #endif resolve_query_op(socket_ops::weak_cancel_token_type cancel_token, const query_type& qry, scheduler_impl& sched, Handler& handler, const IoExecutor& io_ex) : resolve_op(&resolve_query_op::do_complete), cancel_token_(cancel_token), query_(qry), scheduler_(sched), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex), addrinfo_(0) { } ~resolve_query_op() { if (addrinfo_) socket_ops::freeaddrinfo(addrinfo_); } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the operation object. BOOST_ASIO_ASSUME(base != 0); resolve_query_op* o(static_cast<resolve_query_op*>(base)); ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; if (owner && owner != &o->scheduler_) { // The operation is being run on the worker io_context. Time to perform // the resolver operation. // Perform the blocking host resolution operation. socket_ops::background_getaddrinfo(o->cancel_token_, o->query_.host_name().c_str(), o->query_.service_name().c_str(), o->query_.hints(), &o->addrinfo_, o->ec_); // Pass operation back to main io_context for completion. o->scheduler_.post_deferred_completion(o); p.v = p.p = 0; } else { // The operation has been returned to the main io_context. The completion // handler is ready to be delivered. 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_)); // 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_type()); p.h = boost::asio::detail::addressof(handler.handler_); if (o->addrinfo_) { handler.arg2_ = results_type::create(o->addrinfo_, o->query_.host_name(), o->query_.service_name()); } p.reset(); if (owner) { fenced_block b(fenced_block::half); BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "...")); w.complete(handler, handler.handler_); BOOST_ASIO_HANDLER_INVOCATION_END; } } } private: socket_ops::weak_cancel_token_type cancel_token_; query_type query_; scheduler_impl& scheduler_; Handler handler_; handler_work<Handler, IoExecutor> work_; boost::asio::detail::addrinfo_type* addrinfo_; }; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_RESOLVE_QUERY_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/io_uring_socket_recv_op.hpp
// // detail/io_uring_socket_recv_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECV_OP_HPP #define BOOST_ASIO_DETAIL_IO_URING_SOCKET_RECV_OP_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <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_recv_op_base : public io_uring_operation { public: io_uring_socket_recv_op_base(const boost::system::error_code& success_ec, socket_type socket, socket_ops::state_type state, const MutableBufferSequence& buffers, socket_base::message_flags flags, func_type complete_func) : io_uring_operation(success_ec, &io_uring_socket_recv_op_base::do_prepare, &io_uring_socket_recv_op_base::do_perform, complete_func), socket_(socket), state_(state), buffers_(buffers), flags_(flags), bufs_(buffers), msghdr_() { msghdr_.msg_iov = bufs_.buffers(); msghdr_.msg_iovlen = static_cast<int>(bufs_.count()); } static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recv_op_base* o( static_cast<io_uring_socket_recv_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0; ::io_uring_prep_poll_add(sqe, o->socket_, except_op ? POLLPRI : POLLIN); } else if (o->bufs_.is_single_buffer && o->bufs_.is_registered_buffer && o->flags_ == 0) { ::io_uring_prep_read_fixed(sqe, o->socket_, o->bufs_.buffers()->iov_base, o->bufs_.buffers()->iov_len, 0, o->bufs_.registered_id().native_handle()); } else { ::io_uring_prep_recvmsg(sqe, o->socket_, &o->msghdr_, o->flags_); } } static bool do_perform(io_uring_operation* base, bool after_completion) { BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recv_op_base* o( static_cast<io_uring_socket_recv_op_base*>(base)); if ((o->state_ & socket_ops::internal_non_blocking) != 0) { bool except_op = (o->flags_ & socket_base::message_out_of_band) != 0; if (after_completion || !except_op) { if (o->bufs_.is_single_buffer) { return socket_ops::non_blocking_recv1(o->socket_, o->bufs_.first(o->buffers_).data(), o->bufs_.first(o->buffers_).size(), o->flags_, (o->state_ & socket_ops::stream_oriented) != 0, o->ec_, o->bytes_transferred_); } else { return socket_ops::non_blocking_recv(o->socket_, o->bufs_.buffers(), o->bufs_.count(), o->flags_, (o->state_ & socket_ops::stream_oriented) != 0, o->ec_, o->bytes_transferred_); } } } else if (after_completion) { if (!o->ec_ && o->bytes_transferred_ == 0) if ((o->state_ & socket_ops::stream_oriented) != 0) o->ec_ = boost::asio::error::eof; } 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 flags_; buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs_; msghdr msghdr_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class io_uring_socket_recv_op : public io_uring_socket_recv_op_base<MutableBufferSequence> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_socket_recv_op); io_uring_socket_recv_op(const boost::system::error_code& success_ec, int socket, socket_ops::state_type state, const MutableBufferSequence& buffers, socket_base::message_flags flags, Handler& handler, const IoExecutor& io_ex) : io_uring_socket_recv_op_base<MutableBufferSequence>(success_ec, socket, state, buffers, flags, &io_uring_socket_recv_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); io_uring_socket_recv_op* o (static_cast<io_uring_socket_recv_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_RECV_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/winrt_socket_send_op.hpp
// // detail/winrt_socket_send_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WINRT_SOCKET_SEND_OP_HPP #define BOOST_ASIO_DETAIL_WINRT_SOCKET_SEND_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/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/winrt_async_op.hpp> #include <boost/asio/error.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename ConstBufferSequence, typename Handler, typename IoExecutor> class winrt_socket_send_op : public winrt_async_op<unsigned int> { public: BOOST_ASIO_DEFINE_HANDLER_PTR(winrt_socket_send_op); winrt_socket_send_op(const ConstBufferSequence& buffers, Handler& handler, const IoExecutor& io_ex) : winrt_async_op<unsigned int>(&winrt_socket_send_op::do_complete), buffers_(buffers), 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_socket_send_op* o(static_cast<winrt_socket_send_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::const_buffer, ConstBufferSequence>::validate(o->buffers_); } #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // 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->result_); 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: ConstBufferSequence buffers_; 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_SOCKET_SEND_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_static_mutex.hpp
// // detail/win_static_mutex.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP #define BOOST_ASIO_DETAIL_WIN_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_WINDOWS) #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { struct win_static_mutex { typedef boost::asio::detail::scoped_lock<win_static_mutex> scoped_lock; // Initialise the mutex. BOOST_ASIO_DECL void init(); // Initialisation must be performed in a separate function to the "public" // init() function since the compiler does not support the use of structured // exceptions and C++ exceptions in the same function. BOOST_ASIO_DECL int do_init(); // Lock the mutex. void lock() { ::EnterCriticalSection(&crit_section_); } // Unlock the mutex. void unlock() { ::LeaveCriticalSection(&crit_section_); } bool initialised_; ::CRITICAL_SECTION crit_section_; }; #if defined(UNDER_CE) # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0 } } #else // defined(UNDER_CE) # define BOOST_ASIO_WIN_STATIC_MUTEX_INIT { false, { 0, 0, 0, 0, 0, 0 } } #endif // defined(UNDER_CE) } // 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_static_mutex.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) #endif // BOOST_ASIO_DETAIL_WIN_STATIC_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/reactive_socket_recvmsg_op.hpp
// // detail/reactive_socket_recvmsg_op.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_REACTIVE_SOCKET_RECVMSG_OP_HPP #define BOOST_ASIO_DETAIL_REACTIVE_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> #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/socket_base.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename MutableBufferSequence> class reactive_socket_recvmsg_op_base : public reactor_op { public: reactive_socket_recvmsg_op_base(const boost::system::error_code& success_ec, socket_type socket, const MutableBufferSequence& buffers, socket_base::message_flags in_flags, socket_base::message_flags& out_flags, func_type complete_func) : reactor_op(success_ec, &reactive_socket_recvmsg_op_base::do_perform, complete_func), socket_(socket), buffers_(buffers), in_flags_(in_flags), out_flags_(out_flags) { } static status do_perform(reactor_op* base) { BOOST_ASIO_ASSUME(base != 0); reactive_socket_recvmsg_op_base* o( static_cast<reactive_socket_recvmsg_op_base*>(base)); buffer_sequence_adapter<boost::asio::mutable_buffer, MutableBufferSequence> bufs(o->buffers_); status result = socket_ops::non_blocking_recvmsg(o->socket_, bufs.buffers(), bufs.count(), o->in_flags_, o->out_flags_, o->ec_, o->bytes_transferred_) ? done : not_done; BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_recvmsg", o->ec_, o->bytes_transferred_)); return result; } private: socket_type socket_; MutableBufferSequence buffers_; socket_base::message_flags in_flags_; socket_base::message_flags& out_flags_; }; template <typename MutableBufferSequence, typename Handler, typename IoExecutor> class reactive_socket_recvmsg_op : public reactive_socket_recvmsg_op_base<MutableBufferSequence> { public: typedef Handler handler_type; typedef IoExecutor io_executor_type; BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_socket_recvmsg_op); reactive_socket_recvmsg_op(const boost::system::error_code& success_ec, socket_type socket, const MutableBufferSequence& buffers, socket_base::message_flags in_flags, socket_base::message_flags& out_flags, Handler& handler, const IoExecutor& io_ex) : reactive_socket_recvmsg_op_base<MutableBufferSequence>( success_ec, socket, buffers, in_flags, out_flags, &reactive_socket_recvmsg_op::do_complete), handler_(static_cast<Handler&&>(handler)), work_(handler_, io_ex) { } static void do_complete(void* owner, operation* base, const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_recvmsg_op* o( static_cast<reactive_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; } } static void do_immediate(operation* base, bool, const void* io_ex) { // Take ownership of the handler object. BOOST_ASIO_ASSUME(base != 0); reactive_socket_recvmsg_op* o( static_cast<reactive_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. 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_RECVMSG_OP_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_thread.hpp
// // detail/win_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_WIN_THREAD_HPP #define BOOST_ASIO_DETAIL_WIN_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) \ && !defined(UNDER_CE) #include <cstddef> #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 { BOOST_ASIO_DECL unsigned int __stdcall win_thread_function(void* arg); #if defined(WINVER) && (WINVER < 0x0500) BOOST_ASIO_DECL void __stdcall apc_function(ULONG data); #else BOOST_ASIO_DECL void __stdcall apc_function(ULONG_PTR data); #endif template <typename T> class win_thread_base { public: static bool terminate_threads() { return ::InterlockedExchangeAdd(&terminate_threads_, 0) != 0; } static void set_terminate_threads(bool b) { ::InterlockedExchange(&terminate_threads_, b ? 1 : 0); } private: static long terminate_threads_; }; template <typename T> long win_thread_base<T>::terminate_threads_ = 0; class win_thread : private noncopyable, public win_thread_base<win_thread> { public: // Constructor. template <typename Function> win_thread(Function f, unsigned int stack_size = 0) : thread_(0), exit_event_(0) { start_thread(new func<Function>(f), stack_size); } // Destructor. BOOST_ASIO_DECL ~win_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 BOOST_ASIO_DECL unsigned int __stdcall win_thread_function(void* arg); #if defined(WINVER) && (WINVER < 0x0500) friend BOOST_ASIO_DECL void __stdcall apc_function(ULONG); #else friend BOOST_ASIO_DECL void __stdcall apc_function(ULONG_PTR); #endif class func_base { public: virtual ~func_base() {} virtual void run() = 0; ::HANDLE entry_event_; ::HANDLE exit_event_; }; 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, unsigned int stack_size); ::HANDLE thread_; ::HANDLE exit_event_; }; } // 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_thread.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) // && !defined(BOOST_ASIO_WINDOWS_APP) // && !defined(UNDER_CE) #endif // BOOST_ASIO_DETAIL_WIN_THREAD_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/win_mutex.hpp
// // detail/win_mutex.hpp // ~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_WIN_MUTEX_HPP #define BOOST_ASIO_DETAIL_WIN_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_WINDOWS) #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/scoped_lock.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { class win_mutex : private noncopyable { public: typedef boost::asio::detail::scoped_lock<win_mutex> scoped_lock; // Constructor. BOOST_ASIO_DECL win_mutex(); // Destructor. ~win_mutex() { ::DeleteCriticalSection(&crit_section_); } // Lock the mutex. void lock() { ::EnterCriticalSection(&crit_section_); } // Unlock the mutex. void unlock() { ::LeaveCriticalSection(&crit_section_); } private: // Initialisation must be performed in a separate function to the constructor // since the compiler does not support the use of structured exceptions and // C++ exceptions in the same function. BOOST_ASIO_DECL int do_init(); ::CRITICAL_SECTION crit_section_; }; } // 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_mutex.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // defined(BOOST_ASIO_WINDOWS) #endif // BOOST_ASIO_DETAIL_WIN_MUTEX_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/strand_executor_service.hpp
// // detail/impl/strand_executor_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DETAIL_IMPL_STRAND_EXECUTOR_SERVICE_HPP #define BOOST_ASIO_DETAIL_IMPL_STRAND_EXECUTOR_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/recycling_allocator.hpp> #include <boost/asio/executor_work_guard.hpp> #include <boost/asio/defer.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/post.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename F, typename Allocator> class strand_executor_service::allocator_binder { public: typedef Allocator allocator_type; allocator_binder(F&& f, const Allocator& a) : f_(static_cast<F&&>(f)), allocator_(a) { } allocator_binder(const allocator_binder& other) : f_(other.f_), allocator_(other.allocator_) { } allocator_binder(allocator_binder&& other) : f_(static_cast<F&&>(other.f_)), allocator_(static_cast<allocator_type&&>(other.allocator_)) { } allocator_type get_allocator() const noexcept { return allocator_; } void operator()() { f_(); } private: F f_; allocator_type allocator_; }; template <typename Executor> class strand_executor_service::invoker<Executor, enable_if_t< execution::is_executor<Executor>::value >> { public: invoker(const implementation_type& impl, Executor& ex) : impl_(impl), executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked)) { } invoker(const invoker& other) : impl_(other.impl_), executor_(other.executor_) { } invoker(invoker&& other) : impl_(static_cast<implementation_type&&>(other.impl_)), executor_(static_cast<executor_type&&>(other.executor_)) { } struct on_invoker_exit { invoker* this_; ~on_invoker_exit() { if (push_waiting_to_ready(this_->impl_)) { recycling_allocator<void> allocator; executor_type ex = this_->executor_; boost::asio::prefer( boost::asio::require( static_cast<executor_type&&>(ex), execution::blocking.never), execution::allocator(allocator) ).execute(static_cast<invoker&&>(*this_)); } } }; void operator()() { // Ensure the next handler, if any, is scheduled on block exit. on_invoker_exit on_exit = { this }; (void)on_exit; run_ready_handlers(impl_); } private: typedef decay_t< prefer_result_t< Executor, execution::outstanding_work_t::tracked_t > > executor_type; implementation_type impl_; executor_type executor_; }; #if !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename Executor> class strand_executor_service::invoker<Executor, enable_if_t< !execution::is_executor<Executor>::value >> { public: invoker(const implementation_type& impl, Executor& ex) : impl_(impl), work_(ex) { } invoker(const invoker& other) : impl_(other.impl_), work_(other.work_) { } invoker(invoker&& other) : impl_(static_cast<implementation_type&&>(other.impl_)), work_(static_cast<executor_work_guard<Executor>&&>(other.work_)) { } struct on_invoker_exit { invoker* this_; ~on_invoker_exit() { if (push_waiting_to_ready(this_->impl_)) { Executor ex(this_->work_.get_executor()); recycling_allocator<void> allocator; ex.post(static_cast<invoker&&>(*this_), allocator); } } }; void operator()() { // Ensure the next handler, if any, is scheduled on block exit. on_invoker_exit on_exit = { this }; (void)on_exit; run_ready_handlers(impl_); } private: implementation_type impl_; executor_work_guard<Executor> work_; }; #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS) template <typename Executor, typename Function> inline void strand_executor_service::execute(const implementation_type& impl, Executor& ex, Function&& function, enable_if_t< can_query<Executor, execution::allocator_t<void>>::value >*) { return strand_executor_service::do_execute(impl, ex, static_cast<Function&&>(function), boost::asio::query(ex, execution::allocator)); } template <typename Executor, typename Function> inline void strand_executor_service::execute(const implementation_type& impl, Executor& ex, Function&& function, enable_if_t< !can_query<Executor, execution::allocator_t<void>>::value >*) { return strand_executor_service::do_execute(impl, ex, static_cast<Function&&>(function), std::allocator<void>()); } template <typename Executor, typename Function, typename Allocator> void strand_executor_service::do_execute(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a) { typedef decay_t<Function> function_type; // If the executor is not never-blocking, and we are already in the strand, // then the function can run immediately. if (boost::asio::query(ex, execution::blocking) != execution::blocking.never && running_in_this_thread(impl)) { // Make a local, non-const copy of the function. function_type tmp(static_cast<Function&&>(function)); fenced_block b(fenced_block::full); static_cast<function_type&&>(tmp)(); return; } // Allocate and construct an operation to wrap the function. typedef executor_op<function_type, Allocator> op; typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 }; p.p = new (p.v) op(static_cast<Function&&>(function), a); BOOST_ASIO_HANDLER_CREATION((impl->service_->context(), *p.p, "strand_executor", impl.get(), 0, "execute")); // Add the function to the strand and schedule the strand if required. bool first = enqueue(impl, p.p); p.v = p.p = 0; if (first) { ex.execute(invoker<Executor>(impl, ex)); } } template <typename Executor, typename Function, typename Allocator> void strand_executor_service::dispatch(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a) { typedef decay_t<Function> function_type; // If we are already in the strand then the function can run immediately. if (running_in_this_thread(impl)) { // Make a local, non-const copy of the function. function_type tmp(static_cast<Function&&>(function)); fenced_block b(fenced_block::full); static_cast<function_type&&>(tmp)(); return; } // Allocate and construct an operation to wrap the function. typedef executor_op<function_type, Allocator> op; typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 }; p.p = new (p.v) op(static_cast<Function&&>(function), a); BOOST_ASIO_HANDLER_CREATION((impl->service_->context(), *p.p, "strand_executor", impl.get(), 0, "dispatch")); // Add the function to the strand and schedule the strand if required. bool first = enqueue(impl, p.p); p.v = p.p = 0; if (first) { boost::asio::dispatch(ex, allocator_binder<invoker<Executor>, Allocator>( invoker<Executor>(impl, ex), a)); } } // Request invocation of the given function and return immediately. template <typename Executor, typename Function, typename Allocator> void strand_executor_service::post(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a) { typedef decay_t<Function> function_type; // Allocate and construct an operation to wrap the function. typedef executor_op<function_type, Allocator> op; typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 }; p.p = new (p.v) op(static_cast<Function&&>(function), a); BOOST_ASIO_HANDLER_CREATION((impl->service_->context(), *p.p, "strand_executor", impl.get(), 0, "post")); // Add the function to the strand and schedule the strand if required. bool first = enqueue(impl, p.p); p.v = p.p = 0; if (first) { boost::asio::post(ex, allocator_binder<invoker<Executor>, Allocator>( invoker<Executor>(impl, ex), a)); } } // Request invocation of the given function and return immediately. template <typename Executor, typename Function, typename Allocator> void strand_executor_service::defer(const implementation_type& impl, Executor& ex, Function&& function, const Allocator& a) { typedef decay_t<Function> function_type; // Allocate and construct an operation to wrap the function. typedef executor_op<function_type, Allocator> op; typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 }; p.p = new (p.v) op(static_cast<Function&&>(function), a); BOOST_ASIO_HANDLER_CREATION((impl->service_->context(), *p.p, "strand_executor", impl.get(), 0, "defer")); // Add the function to the strand and schedule the strand if required. bool first = enqueue(impl, p.p); p.v = p.p = 0; if (first) { boost::asio::defer(ex, allocator_binder<invoker<Executor>, Allocator>( invoker<Executor>(impl, ex), a)); } } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IMPL_STRAND_EXECUTOR_SERVICE_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/epoll_reactor.hpp
// // detail/impl/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_IMPL_EPOLL_REACTOR_HPP #define BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #if defined(BOOST_ASIO_HAS_EPOLL) #include <boost/asio/detail/scheduler.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { inline void epoll_reactor::post_immediate_completion( operation* op, bool is_continuation) const { scheduler_.post_immediate_completion(op, is_continuation); } template <typename Time_Traits> void epoll_reactor::add_timer_queue(timer_queue<Time_Traits>& queue) { do_add_timer_queue(queue); } template <typename Time_Traits> void epoll_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue) { do_remove_timer_queue(queue); } template <typename Time_Traits> void epoll_reactor::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) { mutex::scoped_lock lock(mutex_); if (shutdown_) { scheduler_.post_immediate_completion(op, false); return; } bool earliest = queue.enqueue_timer(time, timer, op); scheduler_.work_started(); if (earliest) update_timeout(); } template <typename Time_Traits> std::size_t epoll_reactor::cancel_timer(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data& timer, std::size_t max_cancelled) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); lock.unlock(); scheduler_.post_deferred_completions(ops); return n; } template <typename Time_Traits> void epoll_reactor::cancel_timer_by_key(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data* timer, void* cancellation_key) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer_by_key(timer, ops, cancellation_key); lock.unlock(); scheduler_.post_deferred_completions(ops); } template <typename Time_Traits> void epoll_reactor::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) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer(target, ops); queue.move_timer(target, source); lock.unlock(); scheduler_.post_deferred_completions(ops); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_EPOLL) #endif // BOOST_ASIO_DETAIL_IMPL_EPOLL_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/win_iocp_io_context.hpp
// // detail/impl/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_IMPL_WIN_IOCP_IO_CONTEXT_HPP #define BOOST_ASIO_DETAIL_IMPL_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/completion_handler.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/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Time_Traits> void win_iocp_io_context::add_timer_queue( timer_queue<Time_Traits>& queue) { do_add_timer_queue(queue); } template <typename Time_Traits> void win_iocp_io_context::remove_timer_queue( timer_queue<Time_Traits>& queue) { do_remove_timer_queue(queue); } template <typename Time_Traits> void win_iocp_io_context::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) { // If the service has been shut down we silently discard the timer. if (::InterlockedExchangeAdd(&shutdown_, 0) != 0) { post_immediate_completion(op, false); return; } mutex::scoped_lock lock(dispatch_mutex_); bool earliest = queue.enqueue_timer(time, timer, op); work_started(); if (earliest) update_timeout(); } template <typename Time_Traits> std::size_t win_iocp_io_context::cancel_timer(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data& timer, std::size_t max_cancelled) { // If the service has been shut down we silently ignore the cancellation. if (::InterlockedExchangeAdd(&shutdown_, 0) != 0) return 0; mutex::scoped_lock lock(dispatch_mutex_); op_queue<win_iocp_operation> ops; std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); lock.unlock(); post_deferred_completions(ops); return n; } template <typename Time_Traits> void win_iocp_io_context::cancel_timer_by_key(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data* timer, void* cancellation_key) { // If the service has been shut down we silently ignore the cancellation. if (::InterlockedExchangeAdd(&shutdown_, 0) != 0) return; mutex::scoped_lock lock(dispatch_mutex_); op_queue<win_iocp_operation> ops; queue.cancel_timer_by_key(timer, ops, cancellation_key); lock.unlock(); post_deferred_completions(ops); } template <typename Time_Traits> void win_iocp_io_context::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) { boost::asio::detail::mutex::scoped_lock lock(dispatch_mutex_); op_queue<operation> ops; queue.cancel_timer(to, ops); queue.move_timer(to, from); lock.unlock(); post_deferred_completions(ops); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_IOCP) #endif // BOOST_ASIO_DETAIL_IMPL_WIN_IOCP_IO_CONTEXT_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/select_reactor.hpp
// // detail/impl/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_IMPL_SELECT_REACTOR_HPP #define BOOST_ASIO_DETAIL_IMPL_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)) #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 { inline void select_reactor::post_immediate_completion( operation* op, bool is_continuation) const { scheduler_.post_immediate_completion(op, is_continuation); } template <typename Time_Traits> void select_reactor::add_timer_queue(timer_queue<Time_Traits>& queue) { do_add_timer_queue(queue); } // Remove a timer queue from the reactor. template <typename Time_Traits> void select_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue) { do_remove_timer_queue(queue); } template <typename Time_Traits> void select_reactor::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) { boost::asio::detail::mutex::scoped_lock lock(mutex_); if (shutdown_) { scheduler_.post_immediate_completion(op, false); return; } bool earliest = queue.enqueue_timer(time, timer, op); scheduler_.work_started(); if (earliest) interrupter_.interrupt(); } template <typename Time_Traits> std::size_t select_reactor::cancel_timer(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data& timer, std::size_t max_cancelled) { boost::asio::detail::mutex::scoped_lock lock(mutex_); op_queue<operation> ops; std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); lock.unlock(); scheduler_.post_deferred_completions(ops); return n; } template <typename Time_Traits> void select_reactor::cancel_timer_by_key(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data* timer, void* cancellation_key) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer_by_key(timer, ops, cancellation_key); lock.unlock(); scheduler_.post_deferred_completions(ops); } template <typename Time_Traits> void select_reactor::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) { boost::asio::detail::mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer(target, ops); queue.move_timer(target, source); lock.unlock(); scheduler_.post_deferred_completions(ops); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #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_IMPL_SELECT_REACTOR_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/service_registry.hpp
// // detail/impl/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_IMPL_SERVICE_REGISTRY_HPP #define BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Service> Service& service_registry::use_service() { execution_context::service::key key; init_key<Service>(key, 0); factory_type factory = &service_registry::create<Service, execution_context>; return *static_cast<Service*>(do_use_service(key, factory, &owner_)); } template <typename Service> Service& service_registry::use_service(io_context& owner) { execution_context::service::key key; init_key<Service>(key, 0); factory_type factory = &service_registry::create<Service, io_context>; return *static_cast<Service*>(do_use_service(key, factory, &owner)); } template <typename Service> void service_registry::add_service(Service* new_service) { execution_context::service::key key; init_key<Service>(key, 0); return do_add_service(key, new_service); } template <typename Service> bool service_registry::has_service() const { execution_context::service::key key; init_key<Service>(key, 0); return do_has_service(key); } template <typename Service> inline void service_registry::init_key( execution_context::service::key& key, ...) { init_key_from_id(key, Service::id); } #if !defined(BOOST_ASIO_NO_TYPEID) template <typename Service> void service_registry::init_key(execution_context::service::key& key, enable_if_t<is_base_of<typename Service::key_type, Service>::value>*) { key.type_info_ = &typeid(typeid_wrapper<Service>); key.id_ = 0; } template <typename Service> void service_registry::init_key_from_id(execution_context::service::key& key, const service_id<Service>& /*id*/) { key.type_info_ = &typeid(typeid_wrapper<Service>); key.id_ = 0; } #endif // !defined(BOOST_ASIO_NO_TYPEID) template <typename Service, typename Owner> execution_context::service* service_registry::create(void* owner) { return new Service(*static_cast<Owner*>(owner)); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // BOOST_ASIO_DETAIL_IMPL_SERVICE_REGISTRY_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/winrt_timer_scheduler.hpp
// // detail/impl/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_IMPL_WINRT_TIMER_SCHEDULER_HPP #define BOOST_ASIO_DETAIL_IMPL_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 <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { template <typename Time_Traits> void winrt_timer_scheduler::add_timer_queue(timer_queue<Time_Traits>& queue) { do_add_timer_queue(queue); } // Remove a timer queue from the reactor. template <typename Time_Traits> void winrt_timer_scheduler::remove_timer_queue(timer_queue<Time_Traits>& queue) { do_remove_timer_queue(queue); } template <typename Time_Traits> void winrt_timer_scheduler::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) { boost::asio::detail::mutex::scoped_lock lock(mutex_); if (shutdown_) { scheduler_.post_immediate_completion(op, false); return; } bool earliest = queue.enqueue_timer(time, timer, op); scheduler_.work_started(); if (earliest) event_.signal(lock); } template <typename Time_Traits> std::size_t winrt_timer_scheduler::cancel_timer(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data& timer, std::size_t max_cancelled) { boost::asio::detail::mutex::scoped_lock lock(mutex_); op_queue<operation> ops; std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); lock.unlock(); scheduler_.post_deferred_completions(ops); return n; } template <typename Time_Traits> void winrt_timer_scheduler::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) { boost::asio::detail::mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer(to, ops); queue.move_timer(to, from); lock.unlock(); scheduler_.post_deferred_completions(ops); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) #endif // BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_HPP
hpp
asio
data/projects/asio/include/boost/asio/detail/impl/kqueue_reactor.hpp
// // detail/impl/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_IMPL_KQUEUE_REACTOR_HPP #define BOOST_ASIO_DETAIL_IMPL_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 <boost/asio/detail/scheduler.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { namespace detail { inline void kqueue_reactor::post_immediate_completion( operation* op, bool is_continuation) const { scheduler_.post_immediate_completion(op, is_continuation); } template <typename Time_Traits> void kqueue_reactor::add_timer_queue(timer_queue<Time_Traits>& queue) { do_add_timer_queue(queue); } // Remove a timer queue from the reactor. template <typename Time_Traits> void kqueue_reactor::remove_timer_queue(timer_queue<Time_Traits>& queue) { do_remove_timer_queue(queue); } template <typename Time_Traits> void kqueue_reactor::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) { mutex::scoped_lock lock(mutex_); if (shutdown_) { scheduler_.post_immediate_completion(op, false); return; } bool earliest = queue.enqueue_timer(time, timer, op); scheduler_.work_started(); if (earliest) interrupt(); } template <typename Time_Traits> std::size_t kqueue_reactor::cancel_timer(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data& timer, std::size_t max_cancelled) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; std::size_t n = queue.cancel_timer(timer, ops, max_cancelled); lock.unlock(); scheduler_.post_deferred_completions(ops); return n; } template <typename Time_Traits> void kqueue_reactor::cancel_timer_by_key(timer_queue<Time_Traits>& queue, typename timer_queue<Time_Traits>::per_timer_data* timer, void* cancellation_key) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer_by_key(timer, ops, cancellation_key); lock.unlock(); scheduler_.post_deferred_completions(ops); } template <typename Time_Traits> void kqueue_reactor::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) { mutex::scoped_lock lock(mutex_); op_queue<operation> ops; queue.cancel_timer(target, ops); queue.move_timer(target, source); lock.unlock(); scheduler_.post_deferred_completions(ops); } } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #endif // defined(BOOST_ASIO_HAS_KQUEUE) #endif // BOOST_ASIO_DETAIL_IMPL_KQUEUE_REACTOR_HPP
hpp