关于使用asio发送网络数据的优化。
来源:互联网 发布:餐厅预订软件 编辑:程序博客网 时间:2024/06/09 03:07
关于使用asio发送网络数据的优化。
inline bool Axis::send_data()
{
progress_timer t;
//while(true)
try
{
io_service ios;
ip::tcp::endpoint ep(ip::tcp::v4(),6688);
ip::tcp::acceptor acceptor(ios,ep);
// cout<<"1"<<endl;
ip::tcp::iostream tcp_stream;
//cout<<"2"<<endl;
acceptor.accept(*tcp_stream.rdbuf());
//cout<<"3"<<endl;
//mutex::scoped_lock lock(io_str_data);
tcp_stream<<str_data;
//str_data=" ";
cout<<"--------------------------------time elapsed :"<<t.elapsed()<<endl;
// cout<<endl;
// cout<<"thanks to use the net client!"<<endl;
return true;
}
catch(...)
{
return false;
}
}
关于上述代码的优化问题,
上面的这个函数,执行时要花0.5秒左右的时间,当我把它改成下面的代码时,花时间只有几幑秒了。当我看到接受端像法拉利马达一样快的显示下面函数发过来的数据时,我的心都陶醉了!
忙了一天,这个优化是最让我兴奋的了。
inline bool Axis::send_data()
{
progress_timer t;
//while(true)
try
{
static io_service ios;
static ip::tcp::endpoint ep(ip::tcp::v4(),6688);
static ip::tcp::acceptor acceptor(ios,ep);
// cout<<"1"<<endl;
ip::tcp::iostream tcp_stream;
//cout<<"2"<<endl;
acceptor.accept(*tcp_stream.rdbuf());
//cout<<"3"<<endl;
//mutex::scoped_lock lock(io_str_data);
tcp_stream<<str_data;
//str_data=" ";
cout<<"--------------------------------time elapsed :"<<t.elapsed()<<endl;
// cout<<endl;
// cout<<"thanks to use the net client!"<<endl;
return true;
}
catch(...)
{
return false;
}
}
inline bool Axis::send_data()
{
progress_timer t;
//while(true)
try
{
io_service ios;
ip::tcp::endpoint ep(ip::tcp::v4(),6688);
ip::tcp::acceptor acceptor(ios,ep);
// cout<<"1"<<endl;
ip::tcp::iostream tcp_stream;
//cout<<"2"<<endl;
acceptor.accept(*tcp_stream.rdbuf());
//cout<<"3"<<endl;
//mutex::scoped_lock lock(io_str_data);
tcp_stream<<str_data;
//str_data=" ";
cout<<"--------------------------------time elapsed :"<<t.elapsed()<<endl;
// cout<<endl;
// cout<<"thanks to use the net client!"<<endl;
return true;
}
catch(...)
{
return false;
}
}
关于上述代码的优化问题,
上面的这个函数,执行时要花0.5秒左右的时间,当我把它改成下面的代码时,花时间只有几幑秒了。当我看到接受端像法拉利马达一样快的显示下面函数发过来的数据时,我的心都陶醉了!
忙了一天,这个优化是最让我兴奋的了。
inline bool Axis::send_data()
{
progress_timer t;
//while(true)
try
{
static io_service ios;
static ip::tcp::endpoint ep(ip::tcp::v4(),6688);
static ip::tcp::acceptor acceptor(ios,ep);
// cout<<"1"<<endl;
ip::tcp::iostream tcp_stream;
//cout<<"2"<<endl;
acceptor.accept(*tcp_stream.rdbuf());
//cout<<"3"<<endl;
//mutex::scoped_lock lock(io_str_data);
tcp_stream<<str_data;
//str_data=" ";
cout<<"--------------------------------time elapsed :"<<t.elapsed()<<endl;
// cout<<endl;
// cout<<"thanks to use the net client!"<<endl;
return true;
}
catch(...)
{
return false;
}
}
- 关于使用asio发送网络数据的优化。
- 关于网络通信模型的剖析:libevent libev libuv asio
- boost 库asio网络接口收取数据缺失的分析
- 关于asio的interrupted
- ASIO deadline_timer 的使用
- 网络数据传递之数据的发送
- 小数据包网络发送的优化策略
- boost的网络库asio
- 网络编程_UDP协议发送和接收数据代码优化
- 谈谈boost.asio的异步发送
- 谈谈boost.asio的异步发送
- 使用boost::asio开发网络服务器
- 网络发送数据块的方法
- IOS网络编程发送数据的问题
- IOS网络编程发送数据的问题
- Android关于易源数据网络接口的使用
- 使用了ASIO的项目
- Boost.Asio的使用技巧
- asp.net 导出Excel时 身份证号码的正确导出
- 用 vs2010等系列软件编程如何在当前的文件中include其它文件夹中的头文件
- Enhancing Security with Device Management Policies 加强安全与设备管理策略 Developing for Enterprise
- Flume配置文件
- 【达达】UK联合软件加解密成功实现
- 关于使用asio发送网络数据的优化。
- Eclipse颜色设置
- iphone使用keychain来存取用户名和密码
- 嵌入式linux保存参数数据
- postfix——pipe
- 黑马程序员_IO流使用规律
- 代码的坏味道之二十二 :Comments(过多的注释)
- C#调用WebService实现天气预报
- AndroidJSON解析