tcpEpoll.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***** (C) Copyright, Shenzhen SUNWIN Intelligent Co.,Ltd. ******source file****
  2. * File name : tcpEpoll.h
  3. * Author : ShengYin Li
  4. * Brief :
  5. ********************************************************************************
  6. * modify
  7. * Version Date Author Described
  8. * V1.00 2021/04/2 ShengYin Li Created
  9. *******************************************************************************/
  10. #pragma once
  11. #include <arpa/inet.h>
  12. #include <fcntl.h>
  13. #include <stdio.h>
  14. #include <errno.h>
  15. #include <iostream>
  16. #include <stdlib.h>
  17. #include <malloc.h>
  18. #include <sys/types.h>
  19. #include <sys/un.h>
  20. #include <sys/epoll.h>
  21. #include <sys/uio.h>
  22. #include <string.h>
  23. #include <unistd.h>
  24. #include "sdc_common.h"
  25. #include <map>
  26. #include <set>
  27. #include <string.h>
  28. #include <iostream>
  29. #include <pthread.h>
  30. #include "sdc.h"
  31. #include <mutex>
  32. using namespace std;
  33. class tcpEpoll
  34. {
  35. private:
  36. std::mutex m_mutex;
  37. public:
  38. tcpEpoll();
  39. ~tcpEpoll();
  40. int _epoll_fd;
  41. int _type;
  42. int _domain;
  43. map <string,int>_fdMap;
  44. char _err_msg[256];
  45. const int MAXBUFFSIZE = 1024;
  46. const int MAXEVENTS = 500;
  47. const int FDSIZE = 1000;
  48. int getEpollFd();
  49. void addEvent(int fd, int state);
  50. void delEvent(int fd, int state);
  51. void modEvent(int fd, int state);
  52. bool doRead(int fd, char *buf, int &buf_len);
  53. bool doWrite(int fd, const char *buf, int buf_len);
  54. char* getErrmsg();
  55. void addIdNameFd(string idName,int fd);
  56. void delIdNameFd(int fd);
  57. void delIdNameFd(string idName);
  58. int find(string idName);
  59. void allDelIdNameFd();
  60. virtual void allClose() = 0;
  61. virtual bool doEpoll() = 0;
  62. virtual void handleEvents(epoll_event * events, int num, char * buf, int &buf_len) = 0;
  63. virtual int lanch() = 0;
  64. protected:
  65. };
  66. /******** (C) Copyright, Shenzhen SUNWIN Intelligent Co.,Ltd. ******** End *****/