/IOSelect.h
C Header | 59 lines | 43 code | 16 blank | 0 comment | 0 complexity | a9f14f604a608ab4ffaa547cc692fffa MD5 | raw file
1#ifndef __OSELECT_H 2#define __OSELECT_H 3 4#include <sys/select.h> 5#include <sys/time.h> 6#include <algorithm> 7#include <sstream> 8#include <list> 9using namespace std; 10 11#define OSELECT_MAX_FDS 10 12 13class IOSelect { 14 15 private: 16 fd_set set; 17 list<int> fds; 18 int max_fd; 19 20 public: 21 IOSelect(const int fds[]); 22 IOSelect(); 23 24 list<int> can_read(const struct timeval *timeout); 25 list<int> can_read(const int seconds); 26 list<int> can_write(const struct timeval *timeout); 27 list<int> can_write(const int seconds); 28 void add(const int &fd); 29 void remove(const int &fd); 30 size_t count(void); 31}; 32 33class IOSelectTimeout { 34 35 private: 36 string msg; 37 struct timeval *timeout; 38 39 public: 40 41 IOSelectTimeout(const struct timeval *timeout) { 42 stringstream ss; 43 44 this->timeout = (struct timeval *) timeout; 45 46 ss << timeout->tv_sec; 47 ss << "." << timeout->tv_usec; 48 ss << " seconds without I/O" << endl; 49 msg = ss.str(); 50 } 51 52 const char *what() const throw() { 53 return msg.c_str(); 54 } 55}; 56 57 58 59#endif