2022-01-24 03:28:16 +00:00
|
|
|
#ifndef LAIKA_POLLLIST_H
|
|
|
|
#define LAIKA_POLLLIST_H
|
|
|
|
|
2022-09-02 01:00:37 +00:00
|
|
|
#include "core/hashmap.h"
|
|
|
|
#include "core/lmem.h"
|
2022-01-24 03:28:16 +00:00
|
|
|
#include "laika.h"
|
2022-09-02 01:00:37 +00:00
|
|
|
#include "net/lsocket.h"
|
2022-06-27 23:57:00 +00:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
2022-01-24 03:28:16 +00:00
|
|
|
|
|
|
|
/* number of pollFDs or epollFDs we expect to start with */
|
|
|
|
#define POLLSTARTCAP 8
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
struct sLaika_pollEvent
|
|
|
|
{
|
2022-01-24 03:28:16 +00:00
|
|
|
struct sLaika_socket *sock;
|
|
|
|
bool pollIn;
|
|
|
|
bool pollOut;
|
|
|
|
};
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
struct sLaika_pollList
|
|
|
|
{
|
2022-01-24 03:28:16 +00:00
|
|
|
struct hashmap *sockets;
|
2022-09-02 00:05:56 +00:00
|
|
|
/* holds sockets which have data needed to be sent */
|
|
|
|
laikaM_newVector(struct sLaika_socket *, outQueue);
|
2022-09-01 23:47:29 +00:00
|
|
|
laikaM_newVector(struct sLaika_pollEvent, revents);
|
2022-01-24 03:28:16 +00:00
|
|
|
#ifdef LAIKA_USE_EPOLL
|
|
|
|
/* epoll */
|
|
|
|
struct epoll_event ev, ep_events[MAX_EPOLL_EVENTS];
|
|
|
|
SOCKET epollfd;
|
|
|
|
#else
|
|
|
|
/* raw poll descriptor */
|
2022-09-01 23:47:29 +00:00
|
|
|
laikaM_newVector(PollFD, fds);
|
2022-01-24 03:28:16 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
void laikaP_initPList(struct sLaika_pollList *pList);
|
|
|
|
void laikaP_cleanPList(struct sLaika_pollList *pList); /* free's all members */
|
|
|
|
void laikaP_addSock(struct sLaika_pollList *pList, struct sLaika_socket *sock);
|
|
|
|
void laikaP_rmvSock(struct sLaika_pollList *pList, struct sLaika_socket *sock);
|
|
|
|
void laikaP_addPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock);
|
|
|
|
void laikaP_rmvPollOut(struct sLaika_pollList *pList, struct sLaika_socket *sock);
|
2022-03-24 15:26:06 +00:00
|
|
|
void laikaP_pushOutQueue(struct sLaika_pollList *pList, struct sLaika_socket *sock);
|
2022-02-14 05:55:30 +00:00
|
|
|
void laikaP_resetOutQueue(struct sLaika_pollList *pList);
|
2022-03-24 15:26:06 +00:00
|
|
|
void laikaP_flushOutQueue(struct sLaika_pollList *pList);
|
2022-01-24 03:28:16 +00:00
|
|
|
|
|
|
|
struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, int *nevents);
|
2022-03-24 15:26:06 +00:00
|
|
|
bool laikaP_handleEvent(struct sLaika_pollEvent *evnt);
|
2022-01-24 03:28:16 +00:00
|
|
|
|
|
|
|
#endif
|