File indexing completed on 2025-01-18 09:28:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
0012 #define BOOST_ASIO_DETAIL_DESCRIPTOR_WRITE_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_WINDOWS) && !defined(__CYGWIN__)
0021
0022 #include <boost/asio/detail/bind_handler.hpp>
0023 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
0024 #include <boost/asio/detail/descriptor_ops.hpp>
0025 #include <boost/asio/detail/fenced_block.hpp>
0026 #include <boost/asio/detail/handler_work.hpp>
0027 #include <boost/asio/detail/memory.hpp>
0028 #include <boost/asio/detail/reactor_op.hpp>
0029
0030 #include <boost/asio/detail/push_options.hpp>
0031
0032 namespace boost {
0033 namespace asio {
0034 namespace detail {
0035
0036 template <typename ConstBufferSequence>
0037 class descriptor_write_op_base : public reactor_op
0038 {
0039 public:
0040 descriptor_write_op_base(const boost::system::error_code& success_ec,
0041 int descriptor, const ConstBufferSequence& buffers,
0042 func_type complete_func)
0043 : reactor_op(success_ec,
0044 &descriptor_write_op_base::do_perform, complete_func),
0045 descriptor_(descriptor),
0046 buffers_(buffers)
0047 {
0048 }
0049
0050 static status do_perform(reactor_op* base)
0051 {
0052 BOOST_ASIO_ASSUME(base != 0);
0053 descriptor_write_op_base* o(static_cast<descriptor_write_op_base*>(base));
0054
0055 typedef buffer_sequence_adapter<boost::asio::const_buffer,
0056 ConstBufferSequence> bufs_type;
0057
0058 status result;
0059 if (bufs_type::is_single_buffer)
0060 {
0061 result = descriptor_ops::non_blocking_write1(o->descriptor_,
0062 bufs_type::first(o->buffers_).data(),
0063 bufs_type::first(o->buffers_).size(),
0064 o->ec_, o->bytes_transferred_) ? done : not_done;
0065 }
0066 else
0067 {
0068 bufs_type bufs(o->buffers_);
0069 result = descriptor_ops::non_blocking_write(o->descriptor_,
0070 bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_)
0071 ? done : not_done;
0072 }
0073
0074 BOOST_ASIO_HANDLER_REACTOR_OPERATION((*o, "non_blocking_write",
0075 o->ec_, o->bytes_transferred_));
0076
0077 return result;
0078 }
0079
0080 private:
0081 int descriptor_;
0082 ConstBufferSequence buffers_;
0083 };
0084
0085 template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
0086 class descriptor_write_op
0087 : public descriptor_write_op_base<ConstBufferSequence>
0088 {
0089 public:
0090 typedef Handler handler_type;
0091 typedef IoExecutor io_executor_type;
0092
0093 BOOST_ASIO_DEFINE_HANDLER_PTR(descriptor_write_op);
0094
0095 descriptor_write_op(const boost::system::error_code& success_ec,
0096 int descriptor, const ConstBufferSequence& buffers,
0097 Handler& handler, const IoExecutor& io_ex)
0098 : descriptor_write_op_base<ConstBufferSequence>(success_ec,
0099 descriptor, buffers, &descriptor_write_op::do_complete),
0100 handler_(static_cast<Handler&&>(handler)),
0101 work_(handler_, io_ex)
0102 {
0103 }
0104
0105 static void do_complete(void* owner, operation* base,
0106 const boost::system::error_code& ,
0107 std::size_t )
0108 {
0109
0110 BOOST_ASIO_ASSUME(base != 0);
0111 descriptor_write_op* o(static_cast<descriptor_write_op*>(base));
0112 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0113
0114 BOOST_ASIO_HANDLER_COMPLETION((*o));
0115
0116
0117 handler_work<Handler, IoExecutor> w(
0118 static_cast<handler_work<Handler, IoExecutor>&&>(
0119 o->work_));
0120
0121 BOOST_ASIO_ERROR_LOCATION(o->ec_);
0122
0123
0124
0125
0126
0127
0128
0129 detail::binder2<Handler, boost::system::error_code, std::size_t>
0130 handler(o->handler_, o->ec_, o->bytes_transferred_);
0131 p.h = boost::asio::detail::addressof(handler.handler_);
0132 p.reset();
0133
0134
0135 if (owner)
0136 {
0137 fenced_block b(fenced_block::half);
0138 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
0139 w.complete(handler, handler.handler_);
0140 BOOST_ASIO_HANDLER_INVOCATION_END;
0141 }
0142 }
0143
0144 static void do_immediate(operation* base, bool, const void* io_ex)
0145 {
0146
0147 BOOST_ASIO_ASSUME(base != 0);
0148 descriptor_write_op* o(static_cast<descriptor_write_op*>(base));
0149 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0150
0151 BOOST_ASIO_HANDLER_COMPLETION((*o));
0152
0153
0154 immediate_handler_work<Handler, IoExecutor> w(
0155 static_cast<handler_work<Handler, IoExecutor>&&>(
0156 o->work_));
0157
0158 BOOST_ASIO_ERROR_LOCATION(o->ec_);
0159
0160
0161
0162
0163
0164
0165
0166 detail::binder2<Handler, boost::system::error_code, std::size_t>
0167 handler(o->handler_, o->ec_, o->bytes_transferred_);
0168 p.h = boost::asio::detail::addressof(handler.handler_);
0169 p.reset();
0170
0171 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
0172 w.complete(handler, handler.handler_, io_ex);
0173 BOOST_ASIO_HANDLER_INVOCATION_END;
0174 }
0175
0176 private:
0177 Handler handler_;
0178 handler_work<Handler, IoExecutor> work_;
0179 };
0180
0181 }
0182 }
0183 }
0184
0185 #include <boost/asio/detail/pop_options.hpp>
0186
0187 #endif
0188
0189 #endif