123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #ifndef _PX_EPOLL_H_
- #define _PX_EPOLL_H_
- #include <sys/epoll.h>
- #include "pxTools.h"
- #define TIME_UNIT 1000 //0.001S
- typedef struct pxEpoll
- {
- int clientfd;
- int serverfd;
- void (*recvCallBack)(struct pxEpoll *epoll);
- void (*failCallBack)(struct pxEpoll *epoll);
- void (*connSuccess)(struct pxEpoll *epoll);
- void *param;
- }PXEPOLL_S;
- typedef void EPOLLCB(PXEPOLL_S*);
- typedef struct pxTimer
- {
- int num;
- int multiTime;
- int interval;//单位为毫米
- PXEPOLL_S *epoll;
- void (*timerCallBack)(struct pxTimer *timer);
- void *param;
- LISTNODE_S node;
- }PXTIMER_S;
- typedef void TIMERCB(PXTIMER_S *);
- int epollInit(char *threadName);
- //若add失败,需手动关闭fd,
- //若没有指定failCB,param必须仅该epoll使用且是堆内存数据。触发失败会自动释放
- //若指定failCB则需要在failCB里删除epoll,关闭fd,释放param
- PXEPOLL_S* epollAdd(int epollfd,int fd,EPOLLCB *recvCB,EPOLLCB *failCB,void *param);
- //del成功后需手动释放param和关闭fd
- int epollDel(PXEPOLL_S* epoll);
- PXTIMER_S* timerAdd(int epollfd,int num,int interval,int multiTime,TIMERCB *timeoutCB,void *param);
- void timerDel(PXTIMER_S *entry);
- // void timerDelByNum(int timerID);
- int epollMain(int epollfd,char *threadName);
- #endif
|