mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
IO Loop: process socket reads only after timers and events are done
This commit is contained in:
parent
f45c519039
commit
2e882d4a7d
@ -392,6 +392,7 @@ socket_changed(sock *s)
|
|||||||
struct birdloop *loop = s->loop;
|
struct birdloop *loop = s->loop;
|
||||||
ASSERT_DIE(birdloop_inside(loop));
|
ASSERT_DIE(birdloop_inside(loop));
|
||||||
|
|
||||||
|
LOOP_TRACE(loop, DL_SOCKETS, "socket %p changed", s);
|
||||||
loop->sock_changed = 1;
|
loop->sock_changed = 1;
|
||||||
birdloop_ping(loop);
|
birdloop_ping(loop);
|
||||||
}
|
}
|
||||||
@ -506,13 +507,11 @@ int sk_read(sock *s, int revents);
|
|||||||
int sk_write(sock *s);
|
int sk_write(sock *s);
|
||||||
void sk_err(sock *s, int revents);
|
void sk_err(sock *s, int revents);
|
||||||
|
|
||||||
static int
|
static void
|
||||||
sockets_fire(struct birdloop *loop)
|
sockets_fire(struct birdloop *loop, _Bool read, _Bool write)
|
||||||
{
|
{
|
||||||
if (EMPTY_LIST(loop->sock_list))
|
if (EMPTY_LIST(loop->sock_list))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
int repeat = 0;
|
|
||||||
|
|
||||||
times_update();
|
times_update();
|
||||||
|
|
||||||
@ -528,10 +527,10 @@ sockets_fire(struct birdloop *loop)
|
|||||||
{
|
{
|
||||||
int e = 1;
|
int e = 1;
|
||||||
|
|
||||||
if (rev & POLLOUT)
|
if (write && (rev & POLLOUT))
|
||||||
{
|
{
|
||||||
/* Write everything. */
|
/* Write until task limit is up */
|
||||||
while ((s == loop->sock_active) && (e = sk_write(s)))
|
while ((s == loop->sock_active) && (e = sk_write(s)) && task_still_in_limit())
|
||||||
;
|
;
|
||||||
|
|
||||||
if (s != loop->sock_active)
|
if (s != loop->sock_active)
|
||||||
@ -541,16 +540,10 @@ sockets_fire(struct birdloop *loop)
|
|||||||
loop->thread->sock_changed = 1;
|
loop->thread->sock_changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rev & POLLIN)
|
/* Read until task limit is up */
|
||||||
/* Read just one packet and request repeat. */
|
if (read && (rev & POLLIN))
|
||||||
while ((s == loop->sock_active) && s->rx_hook)
|
while ((s == loop->sock_active) && s->rx_hook && sk_read(s, rev) && task_still_in_limit())
|
||||||
if (!task_before_halftime())
|
;
|
||||||
{
|
|
||||||
repeat++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (!sk_read(s, rev))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (s != loop->sock_active)
|
if (s != loop->sock_active)
|
||||||
continue;
|
continue;
|
||||||
@ -564,8 +557,6 @@ sockets_fire(struct birdloop *loop)
|
|||||||
|
|
||||||
loop->sock_active = sk_next(s);
|
loop->sock_active = sk_next(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
return repeat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1516,7 +1507,6 @@ birdloop_run(void *_loop)
|
|||||||
|
|
||||||
uint repeat, loop_runs = 0;
|
uint repeat, loop_runs = 0;
|
||||||
do {
|
do {
|
||||||
repeat = 0;
|
|
||||||
LOOP_TRACE(loop, DL_SCHEDULING, "Regular run (%d)", loop_runs);
|
LOOP_TRACE(loop, DL_SCHEDULING, "Regular run (%d)", loop_runs);
|
||||||
loop_runs++;
|
loop_runs++;
|
||||||
|
|
||||||
@ -1524,14 +1514,17 @@ birdloop_run(void *_loop)
|
|||||||
/* Birdloop left inside the helper function */
|
/* Birdloop left inside the helper function */
|
||||||
return birdloop_stop_internal(loop);
|
return birdloop_stop_internal(loop);
|
||||||
|
|
||||||
/* Process sockets */
|
/* Process socket TX */
|
||||||
repeat += sockets_fire(loop);
|
sockets_fire(loop, 0, 1);
|
||||||
|
|
||||||
/* Run timers */
|
/* Run timers */
|
||||||
timers_fire(&loop->time, 0);
|
timers_fire(&loop->time, 0);
|
||||||
|
|
||||||
/* Run events */
|
/* Run events */
|
||||||
repeat += ev_run_list(&loop->event_list);
|
repeat = ev_run_list(&loop->event_list);
|
||||||
|
|
||||||
|
/* Process socket RX */
|
||||||
|
sockets_fire(loop, 1, 0);
|
||||||
|
|
||||||
/* Check end time */
|
/* Check end time */
|
||||||
} while (repeat && task_still_in_limit());
|
} while (repeat && task_still_in_limit());
|
||||||
|
Loading…
Reference in New Issue
Block a user