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: [PATCH V2 3/5] trace-cmd: Use poll(2) to wait for a message
Date: Fri, 13 Sep 2013 11:06:35 +0900 [thread overview]
Message-ID: <20130913020635.28927.45044.stgit@yunodevel> (raw)
In-Reply-To: <20130913020627.28927.69090.stgit@yunodevel>
Use poll(2) to wait for a message. If a client/server cannot send a message for
any reasons, the current server/client will wait in a blocking read operation.
So, we use poll(2) for avoiding remaining in a blocking state.
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
---
trace-msg.c | 42 ++++++++++++++++++++++++++++++++++++------
1 file changed, 36 insertions(+), 6 deletions(-)
diff --git a/trace-msg.c b/trace-msg.c
index cf82ff6..61bde54 100644
--- a/trace-msg.c
+++ b/trace-msg.c
@@ -396,6 +396,27 @@ error:
return -ENOMSG;
}
+#define MSG_WAIT_MSEC 5000
+
+/*
+ * A return value of 0 indicates time-out
+ */
+static int tracecmd_msg_recv_wait(int fd, char *buf, struct tracecmd_msg **msg)
+{
+ struct pollfd pfd;
+ int ret;
+
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ ret = poll(&pfd, 1, MSG_WAIT_MSEC);
+ if (ret < 0) {
+ return -errno;
+ } else if (ret == 0)
+ return -ETIMEDOUT;
+
+ return tracecmd_msg_recv(fd, buf);
+}
+
static void *tracecmd_msg_buf_access(struct tracecmd_msg *msg, int offset)
{
return (void *)msg + offset;
@@ -407,9 +428,12 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg **msg)
u32 cmd;
int ret;
- ret = tracecmd_msg_recv(fd, msg_tmp);
- if (ret < 0)
+ ret = tracecmd_msg_recv_wait(fd, msg_tmp, msg);
+ if (ret < 0) {
+ if (ret == -ETIMEDOUT)
+ warning("Connection timed out\n");
return ret;
+ }
*msg = (struct tracecmd_msg *)msg_tmp;
cmd = ntohl((*msg)->cmd);
@@ -487,9 +511,12 @@ int tracecmd_msg_initial_setting(int fd, int *cpus, int *pagesize)
u32 size = 0;
u32 cmd;
- ret = tracecmd_msg_recv(fd, buf);
- if (ret < 0)
+ ret = tracecmd_msg_recv_wait(fd, buf, &msg);
+ if (ret < 0) {
+ if (ret == -ETIMEDOUT)
+ warning("Connection timed out\n");
return ret;
+ }
msg = (struct tracecmd_msg *)buf;
cmd = ntohl(msg->cmd);
@@ -625,9 +652,12 @@ int tracecmd_msg_collect_metadata(int ifd, int ofd)
int ret;
do {
- ret = tracecmd_msg_recv(ifd, buf);
+ ret = tracecmd_msg_recv_wait(ifd, buf, &msg);
if (ret < 0) {
- warning("reading client");
+ if (ret == -ETIMEDOUT)
+ warning("Connection timed out\n");
+ else
+ warning("reading client");
return ret;
}
next prev parent reply other threads:[~2013-09-13 2:03 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-13 2:06 [PATCH V2 0/5] trace-cmd: Support the feature recording trace data of guests on the host Yoshihiro YUNOMAE
2013-09-13 2:06 ` [PATCH V2 1/5] [CLEANUP] trace-cmd: Split out binding a port and fork reader from open_udp() Yoshihiro YUNOMAE
2013-09-13 2:06 ` [PATCH V2 2/5] trace-cmd: Apply the trace-msg protocol for communication between a server and clients Yoshihiro YUNOMAE
2013-10-15 2:21 ` Steven Rostedt
2013-10-17 6:34 ` Yoshihiro YUNOMAE
2013-10-17 21:21 ` Steven Rostedt
2013-10-18 2:19 ` Steven Rostedt
2013-10-22 8:53 ` Yoshihiro YUNOMAE
2013-09-13 2:06 ` Yoshihiro YUNOMAE [this message]
2013-09-13 2:06 ` [PATCH V2 4/5] trace-cmd: Add virt-server mode for a virtualization environment Yoshihiro YUNOMAE
2013-10-18 2:32 ` Steven Rostedt
2013-10-22 8:55 ` Yoshihiro YUNOMAE
2013-09-13 2:06 ` [PATCH V2 5/5] trace-cmd: Add --virt option for record mode Yoshihiro YUNOMAE
2013-10-11 1:39 ` [PATCH V2 0/5] trace-cmd: Support the feature recording trace data of guests on the host Yoshihiro YUNOMAE
2013-10-11 1:46 ` Steven Rostedt
2013-10-14 21:26 ` Steven Rostedt
2013-10-17 6:32 ` Yoshihiro YUNOMAE
2013-10-17 21:11 ` Steven Rostedt
2013-10-18 15:06 ` Steven Rostedt
2013-10-22 8:53 ` 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=20130913020635.28927.45044.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