Function amqp_simple_wait_frame_noblock

Synopsis

#include <librabbitmq/amqp.h>

int amqp_simple_wait_frame_noblock(amqp_connection_state_t state, amqp_frame_t *decoded_frame, const struct timeval *tv)

Description

Read a single amqp_frame_t with a timeout.

Waits for the next amqp_frame_t frame to be read from the broker, up to a timespan specified by tv. The function will return AMQP_STATUS_TIMEOUT if the timeout is reached. The tv value is not modified by the function.

If a 0 timeval is specified, the function behaves as if its non-blocking: it will test to see if a frame can be read from the broker, and return immediately.

If NULL is passed in for tv, the function will behave like amqp_simple_wait_frame() and block until a frame is received from the broker

The library may buffer frames. When an amqp_connection_state_t object has frames buffered calling amqp_simple_wait_frame_noblock() will return an amqp_frame_t without entering a blocking read(). You can test to see if an amqp_connection_state_t object has frames buffered by calling the amqp_frames_enqueued() function.

The library has a socket read buffer. When there is data in an amqp_connection_state_t read buffer, amqp_simple_wait_frame_noblock() may return an amqp_frame_t without entering a blocking read(). You can test to see if an amqp_connection_state_t object has data in its read buffer by calling the amqp_data_in_buffer() function.

Note
This function does not return heartbeat frames. When enabled, heartbeating is handled internally by the library.
Parameters:

[ in,out ] state - the connection object

[ out ] decoded_frame - the frame

[ in ] tv - the maximum time to wait for a frame to be read. Setting tv->tv_sec = 0 and tv->tv_usec = 0 will do a non-blocking read. Specifying NULL for tv will make the function block until a frame is read.

Return
AMQP_STATUS_OK on success. An amqp_status_enum value is returned otherwise. Possible errors include:
See
amqp_simple_wait_frame() amqp_frames_enqueued() amqp_data_in_buffer()
Since
v0.4.0

Source

Lines 942-963 in librabbitmq/amqp_socket.c. Line 1550 in librabbitmq/amqp.h.

int amqp_simple_wait_frame_noblock(amqp_connection_state_t state,
                                   amqp_frame_t *decoded_frame,
                                   const struct timeval *timeout) {
  amqp_time_t deadline;

  int res = amqp_time_from_now(&deadline, timeout);
  if (AMQP_STATUS_OK != res) {
    return res;
  }

  if (state->first_queued_frame != NULL) {
    amqp_frame_t *f = (amqp_frame_t *)state->first_queued_frame->data;
    state->first_queued_frame = state->first_queued_frame->next;
    if (state->first_queued_frame == NULL) {
      state->last_queued_frame = NULL;
    }
    *decoded_frame = *f;
    return AMQP_STATUS_OK;
  } else {
    return wait_frame_inner(state, decoded_frame, deadline);
  }
}





Add Discussion as Guest

Log in to DocsForge