linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	linux-kernel@vger.kernel.org, yrl.pp-manager.tt@hitachi.com
Subject: [RFC PATCH 05/11] [CLEANUP] trace-cmd: Split out the connect waiting loop from do_listen()
Date: Mon, 19 Aug 2013 18:46:32 +0900	[thread overview]
Message-ID: <20130819094632.26597.59570.stgit@yunodevel> (raw)
In-Reply-To: <20130819094620.26597.79499.stgit@yunodevel>

Split out the connect waiting loop from do_listen() for avoiding duplicate codes
between listen mode and virt-server mode.

Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
---
 trace-listen.c |   45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/trace-listen.c b/trace-listen.c
index 6c1bcac..c741fa4 100644
--- a/trace-listen.c
+++ b/trace-listen.c
@@ -580,14 +580,35 @@ static void clean_up(int sig)
 	} while (ret > 0);
 }
 
+static void do_accept_loop(int sfd)
+{
+	struct sockaddr_storage peer_addr;
+	socklen_t peer_addr_len;
+	int cfd, pid;
+
+	peer_addr_len = sizeof(peer_addr);
+
+	do {
+		cfd = accept(sfd, (struct sockaddr *)&peer_addr,
+			     &peer_addr_len);
+		printf("connected!\n");
+		if (cfd < 0 && errno == EINTR)
+			continue;
+		if (cfd < 0)
+			pdie("connecting");
+
+		pid = do_connection(cfd, &peer_addr, peer_addr_len);
+		if (pid > 0)
+			add_process(pid);
+
+	} while (!done);
+}
+
 static void do_listen(char *port)
 {
 	struct addrinfo hints;
 	struct addrinfo *result, *rp;
-	int sfd, s, cfd;
-	struct sockaddr_storage peer_addr;
-	socklen_t peer_addr_len;
-	int pid;
+	int sfd, s;
 
 	if (!debug)
 		signal_setup(SIGCHLD, clean_up);
@@ -621,21 +642,7 @@ static void do_listen(char *port)
 	if (listen(sfd, backlog) < 0)
 		pdie("listen");
 
-	peer_addr_len = sizeof(peer_addr);
-
-	do {
-		cfd = accept(sfd, (struct sockaddr *)&peer_addr, &peer_addr_len);
-		printf("connected!\n");
-		if (cfd < 0 && errno == EINTR)
-			continue;
-		if (cfd < 0)
-			pdie("connecting");
-
-		pid = do_connection(cfd, &peer_addr, peer_addr_len);
-		if (pid > 0)
-			add_process(pid);
-
-	} while (!done);
+	do_accept_loop(sfd);
 
 	kill_clients();
 }


  parent reply	other threads:[~2013-08-19  9:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-19  9:46 [RFC PATCH 00/11] trace-cmd: Support the feature recording trace data of guests on the host Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 01/11] [TRIVIAL] trace-cmd: Delete the variable iface in trace-listen Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 02/11] [BUGFIX] trace-cmd: Add waitpid() when recorders are destoried Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 03/11] [BUGFIX]trace-cmd: Quit from splice(read) if there are no data Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 04/11] [CLEANUP] trace-cmd: Split out the communication with listener from setup_network() Yoshihiro YUNOMAE
2013-08-19  9:46 ` Yoshihiro YUNOMAE [this message]
2013-08-20 17:15   ` [RFC PATCH 05/11] [CLEANUP] trace-cmd: Split out the connect waiting loop from do_listen() Steven Rostedt
2013-08-20 17:18   ` Steven Rostedt
2013-08-19  9:46 ` [RFC PATCH 06/11] [CLEANUP] trace-cmd: Split out the communication with client from process_client() Yoshihiro YUNOMAE
2013-08-20 17:38   ` Steven Rostedt
2013-08-19  9:46 ` [RFC PATCH 07/11] [CLEANUP] trace-cmd: Split out binding a port and fork reader from open_udp() Yoshihiro YUNOMAE
2013-08-20 17:49   ` Steven Rostedt
2013-08-26  1:48     ` Yoshihiro YUNOMAE
2013-08-26 14:37       ` Steven Rostedt
2013-08-27  8:08         ` Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 08/11] trace-cmd: Apply the trace-msg protocol for communication between a server and clients Yoshihiro YUNOMAE
2013-08-20 17:56   ` Steven Rostedt
2013-08-26  1:50     ` Yoshihiro YUNOMAE
2013-08-26 15:11       ` Steven Rostedt
2013-08-27 10:23         ` Yoshihiro YUNOMAE
2013-08-27 13:05           ` Steven Rostedt
2013-08-28 11:30             ` Yoshihiro YUNOMAE
2013-08-28 14:42               ` Steven Rostedt
2013-08-29  1:57                 ` Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 09/11] trace-cmd: Use poll(2) to wait for a message Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 10/11] trace-cmd: Add virt-server mode for a virtualization environment Yoshihiro YUNOMAE
2013-08-19  9:46 ` [RFC PATCH 11/11] trace-cmd: Add --virt option for record mode Yoshihiro YUNOMAE
2013-08-20 16:00 ` [RFC PATCH 00/11] trace-cmd: Support the feature recording trace data of guests on the host Steven Rostedt
2013-08-26  1:46   ` Yoshihiro YUNOMAE
2013-08-26 14:22     ` Steven Rostedt
2013-08-27  8:07       ` Yoshihiro YUNOMAE
2013-08-27 13:00         ` Steven Rostedt
2013-08-28 11:31           ` Yoshihiro YUNOMAE

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130819094632.26597.59570.stgit@yunodevel \
    --to=yoshihiro.yunomae.ez@hitachi.com \
    --cc=hidehiro.kawai.ez@hitachi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=rostedt@goodmis.org \
    --cc=yrl.pp-manager.tt@hitachi.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.
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 NNTP newsgroup(s).