Ejemplo n.º 1
0
/* taken from rabbbitmq-c */
int amqp_simple_wait_method_list_noblock(amqp_connection_state_t state,
										 amqp_channel_t expected_channel,
										 amqp_method_number_t *expected_methods,
										 amqp_method_t *output,
										 struct timeval *timeout) {
	amqp_frame_t frame;
	int res = amqp_simple_wait_frame_noblock(state, &frame, timeout);

	if (AMQP_STATUS_OK != res) {
		return res;
	}

	if (AMQP_FRAME_METHOD != frame.frame_type ||
		expected_channel != frame.channel ||
		!amqp_id_in_reply_list(frame.payload.method.id, expected_methods)) {

		if (AMQP_CHANNEL_CLOSE_METHOD == frame.payload.method.id || AMQP_CONNECTION_CLOSE_METHOD == frame.payload.method.id) {

			*output = frame.payload.method;

			return AMQP_RESPONSE_SERVER_EXCEPTION;
		}

		return AMQP_STATUS_WRONG_METHOD;
	}

	*output = frame.payload.method;
	return AMQP_STATUS_OK;
}
Ejemplo n.º 2
0
/* taken from rabbbitmq-c */
static int amqp_simple_wait_method_list(amqp_connection_state_t state,
										amqp_channel_t expected_channel,
										amqp_method_number_t *expected_methods,
										amqp_method_t *output) {
	amqp_frame_t frame;
	int res = amqp_simple_wait_frame(state, &frame);

	if (AMQP_STATUS_OK != res) {
		return res;
	}

	if (AMQP_FRAME_METHOD != frame.frame_type ||
		expected_channel != frame.channel ||
		!amqp_id_in_reply_list(frame.payload.method.id, expected_methods)) {
		return AMQP_STATUS_WRONG_METHOD;
	}

	*output = frame.payload.method;
	return AMQP_STATUS_OK;
}
Ejemplo n.º 3
0
amqp_rpc_reply_t amqp_simple_rpc(amqp_connection_state_t state,
                                 amqp_channel_t channel,
                                 amqp_method_number_t request_id,
                                 amqp_method_number_t *expected_reply_ids,
                                 void *decoded_request_method)
{
    int status;
    amqp_rpc_reply_t result;

    memset(&result, 0, sizeof(result));

    status = amqp_send_method(state, channel, request_id, decoded_request_method);
    if (status < 0) {
        result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION;
        result.library_errno = -status;
        return result;
    }

    {
        amqp_frame_t frame;

retry:
        status = wait_frame_inner(state, &frame);
        if (status <= 0) {
            result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION;
            result.library_errno = -status;
            return result;
        }

        /*
         * We store the frame for later processing unless it's something
         * that directly affects us here, namely a method frame that is
         * either
         *  - on the channel we want, and of the expected type, or
         *  - on the channel we want, and a channel.close frame, or
         *  - on channel zero, and a connection.close frame.
         */
        if (!( (frame.frame_type == AMQP_FRAME_METHOD) &&
                (   ((frame.channel == channel) &&
                     ((amqp_id_in_reply_list(frame.payload.method.id, expected_reply_ids)) ||
                      (frame.payload.method.id == AMQP_CHANNEL_CLOSE_METHOD)))
                    ||
                    ((frame.channel == 0) &&
                     (frame.payload.method.id == AMQP_CONNECTION_CLOSE_METHOD))   ) ))
        {
            amqp_frame_t *frame_copy = amqp_pool_alloc(&state->decoding_pool, sizeof(amqp_frame_t));
            amqp_link_t *link = amqp_pool_alloc(&state->decoding_pool, sizeof(amqp_link_t));

            *frame_copy = frame;

            link->next = NULL;
            link->data = frame_copy;

            if (state->last_queued_frame == NULL) {
                state->first_queued_frame = link;
            } else {
                state->last_queued_frame->next = link;
            }
            state->last_queued_frame = link;

            goto retry;
        }

        result.reply_type = (amqp_id_in_reply_list(frame.payload.method.id, expected_reply_ids))
                            ? AMQP_RESPONSE_NORMAL
                            : AMQP_RESPONSE_SERVER_EXCEPTION;

        result.reply = frame.payload.method;
        return result;
    }
}