Skip to content

Commit 55144cc

Browse files
jeffhostetlergitster
authored andcommitted
unix-socket: add backlog size option to unix_stream_listen()
Update `unix_stream_listen()` to take an options structure to override default behaviors. This commit includes the size of the `listen()` backlog. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f98ce5 commit 55144cc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

builtin/credential-cache--daemon.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ static int serve_cache_loop(int fd)
203203

204204
static void serve_cache(const char *socket_path, int debug)
205205
{
206+
struct unix_stream_listen_opts opts = UNIX_STREAM_LISTEN_OPTS_INIT;
206207
int fd;
207208

208-
fd = unix_stream_listen(socket_path);
209+
fd = unix_stream_listen(socket_path, &opts);
209210
if (fd < 0)
210211
die_errno("unable to bind to '%s'", socket_path);
211212

unix-socket.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "cache.h"
22
#include "unix-socket.h"
33

4+
#define DEFAULT_UNIX_STREAM_LISTEN_BACKLOG (5)
5+
46
static int chdir_len(const char *orig, int len)
57
{
68
char *path = xmemdupz(orig, len);
@@ -89,9 +91,11 @@ int unix_stream_connect(const char *path)
8991
return -1;
9092
}
9193

92-
int unix_stream_listen(const char *path)
94+
int unix_stream_listen(const char *path,
95+
const struct unix_stream_listen_opts *opts)
9396
{
9497
int fd = -1, saved_errno;
98+
int backlog;
9599
struct sockaddr_un sa;
96100
struct unix_sockaddr_context ctx;
97101

@@ -106,7 +110,10 @@ int unix_stream_listen(const char *path)
106110
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
107111
goto fail;
108112

109-
if (listen(fd, 5) < 0)
113+
backlog = opts->listen_backlog_size;
114+
if (backlog <= 0)
115+
backlog = DEFAULT_UNIX_STREAM_LISTEN_BACKLOG;
116+
if (listen(fd, backlog) < 0)
110117
goto fail;
111118

112119
unix_sockaddr_cleanup(&ctx);

unix-socket.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#ifndef UNIX_SOCKET_H
22
#define UNIX_SOCKET_H
33

4+
struct unix_stream_listen_opts {
5+
int listen_backlog_size;
6+
};
7+
8+
#define UNIX_STREAM_LISTEN_OPTS_INIT { 0 }
9+
410
int unix_stream_connect(const char *path);
5-
int unix_stream_listen(const char *path);
11+
int unix_stream_listen(const char *path,
12+
const struct unix_stream_listen_opts *opts);
613

714
#endif /* UNIX_SOCKET_H */

0 commit comments

Comments
 (0)