Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Change blocked RPC to non-blocked RPC #162

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/remote_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "remote_common.h"
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "common.h"

bool die_on_amqp_error(amqp_rpc_reply_t x, char const *context)
Expand Down Expand Up @@ -186,7 +187,12 @@ bool wait_response_message(amqp_connection_state_t *conn,
* AMQP_FRAME_BODY*/
for (;;) {
amqp_maybe_release_buffers(*conn);
amqp_simple_wait_frame(*conn, &frame);

struct timeval t = {10, 0}; /* RPC timeout: 10s*/
wusyong marked this conversation as resolved.
Show resolved Hide resolved
if (!die_on_error(amqp_simple_wait_frame_noblock(*conn, &frame, &t),
"RPC timeout"))
return false;

if (!die_on_amqp_error(amqp_get_rpc_reply(*conn), "Wait method frame"))
return false;

Expand All @@ -209,7 +215,11 @@ bool wait_response_message(amqp_connection_state_t *conn,
#endif

amqp_maybe_release_buffers(*conn);
amqp_simple_wait_frame(*conn, &frame);

if (!die_on_error(amqp_simple_wait_frame_noblock(*conn, &frame, &t),
"RPC timeout"))
return false;

if (!die_on_amqp_error(amqp_get_rpc_reply(*conn), "Wait header frame"))
return false;

Expand All @@ -230,7 +240,10 @@ bool wait_response_message(amqp_connection_state_t *conn,
body_target = (size_t) frame.payload.properties.body_size;
body_received = 0;
while (body_received < body_target) {
amqp_simple_wait_frame(*conn, &frame);
if (!die_on_error(amqp_simple_wait_frame_noblock(*conn, &frame, &t),
"RPC timeout"))
return false;

if (!die_on_amqp_error(amqp_get_rpc_reply(*conn),
"Wait body frame"))
return false;
Expand Down