Factor out the epoll registration of TCP timers from tcp_timer_ctl()
into a separate tcp_timer_epoll_add() helper.
Signed-off-by: Laurent Vivier
---
tcp.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/tcp.c b/tcp.c
index aef689faf031..88caf5d8968b 100644
--- a/tcp.c
+++ b/tcp.c
@@ -545,6 +545,22 @@ static int tcp_epoll_ctl(struct tcp_tap_conn *conn)
return 0;
}
+static int tcp_timer_epoll_add(struct tcp_tap_conn *conn, int fd,
+ const struct timespec *now)
+{
+ union epoll_ref ref;
+
+ ref.type = EPOLL_TYPE_TCP_TIMER;
+ ref.flow = FLOW_IDX(conn);
+ ref.fd = fd;
+ if (epoll_add(flow_epollfd(&conn->f), EPOLLIN | EPOLLET, ref) < 0) {
+ flow_perror_ratelimit(conn, now, "failed to add timer");
+ return -1;
+ }
+
+ return 0;
+}
+
/**
* tcp_timer_ctl() - Set timerfd based on flags/events, create timerfd if needed
* @c: Execution context
@@ -562,7 +578,6 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn,
return;
if (conn->timer == -1) {
- union epoll_ref ref;
int fd;
fd = timerfd_create(CLOCK_MONOTONIC, 0);
@@ -578,12 +593,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn,
return;
}
- ref.type = EPOLL_TYPE_TCP_TIMER;
- ref.flow = FLOW_IDX(conn);
- ref.fd = fd;
- if (epoll_add(flow_epollfd(&conn->f), EPOLLIN | EPOLLET,
- ref) < 0) {
- flow_perror_ratelimit(conn, now, "failed to add timer");
+ if (tcp_timer_epoll_add(conn, fd, now) < 0) {
close(fd);
return;
}
--
2.54.0