How to use the Nanomsg investigation architecture without the While loop?

I am using the nanomsg usage of IPC and want to use the SURVEY-archetype architecture described here. During this process, the process runs as a client and a server and exchanges data. Now the server has The following code (also listed in the link provided):

int server (const char *url)
{
int sock = nn_socket (AF_SP, NN_SURVEYOR);
assert (sock >= 0);
assert (nn_bind (sock, url) >= 0);
sleep(1); // wait for connections
int sz_d = strlen(DATE) + 1; //'\0' too
printf ("SERVER: SENDING DATE SURVEY REQUEST\n");
int bytes = nn_send (sock, DATE, sz_d, 0);
assert (bytes == sz_d);
while (1)
{
char *buf = NULL;
int bytes = nn_recv (sock, &buf, NN_MSG, 0);
if (bytes == ETIMEDOUT) break;
if (bytes >= 0)
{
printf ("SERVER: RECEIVED \ "%s\" SURVEY RESPONSE\n", buf);
nn_freemsg (buf);
}
}
return nn_shutdown (sock, 0);
}

Because the socket type is NN_SURVEY OR, so the while loop will not wait at nn_recv. For the client, the socket type is NN_RESPONDENT, so the loop in the client waits for nn_recv.

Now, because the while loop runs continuously indefinitely, the CPU The utilization rate is as high as 99%. Can you tell me that there are other ways to use nanomsg for survey structure.

If you don’t receive anything, try adding a yield() call at the end of the loop.

I am using IPC’s nanomsg usage and want to use the SURVEY-archetype described here Architecture. In this process, the process runs as a client and a server and exchanges data. Now the server has the following code (also listed in the link provided):

< pre>int server (const char *url)
{
int sock = nn_socket (AF_SP, NN_SURVEYOR);
assert (sock >= 0);
assert (nn_bind (sock , url) >= 0);
sleep(1); // wait for connections
int sz_d = strlen(DATE) + 1; //’\0′ too
printf (” SERVER: SENDING DATE SURVEY REQUEST\n”);
int bytes = nn_send (sock, DATE, sz_d, 0);
assert (bytes == sz_d);
while (1)< br /> {
char *buf = NULL;
int bytes = nn_recv (sock, &buf, NN_MSG, 0);
if (bytes == ETIMEDOUT) break;
i f (bytes >= 0)
{
printf (“SERVER: RECEIVED \”%s\” SURVEY RESPONSE\n”, buf);
nn_freemsg (buf);
}
}
return nn_shutdown (sock, 0);
)

Since the socket type is NN_SURVEYOR, the while loop will not wait at nn_recv. For customers At the end, the socket type is NN_RESPONDENT, so the loop in the client waits for nn_recv.

Now, because the while loop runs continuously indefinitely, the CPU usage rate is as high as 99%. Can you tell me, and Other methods can use nanomsg to investigate the architecture.

If you don’t receive anything, try adding a yield() call at the end of the loop.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2898 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.