fd_manager.h 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * fd_manager.h
  3. *
  4. * Created on: Sep 25, 2017
  5. * Author: root
  6. */
  7. #ifndef FD_MANAGER_H_
  8. #define FD_MANAGER_H_
  9. #include "common.h"
  10. //#include "packet.h"
  11. #include "connection.h"
  12. struct fd_info_t {
  13. // ip_port_t ip_port;
  14. conn_info_t *p_conn_info;
  15. };
  16. struct fd_manager_t // conver fd to a uniq 64bit number,avoid fd value conflict caused by close and re-create
  17. // this class is not strictly necessary,it just makes epoll fd handling easier
  18. {
  19. fd_info_t &get_info(fd64_t fd64);
  20. int exist_info(fd64_t);
  21. int exist(fd64_t fd64);
  22. int to_fd(fd64_t);
  23. void fd64_close(fd64_t fd64);
  24. void reserve(int n);
  25. u64_t create(int fd);
  26. fd_manager_t();
  27. private:
  28. u64_t counter;
  29. unordered_map<int, fd64_t> fd_to_fd64_mp;
  30. unordered_map<fd64_t, int> fd64_to_fd_mp;
  31. unordered_map<fd64_t, fd_info_t> fd_info_mp;
  32. int fd_exist(int fd);
  33. // void remove_fd(int fd);
  34. // fd64_t fd_to_fd64(int fd);
  35. };
  36. extern fd_manager_t fd_manager;
  37. #endif /* FD_MANAGER_H_ */