Re: [PATCH 2/2] GIT: Listen on IPv6 as well, if available.
- From
Petr Baudis <pasky@suse.cz>
- Date
- Jul 22, 2005, 21:21 UTC
- Message-ID
- <20050722212151.GI11916@pasky.ji.cz>
- In-Reply-To
- <20050721.091049.46807257.yoshfuji@linux-ipv6.org>
Dear diary, on Thu, Jul 21, 2005 at 03:10:49PM CEST, I got a letter where "YOSHIFUJI Hideaki / ?$B5HF#1QL@" <yoshfuji@linux-ipv6.org> told me that...
> Hello.
Hello from an IPv6 fan,
Show 11 quoted lines
> Listen on IPv6 as well, if available.
>
> Signed-off-by: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
>
> diff --git a/daemon.c b/daemon.c
> --- a/daemon.c
> +++ b/daemon.c
> @@ -219,37 +219,102 @@ static void child_handler(int signo)
>
> static int serve(int port)
> {..snip..
this whole getaddrinfo() magic looks horribly complicated. What's wrong on just adding a similar code (or factoring it out to a function) for IPv6 as there is for IPv4, just s/INET/INET6/?
Show 15 quoted lines
> for (;;) {
> - struct sockaddr_in in;
> - socklen_t addrlen = sizeof(in);
> - int incoming = accept(sockfd, (void *)&in, &addrlen);
> -
> - if (incoming < 0) {
> - switch (errno) {
> - case EAGAIN:
> - case EINTR:
> - case ECONNABORTED:
> - continue;
> - default:
> - die("accept returned %s", strerror(errno));
> + struct sockaddr_storage ss;
> + socklen_t sslen = sizeof(ss);Perhaps move those to the most inner block. (All right, I'm nitpicking too much again, sorry.)
Show 6 quoted lines
> +
> + int i;
> + fds = fds_init;
> +
> + if (select(maxfd + 1, &fds, NULL, NULL, NULL) == -1) {
> + /* warning? */Certainly a warning and at least sleep(1) to avoid cpuburn-like behaviour in case of anything going wrong.
Show 24 quoted lines
> + continue;
> + }
> +
> + for (i = 0; i < socknum; i++) {
> + int sockfd = socklist[i];
> +
> + if (FD_ISSET(sockfd, &fds)) {
> + int incoming = accept(sockfd, (struct sockaddr *)&ss, &sslen);
> + if (incoming < 0) {
> + switch (errno) {
> + case EAGAIN:
> + case EINTR:
> + case ECONNABORTED:
> + continue;
> + default:
> + die("accept returned %s", strerror(errno));
> + }
> + }
> + handle(incoming, (struct sockaddr *)&ss, sslen);
> }
> }
> - handle(incoming, &in, addrlen);
> }
> }-- Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ If you want the holes in your knowledge showing up try teaching someone. -- Alan Cox