From: Alexander Sulfrian <alexander@sulfrian.net>
To: gitster@pobox.com, git@vger.kernel.org
Cc: Alexander Sulfrian <alexander@sulfrian.net>
Subject: [PATCHv2 1/2] daemon: add helper function named_sock_setup
Date: Sun, 29 Aug 2010 17:07:41 +0200 [thread overview]
Message-ID: <1283094462-5184-2-git-send-email-alexander@sulfrian.net> (raw)
In-Reply-To: <7v4oel14tl.fsf@alter.siamese.dyndns.org>
Add named_sock_setup as helper function for socksetup to make it
easier to create more than one listen sockets. named_sock_setup could
be called more than one time and add the new sockets to the supplied
socklist_p.
Signed-off-by: Alexander Sulfrian <alexander@sulfrian.net>
---
daemon.c | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/daemon.c b/daemon.c
index e22a2b7..deda4cf 100644
--- a/daemon.c
+++ b/daemon.c
@@ -736,9 +736,9 @@ static int set_reuse_addr(int sockfd)
#ifndef NO_IPV6
-static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
+static int setup_named_sock(char *listen_addr, int listen_port, int **socklist_p, int socknum)
{
- int socknum = 0, *socklist = NULL;
+ int *socklist = *socklist_p;
int maxfd = -1;
char pbuf[NI_MAXSERV];
struct addrinfo hints, *ai0, *ai;
@@ -810,8 +810,9 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
#else /* NO_IPV6 */
-static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
+static int setup_named_sock(char *listen_addr, int listen_port, int **socklist_p, int socknum)
{
+ int *socklist = *socklist_p;
struct sockaddr_in sin;
int sockfd;
long flags;
@@ -823,41 +824,53 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
if (listen_addr) {
/* Well, host better be an IP address here. */
if (inet_pton(AF_INET, listen_addr, &sin.sin_addr.s_addr) <= 0)
- return 0;
+ return socknum;
} else {
sin.sin_addr.s_addr = htonl(INADDR_ANY);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
- return 0;
+ return socknum;
if (set_reuse_addr(sockfd)) {
close(sockfd);
- return 0;
+ return socknum;
}
if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
close(sockfd);
- return 0;
+ return socknum;
}
if (listen(sockfd, 5) < 0) {
close(sockfd);
- return 0;
+ return socknum;
}
flags = fcntl(sockfd, F_GETFD, 0);
if (flags >= 0)
fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);
- *socklist_p = xmalloc(sizeof(int));
- **socklist_p = sockfd;
- return 1;
+ socklist = xrealloc(socklist, sizeof(int) * (socknum + 1));
+ socklist[socknum++] = sockfd;
+
+ *socklist_p = socklist;
+ return socknum;
}
#endif
+static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
+{
+ int socknum = 0, *socklist = NULL;
+
+ socknum = setup_named_sock(listen_addr, listen_port, &socklist, socknum);
+
+ *socklist_p = socklist;
+ return socknum;
+}
+
static int service_loop(int socknum, int *socklist)
{
struct pollfd *pfd;
--
1.7.1
next prev parent reply other threads:[~2010-08-29 15:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-23 16:54 added possibility to supply more than one --listen argument to git-daemon Alexander Sulfrian
2010-08-23 16:54 ` [PATCH] " Alexander Sulfrian
2010-08-23 19:56 ` Junio C Hamano
2010-08-29 15:07 ` daemon: allow more than one host addresses given via --listen Alexander Sulfrian
2010-08-29 15:13 ` Alexander Sulfrian
2010-08-29 15:13 ` [PATCHv3 1/2] daemon: add helper function named_sock_setup Alexander Sulfrian
2010-08-29 15:13 ` [PATCHv3 2/2] daemon: allow more than one host address given via --listen Alexander Sulfrian
2010-08-30 7:28 ` Junio C Hamano
2010-08-30 11:30 ` Alexander Sulfrian
2010-08-30 11:30 ` [PATCHv4 1/2] daemon: add helper function named_sock_setup Alexander Sulfrian
2010-08-30 12:12 ` Erik Faye-Lund
2010-08-30 12:46 ` AlexanderS
2010-08-30 12:58 ` Erik Faye-Lund
2010-08-30 11:30 ` [PATCHv4 2/2] daemon: allow more than one host address given via --listen Alexander Sulfrian
2010-08-29 15:07 ` Alexander Sulfrian [this message]
2010-08-29 15:07 ` [PATCHv2 " Alexander Sulfrian
2010-08-29 15:11 ` Erik Faye-Lund
2010-08-29 15:17 ` AlexanderS
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1283094462-5184-2-git-send-email-alexander@sulfrian.net \
--to=alexander@sulfrian.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).