summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-transport/socket/src
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kparthas@redhat.com>2018-10-11 15:16:41 +0530
committerRaghavendra G <rgowdapp@redhat.com>2018-10-12 02:11:38 +0000
commit62faf7d37bd8b6be6657b1e3b61f92eac5b84653 (patch)
tree0143f6ae133ff56fa4823815d3084c632ce37440 /rpc/rpc-transport/socket/src
parent807ec72d740a4548c250cc660c89fc59d2f191d6 (diff)
socket: use accept4/paccept for nonblocking socket
This reduces the no. of syscalls on Linux systems from 2, accept(2) and fcntl(2) for setting O_NONBLOCK, to a single accept4(2). On NetBSD, we have paccept(2) that does the same, if we leave signal masking aside. Added sys_accept which accepts an extra flags argument than accept(2). This would opportunistically use accept4/paccept as available. It would fallback to accept(2) and fcntl(2) otherwise. While at this, the patch sets FD_CLOEXEC flag on the accepted socket fd. BUG: 1236272 Change-Id: I41e43fd3e36d6dabb07e578a1cea7f45b7b4e37f fixes: bz#1236272 Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Diffstat (limited to 'rpc/rpc-transport/socket/src')
-rw-r--r--rpc/rpc-transport/socket/src/socket.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 753722cdb61..9d926e6e078 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -2992,7 +2992,12 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in,
priv->idx = idx;
if (poll_in) {
- new_sock = accept(priv->sock, SA(&new_sockaddr), &addrlen);
+ int aflags = 0;
+
+ if (!priv->bio)
+ aflags = O_NONBLOCK;
+
+ new_sock = sys_accept(priv->sock, SA(&new_sockaddr), &addrlen, aflags);
if (ctx)
event_handled(ctx->event_pool, fd, idx, gen);
@@ -3101,21 +3106,6 @@ socket_server_event_handler(int fd, int idx, int gen, void *data, int poll_in,
new_priv->connected = 1;
new_priv->is_server = _gf_true;
- /* set O_NONBLOCK for plain text as well as ssl connections */
- if (!priv->bio) {
- gf_log(this->name, GF_LOG_TRACE, "### use non-blocking IO");
- ret = __socket_nonblock(new_sock);
-
- if (ret == -1) {
- gf_log(this->name, GF_LOG_WARNING, "NBIO on %d failed (%s)",
- new_sock, strerror(errno));
-
- sys_close(new_sock);
- GF_FREE(new_trans->name);
- GF_FREE(new_trans);
- goto out;
- }
- }
/*
* This is the first ref on the newly accepted
* transport.