git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/8] unix-socket: simplify initialization of unix_stream_listen_opts

From
JGJeff Hostetler via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 4, 2021, 20:17 UTC
Message-ID
<6ef867bf37d366071d5f0f101e7430d859f529b5.1614889047.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.893.git.1614889047.gitgitgadget@gmail.com>
From: Jeff Hostetler <jeffhost@microsoft.com>

Change the public initialization of `struct unix_stream_listen_opts` to be all zeroes. Hide the default values for the timeout and backlog values inside `unix-socket.c`.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 unix-socket.c | 11 +++++++++--
 unix-socket.h |  7 ++-----
 2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/unix-socket.c b/unix-socket.c
index 647bbde37f97..c9ea1de43bd2 100644
--- a/unix-socket.c
+++ b/unix-socket.c
@@ -2,6 +2,9 @@
 #include "lockfile.h"
 #include "unix-socket.h"
 
+#define DEFAULT_UNIX_STREAM_LISTEN_TIMEOUT (100)
+#define DEFAULT_UNIX_STREAM_LISTEN_BACKLOG (5)
+
 static int chdir_len(const char *orig, int len)
 {
 	char *path = xmemdupz(orig, len);
@@ -165,14 +168,18 @@ struct unix_stream_server_socket *unix_stream_server__listen_with_lock(
 	const struct unix_stream_listen_opts *opts)
 {
 	struct lock_file lock = LOCK_INIT;
+	long timeout;
 	int fd_socket;
 	struct unix_stream_server_socket *server_socket;
 
+	timeout = opts->timeout_ms;
+	if (opts->timeout_ms <= 0)
+		timeout = DEFAULT_UNIX_STREAM_LISTEN_TIMEOUT;
+
 	/*
 	 * Create a lock at "<path>.lock" if we can.
 	 */
-	if (hold_lock_file_for_update_timeout(&lock, path, 0,
-					      opts->timeout_ms) < 0) {
+	if (hold_lock_file_for_update_timeout(&lock, path, 0, timeout) < 0) {
 		error_errno(_("could not lock listener socket '%s'"), path);
 		return NULL;
 	}
diff --git a/unix-socket.h b/unix-socket.h
index 8faf5b692f90..bec925ee0213 100644
--- a/unix-socket.h
+++ b/unix-socket.h
@@ -7,13 +7,10 @@ struct unix_stream_listen_opts {
 	unsigned int disallow_chdir:1;
 };
 
-#define DEFAULT_UNIX_STREAM_LISTEN_TIMEOUT (100)
-#define DEFAULT_UNIX_STREAM_LISTEN_BACKLOG (5)
-
 #define UNIX_STREAM_LISTEN_OPTS_INIT \
 { \
-	.timeout_ms = DEFAULT_UNIX_STREAM_LISTEN_TIMEOUT, \
-	.listen_backlog_size = DEFAULT_UNIX_STREAM_LISTEN_BACKLOG, \
+	.timeout_ms = 0, \
+	.listen_backlog_size = 0, \
 	.disallow_chdir = 0, \
 }
 
-- 
gitgitgadget
Previous: Jeff Hostetler via GitGitGadgetNext: Junio C Hamano
Message 5 of 15 in “Simple IPC Cleanups”
  1. 0/8 Simple IPC CleanupsJeff Hostetler via GitGitGadget, Mar 4, 2021
  2. 6/8 test-simple-ipc: refactor command line option processing in helperJeff Hostetler via GitGitGadget, Mar 4, 2021
  3. 7/8 test-simple-ipc: add --token=<token> string optionJeff Hostetler via GitGitGadget, Mar 4, 2021
  4. 4/8 simple-ipc: move error handling up a levelJeff Hostetler via GitGitGadget, Mar 4, 2021
  5. 2/8 unix-socket: simplify initialization of unix_stream_listen_optsJeff Hostetler via GitGitGadget, Mar 4, 2021
  6. Junio C HamanoMar 4, 2021
  7. 3/8 unix-stream-server: create unix-stream-server.cJeff Hostetler via GitGitGadget, Mar 4, 2021
  8. 5/8 unix-stream-server: add st_dev and st_mode to socket stolen checksJeff Hostetler via GitGitGadget, Mar 4, 2021
  9. René ScharfeMar 6, 2021
  10. Jeff HostetlerMar 8, 2021
  11. 1/8 pkt-line: remove buffer arg from write_packetized_from_fd_no_flush()Jeff Hostetler via GitGitGadget, Mar 4, 2021
  12. Junio C HamanoMar 4, 2021
  13. 8/8 simple-ipc: update design documentation with more detailsJeff Hostetler via GitGitGadget, Mar 4, 2021
  14. Junio C HamanoMar 5, 2021
  15. Jeff HostetlerMar 5, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.