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

[PATCH 2/3] daemon.c: simplify add_child() and kill_some_child() logic

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 24, 2008, 20:27 UTC
Message-ID
<7vod3ikvk5.fsf_-_@gitster.siamese.dyndns.org>
In-Reply-To
<7vwsi6kvow.fsf@gitster.siamese.dyndns.org>

kill_some_child() function walks the list of connections and kills the first connection it finds from the same address. There is not much point to find the existing connection from the same address in add_child() to insert the new one in front of it. At the front of the whole queue is just as good.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 daemon.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/daemon.c b/daemon.c
index 35bd34a..8d2755a 100644
--- a/daemon.c
+++ b/daemon.c
@@ -596,18 +596,18 @@ static struct child {
 
 static void add_child(pid_t pid, struct sockaddr *addr, int addrlen)
 {
-	struct child *newborn, **cradle;
-	newborn = xcalloc(1, sizeof(*newborn));
+	struct child *newborn;
 
+	/*
+	 * This must be xcalloc() -- we'll compare the whole sockaddr_storage
+	 * later in kill_some_child().
+	 */
+	newborn = xcalloc(1, sizeof(*newborn));
 	live_children++;
 	newborn->pid = pid;
 	memcpy(&newborn->address, addr, addrlen);
-	for (cradle = &firstborn; *cradle; cradle = &(*cradle)->next)
-		if (!memcmp(&(*cradle)->address, &newborn->address,
-			    sizeof(newborn->address)))
-			break;
-	newborn->next = *cradle;
-	*cradle = newborn;
+	newborn->next = firstborn;
+	firstborn = newborn;
 }
 
 static void remove_child(pid_t pid)
@@ -627,7 +627,8 @@ static void remove_child(pid_t pid)
  * This gets called if the number of connections grows
  * past "max_connections".
  *
- * We kill the newest connection from a duplicate IP.
+ * We kill the newest connection from the same address (add_child() queues
+ * new ones at the front).
  */
 static void kill_some_child(void)
 {
-- 
1.6.0.129.ge10d2
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 11 in “What's cooking in git.git (Aug 2008, #07; Sat, 23)”
  1. Junio C HamanoAug 24, 2008
  2. Maintaining "needswork" section of "What's (not) cooking"Junio C Hamano, Aug 24, 2008
  3. Johannes SchindelinAug 24, 2008
  4. Junio C HamanoAug 24, 2008
  5. Junio C HamanoAug 24, 2008
  6. 1/3 daemon.c: minor style fixupJunio C Hamano, Aug 24, 2008
  7. 2/3 daemon.c: simplify add_child() and kill_some_child() logicJunio C Hamano, Aug 24, 2008
  8. 3/3 daemon.c: make sure kill_some_child() really kills somebodyJunio C Hamano, Aug 24, 2008
  9. Stephen R. van den BergAug 25, 2008
  10. Junio C HamanoAug 25, 2008
  11. Stephen R. van den BergAug 25, 2008

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.