git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Erik Faye-Lund <kusmabite@gmail.com>
To: Alexander Sulfrian <alexander@sulfrian.net>
Cc: gitster@pobox.com, git@vger.kernel.org
Subject: Re: [PATCHv4 1/2] daemon: add helper function named_sock_setup
Date: Mon, 30 Aug 2010 14:12:52 +0200	[thread overview]
Message-ID: <AANLkTindaa-wDkOMW=BgtNJ+Wmi3xaBo1o_CF7NFH=Qm@mail.gmail.com> (raw)
In-Reply-To: <1283167851-18331-2-git-send-email-alexander@sulfrian.net>

On Mon, Aug 30, 2010 at 1:30 PM, Alexander Sulfrian
<alexander@sulfrian.net> wrote:
> 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 |   53 +++++++++++++++++++++++++++++++++--------------------
>  1 files changed, 33 insertions(+), 20 deletions(-)
>
> diff --git a/daemon.c b/daemon.c
> index e22a2b7..c666ced 100644
> --- a/daemon.c
> +++ b/daemon.c
> @@ -734,11 +734,17 @@ static int set_reuse_addr(int sockfd)
>                          &on, sizeof(on));
>  }
>
> +struct socketlist {
> +       int *list;
> +       size_t nr;
> +       size_t alloc;
> +};
> +
>  #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, struct socketlist *socklist)
>  {
> -       int socknum = 0, *socklist = NULL;
> +       int socknum = 0;
>        int maxfd = -1;
>        char pbuf[NI_MAXSERV];
>        struct addrinfo hints, *ai0, *ai;
> @@ -753,8 +759,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
>        hints.ai_flags = AI_PASSIVE;
>
>        gai = getaddrinfo(listen_addr, pbuf, &hints, &ai0);
> -       if (gai)
> -               die("getaddrinfo() failed: %s", gai_strerror(gai));
> +       if (gai) {
> +               logerror("getaddrinfo() for %s failed: %s", listen_addr, gai_strerror(gai));
> +               return 0;
> +       }
>
>        for (ai = ai0; ai; ai = ai->ai_next) {
>                int sockfd;
> @@ -795,8 +803,9 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
>                if (flags >= 0)
>                        fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);
>
> -               socklist = xrealloc(socklist, sizeof(int) * (socknum + 1));
> -               socklist[socknum++] = sockfd;
> +               ALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc);
> +               socklist->list[socklist->nr++] = sockfd;
> +               socknum++;
>
>                if (maxfd < sockfd)
>                        maxfd = sockfd;
> @@ -804,13 +813,12 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
>
>        freeaddrinfo(ai0);
>
> -       *socklist_p = socklist;
>        return socknum;
>  }
>
>  #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, struct socketlist *socklist)
>  {
>        struct sockaddr_in sin;
>        int sockfd;
> @@ -851,22 +859,27 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
>        if (flags >= 0)
>                fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);
>
> -       *socklist_p = xmalloc(sizeof(int));
> -       **socklist_p = sockfd;
> +       ALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc);
> +       socklist->list[socklist->nr++] = sockfd;
>        return 1;
>  }
>
>  #endif
>
> -static int service_loop(int socknum, int *socklist)
> +static void socksetup(char *listen_addr, int listen_port, struct socketlist *socklist)
> +{
> +       setup_named_sock(listen_addr, listen_port, socklist);
> +}
> +
> +static int service_loop(struct socketlist *socklist)
>  {
>        struct pollfd *pfd;
>        int i;
>
> -       pfd = xcalloc(socknum, sizeof(struct pollfd));
> +       pfd = xcalloc(socklist->nr, sizeof(struct pollfd));
>
> -       for (i = 0; i < socknum; i++) {
> -               pfd[i].fd = socklist[i];
> +       for (i = 0; i < socklist->nr; i++) {
> +               pfd[i].fd = socklist->list[i];
>                pfd[i].events = POLLIN;
>        }
>
> @@ -877,7 +890,7 @@ static int service_loop(int socknum, int *socklist)
>
>                check_dead_children();
>
> -               if (poll(pfd, socknum, -1) < 0) {
> +               if (poll(pfd, socklist->nr, -1) < 0) {
>                        if (errno != EINTR) {
>                                logerror("Poll failed, resuming: %s",
>                                      strerror(errno));
> @@ -886,7 +899,7 @@ static int service_loop(int socknum, int *socklist)
>                        continue;
>                }
>
> -               for (i = 0; i < socknum; i++) {
> +               for (i = 0; i < socklist->nr; i++) {
>                        if (pfd[i].revents & POLLIN) {
>                                struct sockaddr_storage ss;
>                                unsigned int sslen = sizeof(ss);
> @@ -948,10 +961,10 @@ static void store_pid(const char *path)
>
>  static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)
>  {
> -       int socknum, *socklist;
> +       struct socketlist socklist = { NULL, 0, 0 };
>

Since serve() isn't a library function, wouldn't it reduce needless
code churn to just make socklist a set of global variables (or just a
global struct)? That way you don't have to pass it around, changing
all those function prototypes.

I'm a bit intimidated by this change since I have a rather big
patch-set on top of daemon.c, and I really don't want to resolve a lot
of conflicts. But I guess that's my problem :P

  reply	other threads:[~2010-08-30 12:17 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 [this message]
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     ` [PATCHv2 1/2] daemon: add helper function named_sock_setup Alexander Sulfrian
2010-08-29 15:07     ` [PATCHv2 2/2] daemon: allow more than one host address given via --listen 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='AANLkTindaa-wDkOMW=BgtNJ+Wmi3xaBo1o_CF7NFH=Qm@mail.gmail.com' \
    --to=kusmabite@gmail.com \
    --cc=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).