Skip to content

Commit

Permalink
feat select: added timeout support
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Mar 1, 2024
1 parent 5e53cb2 commit 7839af8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/event/select/xdbd_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sys/select.h>
#include <xdbd.h>
#include <xdbd_event.h>
#include <xdbd_timer.h>
#include <connection.h>
#include <sys/errno.h>

Expand Down Expand Up @@ -176,6 +177,7 @@ void xdbd_select_repair_fd_sets(xdbd_t *xdbd) {
static int xdbd_select_process_events(xdbd_t *xdbd, xdbd_msec_t timer, unsigned flags) {
xdbd_connection_t *c;
int i = 0, ready, nready, found;
struct timeval timeout;
bfdev_list_head_t *list;
/* struct timeval tv, *tp; */
xdbd_event_t *ev;
Expand All @@ -194,7 +196,9 @@ static int xdbd_select_process_events(xdbd_t *xdbd, xdbd_msec_t timer, unsigned
work_read_fd_set = master_read_fd_set;
work_write_fd_set = master_write_fd_set;

ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, NULL);
timeout.tv_sec = (long) (timer / 1000);
timeout.tv_usec = (long) ((timer % 1000) * 1000);
ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, &timeout);

err = (ready == -1) ? xdbd_errno : 0;

Expand All @@ -210,6 +214,7 @@ static int xdbd_select_process_events(xdbd_t *xdbd, xdbd_msec_t timer, unsigned

bfdev_log_err("select() failed\n");


if (err == XDBD_EBADF) {
xdbd_select_repair_fd_sets(xdbd);
}
Expand All @@ -219,6 +224,7 @@ static int xdbd_select_process_events(xdbd_t *xdbd, xdbd_msec_t timer, unsigned
}

if (ready == 0) {

if (timer != XDBD_TIMER_INFINITE) {
return XDBD_OK;
}
Expand Down

0 comments on commit 7839af8

Please sign in to comment.