/IOSelect.h

http://github.com/riton/SSL-Proxy · 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. #include <sys/select.h>
  4. #include <sys/time.h>
  5. #include <algorithm>
  6. #include <sstream>
  7. #include <list>
  8. using namespace std;
  9. #define OSELECT_MAX_FDS 10
  10. class IOSelect {
  11. private:
  12. fd_set set;
  13. list<int> fds;
  14. int max_fd;
  15. public:
  16. IOSelect(const int fds[]);
  17. IOSelect();
  18. list<int> can_read(const struct timeval *timeout);
  19. list<int> can_read(const int seconds);
  20. list<int> can_write(const struct timeval *timeout);
  21. list<int> can_write(const int seconds);
  22. void add(const int &fd);
  23. void remove(const int &fd);
  24. size_t count(void);
  25. };
  26. class IOSelectTimeout {
  27. private:
  28. string msg;
  29. struct timeval *timeout;
  30. public:
  31. IOSelectTimeout(const struct timeval *timeout) {
  32. stringstream ss;
  33. this->timeout = (struct timeval *) timeout;
  34. ss << timeout->tv_sec;
  35. ss << "." << timeout->tv_usec;
  36. ss << " seconds without I/O" << endl;
  37. msg = ss.str();
  38. }
  39. const char *what() const throw() {
  40. return msg.c_str();
  41. }
  42. };
  43. #endif