boost::asio学习之[八]acceptor 点滴
来源:互联网 发布:spss mac 价格 编辑:程序博客网 时间:2024/05/16 11:09
acceptoracceptor(io_service);acceptot(io_service, protocol_type);acceptor(io_service, endpoint_type, reuse_address = true);acceptor(io_service, protocol_type, native_handle_type);acceptor(basic_socket_acceptor &&other);types1.0 broadcast Socket option to permit sending of broadcast messages.example udp::socket socket(io_service); socket_base::broadcast option(ture); socket.set_option(option); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value(); 1.1 bytes_readable IO control command to get the amount of data that can be read without blocking.example tcp::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();1.2 debug Socket option to enable socket-level debugging.example Setting the option: tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option); Getting the current option value: tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value(); 1.3 do_not_route Socket option to prevent routing, use local interfaces only.example Setting the option: tcp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option); Getting the current option value: tcp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value(); 1.4 enable_connection_aborted Socket option to report aborted connections on accept. Implements a custom socket option that determines whether or not an accept operation is permitted to fail with boost::asio::error::connection_aborted. By default the option is false.example Setting the option: tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option); Getting the current option value: tcp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; acceptor.get_option(option); bool is_set = option.value(); 1.5 endpoint_type1.6 linger Socket option to specify whether the socket lingers on close if unsent data is present.example Setting the option: boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option); Getting the current option value: boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout(); boost中快速关闭socket代码片段。 创建socket后,设置socket的linger属性 boost::asio::ip::tcp::socket socket(io_service); boost::asio::socket_base::linger option(true, 0); socket.set_option(option); 直接关闭socket socket.close(); 此时socket将会发生reset包给对方,然后直接关闭socket,并清理占有资源。1.7 message_flags Bitmask type for flags that can be passed to send and receive operations.1.8 native_handle The native representation of an acceptor.1.9 non_blocking_io (Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.example boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command); 1.10 protocol_type1.11 receive_buffer_size Socket option for the receive buffer size of a socket.example Setting the option: boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option); Getting the current option value: boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();1.12 receive_low_watermark Socket option for the receive low watermark.example Setting the option: boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option); Getting the current option value: boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();1.13 reuse_address Socket option to allow the socket to be bound to an address that is already in use.example Setting the option: boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option); Getting the current option value: boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value(); 1.14 send_buffer_size1.15 sent_low_watermark1.16 shutdown_type Different ways a socket may be shutdown. shutdown_receive Shutdown the receive side of the socket. shutdown_send Shutdown the send side of the socket. shutdown_both Shutdown both send and receive on the socket. 2 member funtions2.0 accept Accept a new connection and obtain the endpoint of the peer. accept(secket); accept(socket, error_code); accept(socket, endpoint); accept(socket, endpoint, error_code);2.1 assign Assigns an existing native acceptor to the acceptor. assign(protocol_type, native_handle_type); assign(protocol_type, native_handle_type, error_code);2.2 async_accept Start an asynchronous accept. async_accept(socket, handler); async_accept(socket, handler, error_code); void handler(error_code);2.3 bind Bind the acceptor to the given local endpoint. bind(endpoint_type); bind(endpoint_type, error_code);2.4 cancel Cancel all asynchronous operations associated with the acceptor. This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error. cancel(); cancel(error_code);2.5 close This function is used to close the acceptor. Any asynchronous accept operations will be cancelled immediately. A subsequent call to open() is required before the acceptor can again be used to again perform socket accept operations. close(); close(error_code);2.6 get_io_service This function may be used to obtain the io_service object that the I/O object uses to dispatch handlers for asynchronous operations. io_service& get_io_service();2.7 get_option This function is used to get the current value of an option on the acceptor. get_option(TOption& option); get_option(TOption& option, error_code&);example boost::asio::ip::tcp::acceptor acceptor(io_service);...boost::asio::ip::tcp::acceptor::reuse_address option;boost::system::error_code ec;acceptor.get_option(option, ec);if (ec){ // An error occurred.}bool is_set = option.get();2.8 io_control This function is used to execute an IO control command on the acceptor. io_control(TIoControlCommand&); io_control(TIoControlCommand&, error_code&);exampleGetting the number of bytes ready to read:boost::asio::ip::tcp::acceptor acceptor(io_service);...boost::asio::ip::tcp::acceptor::non_blocking_io command(true);boost::system::error_code ec;socket.io_control(command, ec);if (ec){ // An error occurred.}2.9 is_open Determine whether the acceptor is open.2.10 listen Place the acceptor into the state where it will listen for new connections. This function puts the socket acceptor into the state where it may accept new connections. listen(int back_log = sock_base::max_connections); back_log: The maximum length of the queue of pending connections. listen(int back_log, error_code);exampleboost::asio::ip::tcp::acceptor acceptor(io_service);...boost::system::error_code ec;acceptor.listen(boost::asio::socket_base::max_connections, ec);if (ec){ // An error occurred.}2.11 local_endpoint Get the local endpoint of the acceptor. This function is used to obtain the locally bound endpoint of the acceptor. endpoint_type local_endpoint(); endpoint_type local_endpoint(boost::system::error_code & ec);exampleboost::asio::ip::tcp::acceptor acceptor(io_service);...boost::system::error_code ec;boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint(ec);if (ec){ // An error occurred.} 2.12 native Get the native acceptor representation. This function may be used to obtain the underlying representation of the acceptor. This is intended to allow access to native acceptor functionality that is not otherwise provided. native_type native();2.13 native_handle();native_handle_type native_handle();This function may be used to obtain the underlying representation of the acceptor. This is intended to allow access to native acceptor functionality that is not otherwise provided.2.14 open Open the acceptor using the specified protocol. open(const protocol_type & protocol);boost::system::error_code open(const protocol_type & protocol,boost::system::error_code & ec);This function opens the socket acceptor so that it will use the specified protocol.example boost::asio::ip::tcp::acceptor acceptor(io_service);boost::system::error_code ec;acceptor.open(boost::asio::ip::tcp::v4(), ec);if (ec){ // An error occurred.}2.15 set_option Set an option on the acceptor. set_option(option);template<typename SettableSocketOption>boost::system::error_code set_option(const SettableSocketOption & option, boost::system::error_code & ec);This function is used to set an option on the acceptor.example boost::asio::ip::tcp::acceptor acceptor(io_service);...boost::asio::ip::tcp::acceptor::reuse_address option(true);boost::system::error_code ec;acceptor.set_option(option, ec);if (ec){ // An error occurred.}
0 0
- boost::asio学习之[八]acceptor 点滴
- boost.asio 使用点滴
- 一步一步学习 Boost 之 Asio
- boost::asio学习之[一]
- Boost.Asio学习之Tutorial
- Boost.Asio学习之Allocation
- Boost.Asio学习之Buffer
- Boost.Asio学习之总结
- boost::asio学习之[二]boost::asio::strand
- Tomcat学习之Acceptor
- Tomcat学习之Acceptor
- boost asio 学习总结之 io_service
- boost::asio学习之[七] buffer
- Boost Asio 1.56 学习之同步定时器
- boost学习之asio—chat
- Boost.Asio学习之Proactor模式简介
- Boost.Asio学习之实现广播ChatRoom
- 【boost学习】之boost::asio(4)——boost::asio::buffer用法
- ASP.NET: Dispaly data from an Excel Spreadsheet
- 用service来进行查询
- 面对对象必须掌握内容
- iphone数据存储之-- Core Data的使用(一)
- C语言中----局部变量,外部变量,静态变量,寄存器变量
- boost::asio学习之[八]acceptor 点滴
- 动态代理模式的相关细节描述
- 基于Web服务的应用、解决方案和开发平台
- 1000know
- 数据库事务使用范例
- (二)、Openstack 之 oslo.config
- 怎么实现每天自动更新订单状态
- 2014-04-23:error:lpSidString = GetUserSid(hToken);%s在UNICODE的情况很特殊
- Linux 系统下 DDOS 工具 tfn2k 攻击原理详解