namespace boost {
namespace asio {
namespace detail {
// Adapts the FD_SET type to meet the Descriptor_Set concept's requirements.
class win_fd_set_adapter : noncopyable
{
public:
enum {default_fd_set_size= 1024 };
win_fd_set_adapter()
:capacity_(default_fd_set_size),
max_descriptor_(invalid_socket)
{
fd_set_ = static_cast<win_fd_set*>(::operator new(
sizeof(win_fd_set) - sizeof(SOCKET)
+ sizeof(SOCKET) * (capacity_)));
fd_set_->fd_count = 0;
}
~win_fd_set_adapter()
{
::operator delete(fd_set_);
}
void reset()
{
fd_set_->fd_count = 0;
max_descriptor_ = invalid_socket;
}
bool set(socket_type descriptor)
{
for (u_int i = 0; i < fd_set_->fd_count; ++i)
if (fd_set_->fd_array[i] == descriptor)
return true;
if (fd_set_->fd_count ==capacity_)
{
u_intnew_capacity= capacity_ + capacity_ / 2;
win_fd_set* new_fd_set = static_cast<win_fd_set*>(::operator new(
sizeof(win_fd_set) - sizeof(SOCKET)
+ sizeof(SOCKET) * (new_capacity)));
new_fd_set->fd_count = fd_set_->fd_count;
for (u_int i = 0; i < fd_set_->fd_count; ++i)
new_fd_set->fd_array[i] = fd_set_->fd_array[i];
::operator delete(fd_set_);
fd_set_ = new_fd_set;
capacity_=new_capacity;
}
fd_set_->fd_array[fd_set_->fd_count++] = descriptor;
return true;
}
bool is_set(socket_type descriptor) const
{
return !!__WSAFDIsSet(descriptor,
const_cast<fd_set*>(reinterpret_cast<const fd_set*>(fd_set_)));
}
operator fd_set*()
{
return reinterpret_cast<fd_set*>(fd_set_);
}
socket_type max_descriptor() const
{
return max_descriptor_;
}
private:
// This structure is defined to be compatible with the Windows API fd_set
// structure, but without being dependent on the value of FD_SETSIZE. We use
// the "struct hack" to allow the number of descriptors to be varied at
// runtime.
struct win_fd_set
{
u_int fd_count;
SOCKET fd_array[1];
};
win_fd_set* fd_set_;
u_intcapacity_;
socket_type max_descriptor_;
};
} // namespace detail
} // namespace asio
} // namespace boost
相关推荐
利用Boost Asio库开发的大并发量,高性能的网络通讯库,有线程池和即时,定时任务调度功能.zip 利用Boost Asio库开发的大并发量,高性能的网络通讯库,有线程池和即时,定时任务调度功能.zip 利用Boost Asio库开发的...
boost库中asio的简单应用,一个服务器一个客户端
该c++ web server基于boost.asio库编写,同时支持http和https协议。该工程基于vs2015编译通过,相关配置和说明见readme.txt
boost.asio库是一个跨平台的网络及底层IO的C++编程库,它使用现代C++手法实现了统一的异步调用模型。 boost.asio库支持TCP、UDP、ICMP通信协议。 下面介绍同步TCP模式: 大家好!我是同步方式! 我的主要特点...
boost 下的asio库在线文档转过来的chm, 有了这个,c++实现高效的跨平台异步操作(通信)原来如此方便,
支持TCP/SSL 的网络库,基于boost asio,支持客户端自动重连、同时支持阻塞和异步模式,可直接应用在项目了,简单易维护
boost::asio tcp服务器的实现 封装socket, 监听socket, C++11智能指针, 要求: vs2012或以上版本
Boost.Asio C++ Network Programming 书的翻译 此版本的书无目录失效BUG 并且带全书源代码 方便学习使用
利用Boost::Asio库来实现Post/Get请求的发送。可以快速开发c++的http请求,访问以http为协议的服务器示例代码。
找c++工作常常会问你一些关于网络编程和多线程编程的相关知识,boost作为c++标准库的预备军,使用boost.asio对于c++开发人员是很好的选择,Boost.Asio C++ Network Programming详细介绍了使用boost.asio进行网络编程...
封装了boost中的asio的一个网络库,低层采用多线程 完成端口 有示例代码,方便使用,如果有需要可以发送asio封装的代码, 要源码的发邮件到我的邮箱中 yesme2000#163.com
asio库 用于TCP通信 不依赖boost版 提供了同步 异步 以及一些进程同步类和计时器等 功能强大 不需要编译 直接包含头文件就可以用 亲测通过
Boost.Asio C++ 网络编程 PDF 高清 非扫描 中文版
boost asio网络编程入门教程,可以作为学习参考
基于boost的asio封装的高性能TCP服务器。asio已经有很好的事件封装机制,只有底层事件,没有针对TCP建立会话机制;也没有多多包进行合包,已包为单位的事件提交机制。由于以上多种原因,决定对boost库进行更高的抽象...
基于官网的boost.asio的HTTPS/SSL例子,包括server和client端,完整的windows VS编译环境,包含了完整的boost库和openssl库,编译配置测试说明文档,测试用的server.crt和server.key证书文件。如需linux版本,和自己...
简单好用的网络编程接口,使用boost asio 开发的网络程序,支持tcp、ssl,包含server和client
Boost.Asio C++ Network Programming Cookbook.pdf Boost.Asio C++ Network Programming Cookbook.pdf
boost asio在Ubuntu下的例子,包含server,client及makefile。 使用方法: 1. 在Ubuntu下安装boost, sudo apt-get install libboost-all-dev 2. 解压代码,然后make all 3. ./server, ./client即可
boost asio 最新版