Boost Asio总结(15)class basic_stream_socket
生活随笔
收集整理的這篇文章主要介紹了
Boost Asio总结(15)class basic_stream_socket
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.
. 多種構造函數重載
一個參數:I/O服務
兩個參數:1.I/O服務和協議;2.I/O服務和socket端點
. send()/receive()和write_some()/read_some()區別
相同:
功能完全相同;寫數據和讀數據。
不同:
send()/receive()有多種重載
. 異步讀寫函數
1.1
template <typename Protocol, typename Executor> class basic_stream_socket: public basic_socket<Protocol, Executor> { public:/// The type of the executor associated with the object.typedef Executor executor_type;//構造函數explicit basic_stream_socket(const executor_type& ex): basic_socket<Protocol, Executor>(ex){}template <typename ExecutionContext>explicit basic_stream_socket(ExecutionContext& context,typename enable_if<is_convertible<ExecutionContext&, execution_context&>::value>::type* = 0): basic_socket<Protocol, Executor>(context){}basic_stream_socket(const executor_type& ex, const protocol_type& protocol): basic_socket<Protocol, Executor>(ex, protocol){}template <typename ExecutionContext>basic_stream_socket(ExecutionContext& context, const protocol_type& protocol,typename enable_if<is_convertible<ExecutionContext&, execution_context&>::value>::type* = 0): basic_socket<Protocol, Executor>(context, protocol){}basic_stream_socket(const executor_type& ex, const endpoint_type& endpoint): basic_socket<Protocol, Executor>(ex, endpoint){}// sendtemplate <typename ConstBufferSequence>std::size_t send(const ConstBufferSequence& buffers){boost::system::error_code ec;std::size_t s = this->impl_.get_service().send(this->impl_.get_implementation(), buffers, 0, ec);boost::asio::detail::throw_error(ec, "send");return s;}template <typename ConstBufferSequence>std::size_t send(const ConstBufferSequence& buffers,socket_base::message_flags flags){boost::system::error_code ec;std::size_t s = this->impl_.get_service().send(this->impl_.get_implementation(), buffers, flags, ec);boost::asio::detail::throw_error(ec, "send");return s;}template <typename ConstBufferSequence>std::size_t send(const ConstBufferSequence& buffers,socket_base::message_flags flags, boost::system::error_code& ec){return this->impl_.get_service().send(this->impl_.get_implementation(), buffers, flags, ec);}template <typename ConstBufferSequence, typename WriteHandler>BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,void (boost::system::error_code, std::size_t))async_send(const ConstBufferSequence& buffers,BOOST_ASIO_MOVE_ARG(WriteHandler) handler){return async_initiate<WriteHandler,void (boost::system::error_code, std::size_t)>(initiate_async_send(), handler, this,buffers, socket_base::message_flags(0));}template <typename ConstBufferSequence, typename WriteHandler>BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,void (boost::system::error_code, std::size_t))async_send(const ConstBufferSequence& buffers,socket_base::message_flags flags,BOOST_ASIO_MOVE_ARG(WriteHandler) handler){return async_initiate<WriteHandler,void (boost::system::error_code, std::size_t)>(initiate_async_send(), handler, this, buffers, flags);}template <typename MutableBufferSequence>std::size_t receive(const MutableBufferSequence& buffers){boost::system::error_code ec;std::size_t s = this->impl_.get_service().receive(this->impl_.get_implementation(), buffers, 0, ec);boost::asio::detail::throw_error(ec, "receive");return s;}... }總結
以上是生活随笔為你收集整理的Boost Asio总结(15)class basic_stream_socket的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Boost Asio总结(12)clas
- 下一篇: 排序 (2)快速排序