一个linux典型的select模型更新方法
2008-03-22 11:16
549 查看
bool update(int _fd, int _timeout, char *buffer){
//cout << "update +++++++" << endl;
fd_set fdClient;
FD_ZERO( &fdClient );
FD_SET( _fd, &fdClient );
struct timeval tv;
tv.tv_sec = _timeout;
tv.tv_usec = 0;
if( select( _fd + 1, &fdClient, NULL, NULL, &tv ) == -1 ) {
return true;
}
if( FD_ISSET( _fd, &fdClient ) ) {
memset( buffer, 0, sizeof( char ) * GPBUF_SIZE );
int c = recv( _fd, buffer, GPBUF_SIZE, 0 );
if( c == -1 && errno != EWOULDBLOCK ) {
if( errno != ECONNRESET )
//cout << "peer reset the connection" << endl;
return true;
}
if( c == 0 )
return true;
}
return false;
}
//cout << "update +++++++" << endl;
fd_set fdClient;
FD_ZERO( &fdClient );
FD_SET( _fd, &fdClient );
struct timeval tv;
tv.tv_sec = _timeout;
tv.tv_usec = 0;
if( select( _fd + 1, &fdClient, NULL, NULL, &tv ) == -1 ) {
return true;
}
if( FD_ISSET( _fd, &fdClient ) ) {
memset( buffer, 0, sizeof( char ) * GPBUF_SIZE );
int c = recv( _fd, buffer, GPBUF_SIZE, 0 );
if( c == -1 && errno != EWOULDBLOCK ) {
if( errno != ECONNRESET )
//cout << "peer reset the connection" << endl;
return true;
}
if( c == 0 )
return true;
}
return false;
}
相关文章推荐
- 一个linux典型的select模型更新方法
- 一个linux典型的select模型更新方法
- 一个linux典型的select模型更新方法
- 采用DOM模型时创建一个Select节点后,要删除option项的解决方法
- Linux下直接杀掉一个进程的方法
- nopCommerce开发者指南(二):更新一个现有实体,添加新属性的方法。
- 关于linux多线程同时对一个fd做select
- Linux的一些很有用的命令或者方法(持续更新)
- linux中Cron执行shell的一个问题(子shell的调用方法)
- java线程基础巩固---分析Thread的join方法详细介绍,结合一个典型案例
- SQL语句 使用一个表更新另一个表的方法
- Linux下select, poll和epoll IO模型的详解
- 下拉框select,Jquery的data()方法,JavaScript join() 方法用于把数组中的所有元素放入一个字符串
- Linux--14:ubuntu12.04 vi不能正常使用、右上角出现红杠提醒更新出问题、网速比相同条件下windows下慢 解决方法
- Linux下select的用法--实现一个简单的回射服务器程序
- 运维笔记7(文件的归档与压缩,linux网络配置 更新:ssh服务配置文件,网络配置的四个方法
- 【Linux网络编程】基于TCP协议 I/O多路转接(select) 的高性能回显服务器客户端模型
- 写student类中的select,delete,update,insert方法并在objectDataSource中应用(分别写两个,一个返回datatable,一个使用list)
- mysql用一个表更新另一个表的方法
- 一个 Linux 上分析死锁的简单方法