fd_manager.h 948 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. {
  14. //ip_port_t ip_port;
  15. conn_info_t *p_conn_info;
  16. };
  17. struct fd_manager_t //conver fd to a uniq 64bit number,avoid fd value conflict caused by close and re-create
  18. //this class is not strictly necessary,it just makes epoll fd handling easier
  19. {
  20. fd_info_t & get_info(fd64_t fd64);
  21. int exist_info(fd64_t);
  22. int exist(fd64_t fd64);
  23. int to_fd(fd64_t);
  24. void fd64_close(fd64_t fd64);
  25. void reserve(int n);
  26. u64_t create(int fd);
  27. fd_manager_t();
  28. private:
  29. u64_t counter;
  30. unordered_map<int,fd64_t> fd_to_fd64_mp;
  31. unordered_map<fd64_t,int> fd64_to_fd_mp;
  32. unordered_map<fd64_t,fd_info_t> fd_info_mp;
  33. int fd_exist(int fd);
  34. //void remove_fd(int fd);
  35. //fd64_t fd_to_fd64(int fd);
  36. };
  37. extern fd_manager_t fd_manager;
  38. #endif /* FD_MANAGER_H_ */