namespace asio { template< typename Handler > class basic_yield_context { public: basic_yield_context( boost::fibers::context * ctx, Handler& handler) : ctx_( ctx), handler_( handler), ec_( 0) { } basic_yield_context operator[]( boost::system::error_code & ec) { basic_yield_context tmp( * this); tmp.ec_ = & ec; return tmp; } private: boost::fibers::context * ctx_; Handler & handler_; boost::system::error_code * ec_; }; typedef basic_yield_context< boost::asio::detail::wrapped_handler< boost::asio::io_service::strand, void(*)(), boost::asio::detail::is_continuation_if_running> > yield_context; template< typename Handler, typename Function > void spawn( boost::asio::io_service & io_service, BOOST_ASIO_MOVE_ARG( Handler) handler, BOOST_ASIO_MOVE_ARG( Function) function); template< typename Handler, typename Function > void spawn( boost::asio::io_service & io_service, basic_yield_context< Handler > ctx, BOOST_ASIO_MOVE_ARG( Function) function); template< typename Function > void spawn( boost::asio::io_service::strand strand, BOOST_ASIO_MOVE_ARG( Function) function); template< typename Function > void spawn( boost::asio::io_service & io_service, BOOST_ASIO_MOVE_ARG( Function) function); }}}
async_accept(basic_socket<Protocol1, SocketService>& peer, BOOST_ASIO_MOVE_ARG(AcceptHandler) handler, typename enable_if<is_convertible<Protocol, Protocol1>::value>::type* = 0) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a AcceptHandler. BOOST_ASIO_ACCEPT_HANDLER_CHECK(AcceptHandler, handler) type_check; return this->get_service().async_accept(this->get_implementation(), peer, static_cast<endpoint_type*>(0), BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler)); }
async_accept(implementation_type& impl, basic_socket<Protocol1, SocketService>& peer, endpoint_type* peer_endpoint, BOOST_ASIO_MOVE_ARG(AcceptHandler) handler, typename enable_if< is_convertible<Protocol, Protocol1>::value>::type* = 0) { boost::asio::detail::async_result_init<AcceptHandler, void(boost::system::error_code)> init(BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler)); { boost::recursive_mutex::scoped_lock lock_state(impl->state_mutex); if (impl->closed) { auto handler_to_post = [init]() mutable { init.handler( boost::system::error_code(ssf::error::not_connected, ssf::error::get_ssf_category())); }; this->get_io_service().post(handler_to_post); return init.result.get(); } } boost::system::error_code ec; auto fiber_impl = peer.native_handle(); fiber_impl->p_fib_demux = impl->p_fib_demux; fiber_impl->id.set_local_port(impl->id.local_port()); BOOST_LOG_TRIVIAL(debug) << "fiber acceptor: local port set " << impl->id.local_port(); typedef detail::pending_accept_operation< AcceptHandler, typename Protocol::socket_type> op; typename op::ptr p = { boost::asio::detail::addressof(init.handler), boost_asio_handler_alloc_helpers::allocate(sizeof(op), init.handler), 0}; p.p = new (p.v) op(peer.native_handle(), &(peer.native_handle()->id), init.handler); { boost::recursive_mutex::scoped_lock lock(impl->accept_op_queue_mutex); impl->accept_op_queue.push(p.p); } p.v = p.p = 0; impl->a_queues_handler(); return init.result.get(); }
// @end code // @begin example // void receive_header_handler(const boost::system::error_code& ec) // { // if (!ec) // { // // 请求成功! // } // } // ... // avhttp::http_stream h(io_service); // ... // h.async_recvive_header(boost::bind(&receive_header_handler, boost::asio::placeholders::error)); // @end example template <typename Handler> void async_receive_header(BOOST_ASIO_MOVE_ARG(Handler) handler); ///清除读写缓冲区数据. // @备注: 非线程安全! 不应在正在进行读写操作时进行该操作! AVHTTP_DECL void clear(); ///关闭http_stream. // @失败抛出asio::system_error异常. // @备注: 停止所有正在进行的读写操作, 正在进行的异步调用将回调 // boost::asio::error::operation_aborted错误. AVHTTP_DECL void close(); ///关闭http_stream. // @param ec保存失败信息. // @备注: 停止所有正在进行的读写操作, 正在进行的异步调用将回调 // boost::asio::error::operation_aborted错误.
{ return service_impl_.cancel(impl, ec); } // Wait for a signaled state. void wait(implementation_type& impl, boost::system::error_code& ec) { service_impl_.wait(impl, ec); } /// Start an asynchronous wait. template <typename WaitHandler> BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler, void (boost::system::error_code)) async_wait(implementation_type& impl, BOOST_ASIO_MOVE_ARG(WaitHandler) handler) { boost::asio::detail::async_result_init< WaitHandler, void (boost::system::error_code)> init( BOOST_ASIO_MOVE_CAST(WaitHandler)(handler)); service_impl_.async_wait(impl, init.handler); return init.result.get(); } private: // Destroy all user-defined handler objects owned by the service. void shutdown_service() { service_impl_.shutdown_service();
* not, the handler will not be invoked from within this function. Invocation of * the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). * * @note This overload is equivalent to calling: * @code boost::asio::async_read_at( * d, 42, b, * boost::asio::transfer_all(), * handler); @endcode */ template <typename AsyncRandomAccessReadDevice, typename Allocator, typename ReadHandler> BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) async_read_at(AsyncRandomAccessReadDevice& d, uint64_t offset, basic_streambuf<Allocator>& b, BOOST_ASIO_MOVE_ARG(ReadHandler) handler); /// Start an asynchronous operation to read a certain amount of data at the /// specified offset. /** * This function is used to asynchronously read a certain number of bytes of * data from a random access device at the specified offset. The function call * always returns immediately. The asynchronous operation will continue until * one of the following conditions is true: * * @li The completion_condition function object returns 0. * * This operation is implemented in terms of zero or more calls to the device's * async_read_some_at function. * * @param d The device from which the data is to be read. The type must support
* * @param type The type of handshaking to be performed, i.e. as a client or as * a server. * * @param handler The handler to be called when the handshake operation * completes. Copies will be made of the handler as required. The equivalent * function signature of the handler must be: * @code void handler( * const boost::system::error_code& error // Result of operation. * ); @endcode */ template <typename HandshakeHandler> BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void (boost::system::error_code)) async_handshake(handshake_type type, BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a HandshakeHandler. BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check; boost::asio::detail::async_result_init< HandshakeHandler, void (boost::system::error_code)> init( BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler)); detail::async_io(next_layer_, core_, detail::handshake_op(type), init.handler); return init.result.get(); }
/// completes. /** * This function is used to launch a new coroutine. * * @param handler A handler to be called when the coroutine exits. More * importantly, the handler provides an execution context (via the the handler * invocation hook) for the coroutine. The handler must have the signature: * @code void handler(); @endcode * * @param function The coroutine function. The function must have the signature: * @code void function(basic_yield_context<Handler> yield); @endcode * * @param attributes Boost.Coroutine attributes used to customise the coroutine. */ template <typename Handler, typename Function> void spawn(BOOST_ASIO_MOVE_ARG(Handler) handler, BOOST_ASIO_MOVE_ARG(Function) function, const pdalboost::coroutines::attributes& attributes = pdalboost::coroutines::attributes()); /// Start a new stackful coroutine, inheriting the execution context of another. /** * This function is used to launch a new coroutine. * * @param ctx Identifies the current coroutine as a parent of the new * coroutine. This specifies that the new coroutine should inherit the * execution context of the parent. For example, if the parent coroutine is * executing in a particular strand, then the new coroutine will execute in the * same strand. * * @param function The coroutine function. The function must have the signature:
* @li Constructs an object @c result of type <tt>async_result<Handler></tt>, * initializing the object as <tt>result(handler)</tt>. * * @li Obtains the handler's associated executor object @c ex by performing * <tt>get_associated_executor(handler)</tt>. * * @li Obtains the handler's associated allocator object @c alloc by performing * <tt>get_associated_allocator(handler)</tt>. * * @li Performs <tt>ex.dispatch(std::move(handler), alloc)</tt>. * * @li Returns <tt>result.get()</tt>. */ template <typename CompletionToken> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) dispatch( BOOST_ASIO_MOVE_ARG(CompletionToken) token); /// Submits a completion token or function object for execution. /** * This function submits an object for execution using the specified executor. * The function object is queued for execution, and is never called from the * current thread prior to returning from <tt>dispatch()</tt>. * * This function has the following effects: * * @li Constructs a function object handler of type @c Handler, initialized * with <tt>handler(forward<CompletionToken>(token))</tt>. * * @li Constructs an object @c result of type <tt>async_result<Handler></tt>, * initializing the object as <tt>result(handler)</tt>. *
template <typename CompletionHandler> void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) const { typedef typename decay<CompletionHandler>::type DecayedHandler; typename associated_executor<DecayedHandler>::type ex( (get_associated_executor)(handler)); typename associated_allocator<DecayedHandler>::type alloc( (get_associated_allocator)(handler)); ex.dispatch(BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler), alloc); } template <typename CompletionHandler, typename Executor> void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler, BOOST_ASIO_MOVE_ARG(Executor) ex) const { typedef typename decay<CompletionHandler>::type DecayedHandler; typename associated_allocator<DecayedHandler>::type alloc( (get_associated_allocator)(handler)); ex.dispatch(detail::work_dispatcher<DecayedHandler>( BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc); } }; } // namespace detail template <typename CompletionToken>
#include <boost/asio/detail/type_traits.hpp> #include <boost/asio/system_context.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { inline system_context& system_executor::context() const BOOST_ASIO_NOEXCEPT { return detail::global<system_context>(); } template <typename Function, typename Allocator> void system_executor::dispatch( BOOST_ASIO_MOVE_ARG(Function) f, const Allocator&) const { typename decay<Function>::type tmp(BOOST_ASIO_MOVE_CAST(Function)(f)); boost_asio_handler_invoke_helpers::invoke(tmp, tmp); } template <typename Function, typename Allocator> void system_executor::post( BOOST_ASIO_MOVE_ARG(Function) f, const Allocator& a) const { typedef typename decay<Function>::type function_type; system_context& ctx = detail::global<system_context>(); // Allocate and construct an operation to wrap the function. typedef detail::executor_op<function_type, Allocator> op;
#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(BOOST_ASIO_MOVE_ARG(H) h, const Alloc& allocator) : Operation(&executor_op::do_complete), handler_(BOOST_ASIO_MOVE_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. executor_op* o(static_cast<executor_op*>(base)); Alloc allocator(o->allocator_); ptr p = { detail::addressof(allocator), o, o };
* } * } * * ... * * boost::asio::posix::stream_descriptor descriptor(io_context); * ... * descriptor.async_wait( * boost::asio::posix::stream_descriptor::wait_read, * wait_handler); * @endcode */ template <typename WaitHandler> BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler, void (boost::system::error_code)) async_wait(wait_type w, BOOST_ASIO_MOVE_ARG(WaitHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a WaitHandler. BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check; async_completion<WaitHandler, void (boost::system::error_code)> init(handler); this->get_service().async_wait( this->get_implementation(), w, init.completion_handler); return init.result.get(); } protected:
* { * // Accept succeeded. * } * } * * ... * * boost::asio::ip::tcp::acceptor acceptor(io_service); * ... * boost::asio::ip::tcp::socket socket(io_service); * acceptor.async_accept(socket, accept_handler); * @endcode */ template <typename SocketService, typename AcceptHandler> void async_accept(basic_socket<protocol_type, SocketService>& peer, BOOST_ASIO_MOVE_ARG(AcceptHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a AcceptHandler. BOOST_ASIO_ACCEPT_HANDLER_CHECK(AcceptHandler, handler) type_check; this->get_service().async_accept(this->get_implementation(), peer, 0, BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler)); } /// Accept a new connection and obtain the endpoint of the peer /** * This function is used to accept a new connection from a peer into the * given socket, and additionally provide the endpoint of the remote peer. * The function call will block until a new connection has been accepted * successfully or an error occurs.
: public basic_io_object<RegistrationService> { public: explicit basic_registration(io_service& io, std::string name) // eventually, this will have to be wstring or // something - name is UTF-8 [dns-sd.h : 883] : basic_io_object<RegistrationService>(io) { } /// Commit a registration template <typename CommitHandler> inline BOOST_ASIO_INITFN_RESULT_TYPE(CommitHandler, void(boost::system::error_code)) async_commit(BOOST_ASIO_MOVE_ARG(CommitHandler) handler) { return this->get_service().async_commit( this->get_implementation(), BOOST_ASIO_MOVE_CAST(CommitHandler)(handler)); } }; typedef basic_registration<registration_service> registration; } // namespace dnssd } // namespace ip } // namespace asio } // namespace boost
if(timeout == Duration::zero()) { //TODO this can return false if it failed impl.send(m); return message(); } else { return impl.send_with_reply_and_block(m, chrono::milliseconds(timeout).count()); } } template<typename MessageHandler> inline BOOST_ASIO_INITFN_RESULT_TYPE(MessageHandler, void(boost::system::error_code, message)) async_send(implementation_type& impl, message& m, BOOST_ASIO_MOVE_ARG(MessageHandler) handler) { // begin asynchronous operation impl.start(this->get_io_service()); boost::asio::detail::async_result_init< MessageHandler, void(boost::system::error_code, message)> init( BOOST_ASIO_MOVE_CAST(MessageHandler)(handler)); detail::async_send_op< BOOST_ASIO_HANDLER_TYPE(MessageHandler, void(boost::system::error_code, message))>( this->get_io_service(), BOOST_ASIO_MOVE_CAST(MessageHandler)(init.handler)) (impl, m); return init.result.get();
return stream_impl_.next_layer().flush(); } /// Flush all data from the buffer to the next layer. Returns the number of /// bytes written to the next layer on the last write operation, or 0 if an /// error occurred. std::size_t flush(boost::system::error_code& ec) { return stream_impl_.next_layer().flush(ec); } /// Start an asynchronous flush. template <typename WriteHandler> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (boost::system::error_code, std::size_t)) async_flush(BOOST_ASIO_MOVE_ARG(WriteHandler) handler) { return stream_impl_.next_layer().async_flush( BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); } /// Write the given data to the stream. Returns the number of bytes written. /// Throws an exception on failure. template <typename ConstBufferSequence> std::size_t write_some(const ConstBufferSequence& buffers) { return stream_impl_.write_some(buffers); } /// Write the given data to the stream. Returns the number of bytes written, /// or 0 if an error occurred.
virtual ~basic_coproto_handle() { //std::cout << "coproto_handle destructor" << std::endl; } std::string request() const { return this->service.request(this->implementation); } void request(const std::string& req) { this->service.request(this->implementation, req); } template <typename DoHandler> BOOST_ASIO_INITFN_RESULT_TYPE(DoHandler, void (boost::system::error_code, std::string)) async_do(BOOST_ASIO_MOVE_ARG(DoHandler) handler) { // HANDLER_CHECK macro needs to be created and called return this->service.async_do(this->implementation, BOOST_ASIO_MOVE_CAST(DoHandler)(handler)); } }; typedef basic_coproto_handle<std::string, QueueManager > coproto_handle; #endif /* COPROTO_HANDLE_HPP_ */
* @li The timer was cancelled, in which case the handler is passed the error * code boost::asio::error::operation_aborted. * * @param handler The handler to be called when the timer expires. Copies * will be made of the handler as required. The function signature of the * handler must be: * @code void handler( * const boost::system::error_code& error // Result of operation. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). */ template <typename WaitHandler> void async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a WaitHandler. BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check; this->service.async_wait(this->implementation, BOOST_ASIO_MOVE_CAST(WaitHandler)(handler)); } }; } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp>
namespace asio { /** * @defgroup connect boost::asio::connect * * @brief Establishes a socket connection by trying each endpoint in a sequence. */ /*@{*/ /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @throws boost::system::system_error Thrown on failure. If the sequence is * empty, the associated @c error_code is boost::asio::error::not_found. * Otherwise, contains the error from the last connection attempt. * * @note This overload assumes that a default constructed object of type @c * Iterator represents the end of the sequence. This is a valid assumption for * iterator types such as @c boost::asio::ip::tcp::resolver::iterator. * * @par Example * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * boost::asio::connect(s, r.resolve(q)); @endcode */ template <typename Protocol, typename SocketService, typename Iterator> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param ec Set to indicate what error occurred, if any. If the sequence is * empty, set to boost::asio::error::not_found. Otherwise, contains the error * from the last connection attempt. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @note This overload assumes that a default constructed object of type @c * Iterator represents the end of the sequence. This is a valid assumption for * iterator types such as @c boost::asio::ip::tcp::resolver::iterator. * * @par Example * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * boost::system::error_code ec; * boost::asio::connect(s, r.resolve(q), ec); * if (ec) * { * // An error occurred. * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, boost::system::error_code& ec); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @throws boost::system::system_error Thrown on failure. If the sequence is * empty, the associated @c error_code is boost::asio::error::not_found. * Otherwise, contains the error from the last connection attempt. * * @par Example * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::resolver::iterator i = r.resolve(q), end; * tcp::socket s(io_service); * boost::asio::connect(s, i, end); @endcode */ template <typename Protocol, typename SocketService, typename Iterator> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator end); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints. * * @param ec Set to indicate what error occurred, if any. If the sequence is * empty, set to boost::asio::error::not_found. Otherwise, contains the error * from the last connection attempt. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @par Example * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::resolver::iterator i = r.resolve(q), end; * tcp::socket s(io_service); * boost::system::error_code ec; * boost::asio::connect(s, i, end, ec); * if (ec) * { * // An error occurred. * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator end, boost::system::error_code& ec); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param connect_condition A function object that is called prior to each * connection attempt. The signature of the function object must be: * @code Iterator connect_condition( * const boost::system::error_code& ec, * Iterator next); @endcode * The @c ec parameter contains the result from the most recent connect * operation. Before the first connection attempt, @c ec is always set to * indicate success. The @c next parameter is an iterator pointing to the next * endpoint to be tried. The function object should return the next iterator, * but is permitted to return a different iterator so that endpoints may be * skipped. The implementation guarantees that the function object will never * be called with the end iterator. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @throws boost::system::system_error Thrown on failure. If the sequence is * empty, the associated @c error_code is boost::asio::error::not_found. * Otherwise, contains the error from the last connection attempt. * * @note This overload assumes that a default constructed object of type @c * Iterator represents the end of the sequence. This is a valid assumption for * iterator types such as @c boost::asio::ip::tcp::resolver::iterator. * * @par Example * The following connect condition function object can be used to output * information about the individual connection attempts: * @code struct my_connect_condition * { * template <typename Iterator> * Iterator operator()( * const boost::system::error_code& ec, * Iterator next) * { * if (ec) std::cout << "Error: " << ec.message() << std::endl; * std::cout << "Trying: " << next->endpoint() << std::endl; * return next; * } * }; @endcode * It would be used with the boost::asio::connect function as follows: * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * tcp::resolver::iterator i = boost::asio::connect( * s, r.resolve(q), my_connect_condition()); * std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, ConnectCondition connect_condition); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param connect_condition A function object that is called prior to each * connection attempt. The signature of the function object must be: * @code Iterator connect_condition( * const boost::system::error_code& ec, * Iterator next); @endcode * The @c ec parameter contains the result from the most recent connect * operation. Before the first connection attempt, @c ec is always set to * indicate success. The @c next parameter is an iterator pointing to the next * endpoint to be tried. The function object should return the next iterator, * but is permitted to return a different iterator so that endpoints may be * skipped. The implementation guarantees that the function object will never * be called with the end iterator. * * @param ec Set to indicate what error occurred, if any. If the sequence is * empty, set to boost::asio::error::not_found. Otherwise, contains the error * from the last connection attempt. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @note This overload assumes that a default constructed object of type @c * Iterator represents the end of the sequence. This is a valid assumption for * iterator types such as @c boost::asio::ip::tcp::resolver::iterator. * * @par Example * The following connect condition function object can be used to output * information about the individual connection attempts: * @code struct my_connect_condition * { * template <typename Iterator> * Iterator operator()( * const boost::system::error_code& ec, * Iterator next) * { * if (ec) std::cout << "Error: " << ec.message() << std::endl; * std::cout << "Trying: " << next->endpoint() << std::endl; * return next; * } * }; @endcode * It would be used with the boost::asio::connect function as follows: * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * boost::system::error_code ec; * tcp::resolver::iterator i = boost::asio::connect( * s, r.resolve(q), my_connect_condition(), ec); * if (ec) * { * // An error occurred. * } * else * { * std::cout << "Connected to: " << i->endpoint() << std::endl; * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, ConnectCondition connect_condition, boost::system::error_code& ec); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints. * * @param connect_condition A function object that is called prior to each * connection attempt. The signature of the function object must be: * @code Iterator connect_condition( * const boost::system::error_code& ec, * Iterator next); @endcode * The @c ec parameter contains the result from the most recent connect * operation. Before the first connection attempt, @c ec is always set to * indicate success. The @c next parameter is an iterator pointing to the next * endpoint to be tried. The function object should return the next iterator, * but is permitted to return a different iterator so that endpoints may be * skipped. The implementation guarantees that the function object will never * be called with the end iterator. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @throws boost::system::system_error Thrown on failure. If the sequence is * empty, the associated @c error_code is boost::asio::error::not_found. * Otherwise, contains the error from the last connection attempt. * * @par Example * The following connect condition function object can be used to output * information about the individual connection attempts: * @code struct my_connect_condition * { * template <typename Iterator> * Iterator operator()( * const boost::system::error_code& ec, * Iterator next) * { * if (ec) std::cout << "Error: " << ec.message() << std::endl; * std::cout << "Trying: " << next->endpoint() << std::endl; * return next; * } * }; @endcode * It would be used with the boost::asio::connect function as follows: * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::resolver::iterator i = r.resolve(q), end; * tcp::socket s(io_service); * i = boost::asio::connect(s, i, end, my_connect_condition()); * std::cout << "Connected to: " << i->endpoint() << std::endl; @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator end, ConnectCondition connect_condition); /// Establishes a socket connection by trying each endpoint in a sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c connect member * function, once for each endpoint in the sequence, until a connection is * successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints. * * @param connect_condition A function object that is called prior to each * connection attempt. The signature of the function object must be: * @code Iterator connect_condition( * const boost::system::error_code& ec, * Iterator next); @endcode * The @c ec parameter contains the result from the most recent connect * operation. Before the first connection attempt, @c ec is always set to * indicate success. The @c next parameter is an iterator pointing to the next * endpoint to be tried. The function object should return the next iterator, * but is permitted to return a different iterator so that endpoints may be * skipped. The implementation guarantees that the function object will never * be called with the end iterator. * * @param ec Set to indicate what error occurred, if any. If the sequence is * empty, set to boost::asio::error::not_found. Otherwise, contains the error * from the last connection attempt. * * @returns On success, an iterator denoting the successfully connected * endpoint. Otherwise, the end iterator. * * @par Example * The following connect condition function object can be used to output * information about the individual connection attempts: * @code struct my_connect_condition * { * template <typename Iterator> * Iterator operator()( * const boost::system::error_code& ec, * Iterator next) * { * if (ec) std::cout << "Error: " << ec.message() << std::endl; * std::cout << "Trying: " << next->endpoint() << std::endl; * return next; * } * }; @endcode * It would be used with the boost::asio::connect function as follows: * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::resolver::iterator i = r.resolve(q), end; * tcp::socket s(io_service); * boost::system::error_code ec; * i = boost::asio::connect(s, i, end, my_connect_condition(), ec); * if (ec) * { * // An error occurred. * } * else * { * std::cout << "Connected to: " << i->endpoint() << std::endl; * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition> Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator end, ConnectCondition connect_condition, boost::system::error_code& ec); /*@}*/ /** * @defgroup async_connect boost::asio::async_connect * * @brief Asynchronously establishes a socket connection by trying each * endpoint in a sequence. */ /*@{*/ /// Asynchronously establishes a socket connection by trying each endpoint in a /// sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c async_connect * member function, once for each endpoint in the sequence, until a connection * is successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param handler The handler to be called when the connect operation * completes. Copies will be made of the handler as required. The function * signature of the handler must be: * @code void handler( * // Result of operation. if the sequence is empty, set to * // boost::asio::error::not_found. Otherwise, contains the * // error from the last connection attempt. * const boost::system::error_code& error, * * // On success, an iterator denoting the successfully * // connected endpoint. Otherwise, the end iterator. * Iterator iterator * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). * * @note This overload assumes that a default constructed object of type @c * Iterator represents the end of the sequence. This is a valid assumption for * iterator types such as @c boost::asio::ip::tcp::resolver::iterator. * * @par Example * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * * // ... * * r.async_resolve(q, resolve_handler); * * // ... * * void resolve_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * if (!ec) * { * boost::asio::async_connect(s, i, connect_handler); * } * } * * // ... * * void connect_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * // ... * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> void async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler); /// Asynchronously establishes a socket connection by trying each endpoint in a /// sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c async_connect * member function, once for each endpoint in the sequence, until a connection * is successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints. * * @param handler The handler to be called when the connect operation * completes. Copies will be made of the handler as required. The function * signature of the handler must be: * @code void handler( * // Result of operation. if the sequence is empty, set to * // boost::asio::error::not_found. Otherwise, contains the * // error from the last connection attempt. * const boost::system::error_code& error, * * // On success, an iterator denoting the successfully * // connected endpoint. Otherwise, the end iterator. * Iterator iterator * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). * * @par Example * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * * // ... * * r.async_resolve(q, resolve_handler); * * // ... * * void resolve_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * if (!ec) * { * tcp::resolver::iterator end; * boost::asio::async_connect(s, i, end, connect_handler); * } * } * * // ... * * void connect_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * // ... * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> void async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator end, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler); /// Asynchronously establishes a socket connection by trying each endpoint in a /// sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c async_connect * member function, once for each endpoint in the sequence, until a connection * is successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param connect_condition A function object that is called prior to each * connection attempt. The signature of the function object must be: * @code Iterator connect_condition( * const boost::system::error_code& ec, * Iterator next); @endcode * The @c ec parameter contains the result from the most recent connect * operation. Before the first connection attempt, @c ec is always set to * indicate success. The @c next parameter is an iterator pointing to the next * endpoint to be tried. The function object should return the next iterator, * but is permitted to return a different iterator so that endpoints may be * skipped. The implementation guarantees that the function object will never * be called with the end iterator. * * @param handler The handler to be called when the connect operation * completes. Copies will be made of the handler as required. The function * signature of the handler must be: * @code void handler( * // Result of operation. if the sequence is empty, set to * // boost::asio::error::not_found. Otherwise, contains the * // error from the last connection attempt. * const boost::system::error_code& error, * * // On success, an iterator denoting the successfully * // connected endpoint. Otherwise, the end iterator. * Iterator iterator * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). * * @note This overload assumes that a default constructed object of type @c * Iterator represents the end of the sequence. This is a valid assumption for * iterator types such as @c boost::asio::ip::tcp::resolver::iterator. * * @par Example * The following connect condition function object can be used to output * information about the individual connection attempts: * @code struct my_connect_condition * { * template <typename Iterator> * Iterator operator()( * const boost::system::error_code& ec, * Iterator next) * { * if (ec) std::cout << "Error: " << ec.message() << std::endl; * std::cout << "Trying: " << next->endpoint() << std::endl; * return next; * } * }; @endcode * It would be used with the boost::asio::connect function as follows: * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * * // ... * * r.async_resolve(q, resolve_handler); * * // ... * * void resolve_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * if (!ec) * { * boost::asio::async_connect(s, i, * my_connect_condition(), * connect_handler); * } * } * * // ... * * void connect_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * if (ec) * { * // An error occurred. * } * else * { * std::cout << "Connected to: " << i->endpoint() << std::endl; * } * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition, typename ComposedConnectHandler> void async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin, ConnectCondition connect_condition, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler); /// Asynchronously establishes a socket connection by trying each endpoint in a /// sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c async_connect * member function, once for each endpoint in the sequence, until a connection * is successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints. * * @param connect_condition A function object that is called prior to each * connection attempt. The signature of the function object must be: * @code Iterator connect_condition( * const boost::system::error_code& ec, * Iterator next); @endcode * The @c ec parameter contains the result from the most recent connect * operation. Before the first connection attempt, @c ec is always set to * indicate success. The @c next parameter is an iterator pointing to the next * endpoint to be tried. The function object should return the next iterator, * but is permitted to return a different iterator so that endpoints may be * skipped. The implementation guarantees that the function object will never * be called with the end iterator. * * @param handler The handler to be called when the connect operation * completes. Copies will be made of the handler as required. The function * signature of the handler must be: * @code void handler( * // Result of operation. if the sequence is empty, set to * // boost::asio::error::not_found. Otherwise, contains the * // error from the last connection attempt. * const boost::system::error_code& error, * * // On success, an iterator denoting the successfully * // connected endpoint. Otherwise, the end iterator. * Iterator iterator * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). * * @par Example * The following connect condition function object can be used to output * information about the individual connection attempts: * @code struct my_connect_condition * { * template <typename Iterator> * Iterator operator()( * const boost::system::error_code& ec, * Iterator next) * { * if (ec) std::cout << "Error: " << ec.message() << std::endl; * std::cout << "Trying: " << next->endpoint() << std::endl; * return next; * } * }; @endcode * It would be used with the boost::asio::connect function as follows: * @code tcp::resolver r(io_service); * tcp::resolver::query q("host", "service"); * tcp::socket s(io_service); * * // ... * * r.async_resolve(q, resolve_handler); * * // ... * * void resolve_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * if (!ec) * { * tcp::resolver::iterator end; * boost::asio::async_connect(s, i, end, * my_connect_condition(), * connect_handler); * } * } * * // ... * * void connect_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * if (ec) * { * // An error occurred. * } * else * { * std::cout << "Connected to: " << i->endpoint() << std::endl; * } * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ConnectCondition, typename ComposedConnectHandler> void async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator end, ConnectCondition connect_condition, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler); /*@}*/ } // namespace asio
* inside this function if the guarantee can be met. If this function is * called from within a handler that was posted or dispatched through the same * strand, then the new handler will be executed immediately. * * The strand's guarantee is in addition to the guarantee provided by the * underlying io_service. The io_service guarantees that the handler will only * be called in a thread in which the io_service's run member function is * currently being invoked. * * @param handler The handler to be called. The strand will make a copy of the * handler object as required. The function signature of the handler must be: * @code void handler(); @endcode */ template <typename CompletionHandler> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ()) dispatch(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a CompletionHandler. BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check; detail::async_result_init< CompletionHandler, void ()> init( BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)); service_.dispatch(impl_, init.handler); return init.result.get(); } /// Request the strand to invoke the given handler and return
// void tail_handler(const boost::system::error_code& ec) // { // if (!ec) // { // // 发送成功! // } // } // ... // avhttp::file_upload f(io_service); // ... // f.async_write_tail(handler); // @end example // @备注: handler也可以使用boost.bind来绑定一个符合规定的函数作 // 为async_open的参数handler. template <typename Handler> void async_write_tail(BOOST_ASIO_MOVE_ARG(Handler) handler); ///设置http header选项. AVHTTP_DECL void request_option(request_opts& opts); ///返回http_stream对象的引用. AVHTTP_DECL http_stream& get_http_stream(); ///反回当前file_upload所使用的io_service的引用. AVHTTP_DECL boost::asio::io_service& get_io_service(); private: template <typename Handler> struct open_coro;
* @param handler The handler to be called when the accept operation * completes. Copies will be made of the handler as required. The function * signature of the handler must be: * @code void handler( * const lslboost::system::error_code& error // Result of operation. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * lslboost::asio::io_service::post(). */ template <typename SocketService, typename AcceptHandler> BOOST_ASIO_INITFN_RESULT_TYPE(AcceptHandler, void (lslboost::system::error_code)) async_accept(basic_socket<protocol_type, SocketService>& peer, endpoint_type& peer_endpoint, BOOST_ASIO_MOVE_ARG(AcceptHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a AcceptHandler. BOOST_ASIO_ACCEPT_HANDLER_CHECK(AcceptHandler, handler) type_check; return this->get_service().async_accept(this->get_implementation(), peer, &peer_endpoint, BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler)); } }; } // namespace asio } // namespace lslboost #include <lslboost/asio/detail/pop_options.hpp>
* @param handler The handler to be called when the signal occurs. Copies * will be made of the handler as required. The function signature of the * handler must be: * @code void handler( * const boost::system::error_code& error, // Result of operation. * int signal_number // Indicates which signal occurred. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation * of the handler will be performed in a manner equivalent to using * boost::asio::io_service::post(). */ template <typename SignalHandler> BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler, void (boost::system::error_code, int)) async_wait(BOOST_ASIO_MOVE_ARG(SignalHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a SignalHandler. BOOST_ASIO_SIGNAL_HANDLER_CHECK(SignalHandler, handler) type_check; return this->service.async_wait(this->implementation, BOOST_ASIO_MOVE_CAST(SignalHandler)(handler)); } }; } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp>
* * // ... * * void connect_handler( * const boost::system::error_code& ec, * tcp::resolver::iterator i) * { * // ... * } @endcode */ template <typename Protocol, typename SocketService, typename Iterator, typename ComposedConnectHandler> BOOST_ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler, void (boost::system::error_code, Iterator)) async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin, BOOST_ASIO_MOVE_ARG(ComposedConnectHandler) handler); /// Asynchronously establishes a socket connection by trying each endpoint in a /// sequence. /** * This function attempts to connect a socket to one of a sequence of * endpoints. It does this by repeated calls to the socket's @c async_connect * member function, once for each endpoint in the sequence, until a connection * is successfully established. * * @param s The socket to be connected. If the socket is already open, it will * be closed. * * @param begin An iterator pointing to the start of a sequence of endpoints. * * @param end An iterator pointing to the end of a sequence of endpoints.
/** * This function is used to ask the strand to execute the given function * object on its underlying executor. The function object will be executed * inside this function if the strand is not otherwise busy and if the * underlying executor's @c dispatch() function is also able to execute the * function before returning. * * @param f The function object to be called. The executor will make * a copy of the handler object as required. The function signature of the * function object must be: @code void function(); @endcode * * @param a An allocator that may be used by the executor to allocate the * internal storage needed for function invocation. */ template <typename Function, typename Allocator> void dispatch(BOOST_ASIO_MOVE_ARG(Function) f, const Allocator& a) const { detail::strand_executor_service::dispatch(impl_, executor_, BOOST_ASIO_MOVE_CAST(Function)(f), a); } /// Request the strand to invoke the given function object. /** * This function is used to ask the executor to execute the given function * object. The function object will never be executed inside this function. * Instead, it will be scheduled by the underlying executor's defer function. * * @param f The function object to be called. The executor will make * a copy of the handler object as required. The function signature of the * function object must be: @code void function(); @endcode *
return service_impl_.clear(impl, ec); } /// Cancel all operations associated with the signal set. lslboost::system::error_code cancel(implementation_type& impl, lslboost::system::error_code& ec) { return service_impl_.cancel(impl, ec); } // Start an asynchronous operation to wait for a signal to be delivered. template <typename SignalHandler> BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler, void (lslboost::system::error_code, int)) async_wait(implementation_type& impl, BOOST_ASIO_MOVE_ARG(SignalHandler) handler) { detail::async_result_init< SignalHandler, void (lslboost::system::error_code, int)> init( BOOST_ASIO_MOVE_CAST(SignalHandler)(handler)); service_impl_.async_wait(impl, init.handler); return init.result.get(); } private: // Destroy all user-defined handler objects owned by the service. void shutdown_service() { service_impl_.shutdown_service();
# include <boost/bind.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_BIND) # include <functional> #endif // defined(BOOST_ASIO_HAS_BOOST_BIND) namespace archetypes { #if defined(BOOST_ASIO_HAS_BOOST_BIND) namespace bindns = boost; #else // defined(BOOST_ASIO_HAS_BOOST_BIND) namespace bindns = std; #endif // defined(BOOST_ASIO_HAS_BOOST_BIND) template <typename CompletionToken> BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) async_op_0(BOOST_ASIO_MOVE_ARG(CompletionToken) token) { typedef typename boost::asio::async_completion<CompletionToken, void()>::completion_handler_type handler_type; boost::asio::async_completion<CompletionToken, void()> completion(token); typename boost::asio::associated_allocator<handler_type>::type a = boost::asio::get_associated_allocator(completion.completion_handler); typename boost::asio::associated_executor<handler_type>::type ex = boost::asio::get_associated_executor(completion.completion_handler); ex.post(BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler), a);
template <typename Function, typename ReadHandler> inline void asio_handler_invoke(const Function& function, buffered_fill_handler<ReadHandler>* this_handler) { boost_asio_handler_invoke_helpers::invoke( function, this_handler->handler_); } } // namespace detail template <typename Stream> template <typename ReadHandler> BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) buffered_read_stream<Stream>::async_fill( BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { // If you get an error on the following line it means that your handler does // not meet the documented type requirements for a ReadHandler. BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; detail::async_result_init< ReadHandler, void (boost::system::error_code, std::size_t)> init( BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); std::size_t previous_size = storage_.size(); storage_.resize(storage_.capacity()); next_layer_.async_read_some( buffer( storage_.data() + previous_size, storage_.size() - previous_size),
* * std::size_t bytes_transferred // Number of bytes written from the * // buffers. If an error occurred, * // this will be less than the sum * // of the buffer sizes. * ); @endcode * Regardless of whether the asynchronous operation completes immediately or * not, the handler will not be invoked from within this function. Invocation of * the handler will be performed in a manner equivalent to using * pdalboost::asio::io_service::post(). */ template <typename AsyncWriteStream, typename Allocator, typename WriteHandler> BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (pdalboost::system::error_code, std::size_t)) async_write(AsyncWriteStream& s, basic_streambuf<Allocator>& b, BOOST_ASIO_MOVE_ARG(WriteHandler) handler); /// Start an asynchronous operation to write a certain amount of data to a /// stream. /** * This function is used to asynchronously write a certain number of bytes of * data to a stream. The function call always returns immediately. The * asynchronous operation will continue until one of the following conditions * is true: * * @li All of the data in the supplied basic_streambuf has been written. * * @li The completion_condition function object returns 0. * * This operation is implemented in terms of zero or more calls to the stream's * async_write_some function, and is known as a <em>composed operation</em>. The