mirror of
https://github.com/pissnet/pissircd.git
synced 2025-08-08 19:25:25 +01:00
- Add support for oneshot I/O handlers.
This commit is contained in:
parent
ae7a3912e7
commit
110aeceaec
2 changed files with 32 additions and 6 deletions
|
@ -11,7 +11,9 @@ typedef struct fd_entry {
|
|||
int fd;
|
||||
char desc[FD_DESC_SZ];
|
||||
IOCallbackFunc read_callback;
|
||||
unsigned char read_oneshot;
|
||||
IOCallbackFunc write_callback;
|
||||
unsigned char write_oneshot;
|
||||
void *data;
|
||||
time_t deadline;
|
||||
unsigned char is_open;
|
||||
|
@ -25,8 +27,9 @@ extern int fd_socket(int family, int type, int protocol, const char *desc);
|
|||
extern int fd_accept(int sockfd);
|
||||
extern void fd_desc(int fd, const char *desc);
|
||||
|
||||
#define FD_SELECT_READ 0x1
|
||||
#define FD_SELECT_WRITE 0x2
|
||||
#define FD_SELECT_READ 0x1
|
||||
#define FD_SELECT_WRITE 0x2
|
||||
#define FD_SELECT_ONESHOT 0x4
|
||||
|
||||
extern void fd_setselect(int fd, int flags, IOCallbackFunc iocb, void *data);
|
||||
extern void fd_select(time_t delay); /* backend-specific */
|
||||
|
|
|
@ -72,10 +72,20 @@ void fd_setselect(int fd, int flags, IOCallbackFunc iocb, void *data)
|
|||
fde->data = data;
|
||||
|
||||
if (flags & FD_SELECT_READ)
|
||||
{
|
||||
fde->read_callback = iocb;
|
||||
|
||||
if (flags & FD_SELECT_ONESHOT)
|
||||
fde->read_oneshot = 1;
|
||||
}
|
||||
if (flags & FD_SELECT_WRITE)
|
||||
{
|
||||
fde->write_callback = iocb;
|
||||
|
||||
if (flags & FD_SELECT_ONESHOT)
|
||||
fde->write_oneshot = 1;
|
||||
}
|
||||
|
||||
fd_refresh(fd);
|
||||
}
|
||||
|
||||
|
@ -141,6 +151,7 @@ void fd_select(time_t delay)
|
|||
for (p = 0; p < (nfds + 1); p++)
|
||||
{
|
||||
FDEntry *fde;
|
||||
IOCallbackFunc iocb;
|
||||
int evflags = 0;
|
||||
|
||||
pfd = &pollfds[p];
|
||||
|
@ -160,14 +171,26 @@ void fd_select(time_t delay)
|
|||
|
||||
if (evflags & FD_SELECT_READ)
|
||||
{
|
||||
if (fde->read_callback != NULL)
|
||||
fde->read_callback(fd, evflags, fde->data);
|
||||
iocb = fde->read_callback;
|
||||
if (fde->read_oneshot)
|
||||
fde->read_callback = NULL;
|
||||
|
||||
if (iocb != NULL)
|
||||
iocb(fd, evflags, fde->data);
|
||||
|
||||
fde->read_oneshot = 0;
|
||||
}
|
||||
|
||||
if (evflags & FD_SELECT_WRITE)
|
||||
{
|
||||
if (fde->write_callback != NULL)
|
||||
fde->write_callback(fd, evflags, fde->data);
|
||||
iocb = fde->write_callback;
|
||||
if (fde->write_oneshot)
|
||||
fde->write_callback = NULL;
|
||||
|
||||
if (iocb != NULL)
|
||||
iocb(fd, evflags, fde->data);
|
||||
|
||||
fde->write_oneshot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue