fd_manager.h 904 B

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