It's a bit odd to have the listen(2) call for TCP listening sockets, down
deep in sock_l4_() conditional upon the epoll type passed in. Move it to
pif_listen(), which is at least about listening, although it does still
need to be conditional on TCP.
Signed-off-by: David Gibson
---
pif.c | 14 ++++++++++----
util.c | 7 -------
2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/pif.c b/pif.c
index ede2f903..f99f33e5 100644
--- a/pif.c
+++ b/pif.c
@@ -123,11 +123,17 @@ int pif_listen(const struct ctx *c, uint8_t proto, uint8_t pif,
ref.listen.pif = pif;
ref.listen.rule = rule;
- ret = epoll_add(c->epollfd, EPOLLIN, ref);
- if (ret < 0) {
- close(ref.fd);
- return ret;
+ if (proto == IPPROTO_TCP && listen(ref.fd, 128) < 0) {
+ ret = -errno;
+ goto fail;
}
+ ret = epoll_add(c->epollfd, EPOLLIN, ref);
+ if (ret < 0)
+ goto fail;
+
return ref.fd;
+fail:
+ close(ref.fd);
+ return ret;
}
diff --git a/util.c b/util.c
index b64c29ed..e22696e3 100644
--- a/util.c
+++ b/util.c
@@ -169,13 +169,6 @@ static int sock_l4_(const struct ctx *c, enum epoll_type type,
}
}
- if (type == EPOLL_TYPE_TCP_LISTEN && listen(fd, 128) < 0) {
- ret = -errno;
- warn("TCP socket listen: %s", strerror_(-ret));
- close(fd);
- return ret;
- }
-
return fd;
}
--
2.54.0