?? client.cc
字號:
#include "client.h"client::client(int fd, sockaddr_in sinaddr, int timeout){ _fd = fd; _timeout = timeout; fcntl( _fd, F_SETFL, fcntl( _fd, F_GETFL ) | O_NONBLOCK ); buffer = NULL; buffer = new char[BUFFERSIZE];}client::~client(){ close(_fd); delete buffer; buffer = NULL;}bool client::update(){ 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 ) * BUFFERSIZE ); int c = recv( _fd, buffer, BUFFERSIZE, 0 ); if( c == -1 && errno != EWOULDBLOCK ) { if( errno != ECONNRESET ) cout << "peer reset the connection" << endl; return true; } else if( c == 0 ) return true; else if( c > 0 ) { _value = string( buffer, c ); cout << _value << endl; } else { return true; } } return false;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -