File indexing completed on 2025-01-18 09:28:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP
0012 #define BOOST_ASIO_DETAIL_WIN_IOCP_SOCKET_RECVFROM_OP_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_HAS_IOCP)
0021
0022 #include <boost/asio/detail/bind_handler.hpp>
0023 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
0024 #include <boost/asio/detail/fenced_block.hpp>
0025 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0026 #include <boost/asio/detail/handler_work.hpp>
0027 #include <boost/asio/detail/memory.hpp>
0028 #include <boost/asio/detail/operation.hpp>
0029 #include <boost/asio/detail/socket_ops.hpp>
0030 #include <boost/asio/error.hpp>
0031
0032 #include <boost/asio/detail/push_options.hpp>
0033
0034 namespace boost {
0035 namespace asio {
0036 namespace detail {
0037
0038 template <typename MutableBufferSequence, typename Endpoint,
0039 typename Handler, typename IoExecutor>
0040 class win_iocp_socket_recvfrom_op : public operation
0041 {
0042 public:
0043 BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recvfrom_op);
0044
0045 win_iocp_socket_recvfrom_op(Endpoint& endpoint,
0046 socket_ops::weak_cancel_token_type cancel_token,
0047 const MutableBufferSequence& buffers, Handler& handler,
0048 const IoExecutor& io_ex)
0049 : operation(&win_iocp_socket_recvfrom_op::do_complete),
0050 endpoint_(endpoint),
0051 endpoint_size_(static_cast<int>(endpoint.capacity())),
0052 cancel_token_(cancel_token),
0053 buffers_(buffers),
0054 handler_(static_cast<Handler&&>(handler)),
0055 work_(handler_, io_ex)
0056 {
0057 }
0058
0059 int& endpoint_size()
0060 {
0061 return endpoint_size_;
0062 }
0063
0064 static void do_complete(void* owner, operation* base,
0065 const boost::system::error_code& result_ec,
0066 std::size_t bytes_transferred)
0067 {
0068 boost::system::error_code ec(result_ec);
0069
0070
0071 BOOST_ASIO_ASSUME(base != 0);
0072 win_iocp_socket_recvfrom_op* o(
0073 static_cast<win_iocp_socket_recvfrom_op*>(base));
0074 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0075
0076 BOOST_ASIO_HANDLER_COMPLETION((*o));
0077
0078
0079 handler_work<Handler, IoExecutor> w(
0080 static_cast<handler_work<Handler, IoExecutor>&&>(
0081 o->work_));
0082
0083 #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
0084
0085 if (owner)
0086 {
0087 buffer_sequence_adapter<boost::asio::mutable_buffer,
0088 MutableBufferSequence>::validate(o->buffers_);
0089 }
0090 #endif
0091
0092 socket_ops::complete_iocp_recvfrom(o->cancel_token_, ec);
0093
0094
0095 o->endpoint_.resize(o->endpoint_size_);
0096
0097 BOOST_ASIO_ERROR_LOCATION(ec);
0098
0099
0100
0101
0102
0103
0104
0105 detail::binder2<Handler, boost::system::error_code, std::size_t>
0106 handler(o->handler_, ec, bytes_transferred);
0107 p.h = boost::asio::detail::addressof(handler.handler_);
0108 p.reset();
0109
0110
0111 if (owner)
0112 {
0113 fenced_block b(fenced_block::half);
0114 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
0115 w.complete(handler, handler.handler_);
0116 BOOST_ASIO_HANDLER_INVOCATION_END;
0117 }
0118 }
0119
0120 private:
0121 Endpoint& endpoint_;
0122 int endpoint_size_;
0123 socket_ops::weak_cancel_token_type cancel_token_;
0124 MutableBufferSequence buffers_;
0125 Handler handler_;
0126 handler_work<Handler, IoExecutor> work_;
0127 };
0128
0129 }
0130 }
0131 }
0132
0133 #include <boost/asio/detail/pop_options.hpp>
0134
0135 #endif
0136
0137 #endif