GNUnet  0.10.x
Data Structures | Macros | Functions
mq.c File Reference

general purpose request queue More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for mq.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MQ_Envelope
 
struct  GNUNET_MQ_Handle
 Handle to a message queue. More...
 
struct  GNUNET_MQ_DestroyNotificationHandle
 Handle we return for callbacks registered to be notified when GNUNET_MQ_destroy() is called on a queue. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from(kind, "util-mq", __VA_ARGS__)
 

Functions

void GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
 Call the message message handler that was registered for the type of the given message in the given message queue. More...
 
int GNUNET_MQ_handle_message (const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
 Call the message message handler that was registered for the type of the given message in the given handlers list. More...
 
void GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
 Call the error handler of a message queue with the given error code. More...
 
void GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *ev)
 Discard the message queue message, free all allocated resources. More...
 
unsigned int GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq)
 Obtain the current length of the message queue. More...
 
void GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
 Send a message with the given message queue. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq)
 Remove the first envelope that has not yet been sent from the message queue and return it. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_env_copy (struct GNUNET_MQ_Envelope *env)
 Function to copy an envelope. More...
 
void GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_Envelope *ev)
 Send a copy of a message with the given message queue. More...
 
static void impl_send_continue (void *cls)
 Task run to call the send implementation for the next queued message, if any. More...
 
void GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
 Call the send implementation for the next queued message, if any. More...
 
void GNUNET_MQ_impl_send_in_flight (struct GNUNET_MQ_Handle *mq)
 Call the send notification for the current message, but do not try to send the next message until GNUNET_MQ_impl_send_continue is called. More...
 
struct GNUNET_MQ_HandleGNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
 Create a message queue for the specified handlers. More...
 
void GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq, void *handlers_cls)
 Change the closure argument in all of the handlers of the mq. More...
 
const struct GNUNET_MessageHeaderGNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq)
 Get the message that should currently be sent. More...
 
void * GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq)
 Get the implementation state associated with the message queue. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
 Create a new envelope. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr)
 Create a new envelope by copying an existing message. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, uint16_t base_size, uint16_t type, const struct GNUNET_MessageHeader *nested_mh)
 Implementation of the GNUNET_MQ_msg_nested_mh macro. More...
 
uint32_t GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data)
 Associate the assoc_data in mq with a unique request id. More...
 
void * GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
 Get the data associated with a request_id in a queue. More...
 
void * GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
 Remove the association for a request_id. More...
 
void GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
 Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore. More...
 
void GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
 Destroy the message queue. More...
 
const struct GNUNET_MessageHeaderGNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, uint16_t base_size)
 Implementation of the #GNUNET_MQ_extract_nexted_mh macro. More...
 
void GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
 Cancel sending the message. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq)
 Function to obtain the current envelope from within GNUNET_MQ_SendImpl implementations. More...
 
struct GNUNET_MQ_EnvelopeGNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq)
 Function to obtain the last envelope in the queue. More...
 
void GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env, enum GNUNET_MQ_PriorityPreferences pp)
 Set application-specific preferences for this envelope. More...
 
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env)
 Get application-specific options for this envelope. More...
 
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1, enum GNUNET_MQ_PriorityPreferences p2)
 Combine performance preferences set for different envelopes that are being combined into one larger envelope. More...
 
void GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_PriorityPreferences pp)
 Set application-specific default options for this queue. More...
 
const struct GNUNET_MessageHeaderGNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env)
 Obtain message contained in envelope. More...
 
const struct GNUNET_MQ_EnvelopeGNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env)
 Return next envelope in queue. More...
 
struct GNUNET_MQ_DestroyNotificationHandleGNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
 Register function to be called whenever mq is being destroyed. More...
 
void GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh)
 Cancel registration from GNUNET_MQ_destroy_notify(). More...
 
void GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head, struct GNUNET_MQ_Envelope **env_tail, struct GNUNET_MQ_Envelope *env)
 Insert env into the envelope DLL starting at env_head Note that env must not be in any MQ while this function is used with DLLs defined outside of the MQ module. More...
 
void GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head, struct GNUNET_MQ_Envelope **env_tail, struct GNUNET_MQ_Envelope *env)
 Insert env into the envelope DLL starting at env_head Note that env must not be in any MQ while this function is used with DLLs defined outside of the MQ module. More...
 
void GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head, struct GNUNET_MQ_Envelope **env_tail, struct GNUNET_MQ_Envelope *env)
 Remove env from the envelope DLL starting at env_head. More...
 
struct GNUNET_MQ_MessageHandlerGNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
 Copy an array of handlers. More...
 
struct GNUNET_MQ_MessageHandlerGNUNET_MQ_copy_handlers2 (const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_MessageCallback agpl_handler, void *agpl_cls)
 Copy an array of handlers, appending AGPL handler. More...
 
unsigned int GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers)
 Count the handlers in a handler array. More...
 
const char * GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type)
 Convert an enum GNUNET_MQ_PreferenceType to a string. More...
 

Detailed Description

general purpose request queue

Author
Florian Dold

Definition in file mq.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "util-mq", __VA_ARGS__)

Function Documentation

◆ impl_send_continue()

static void impl_send_continue ( void *  cls)
static

Task run to call the send implementation for the next queued message, if any.

Only useful for implementing message queues, results in undefined behavior if not used carefully.

Parameters
clsmessage queue to send the next message with

Definition at line 454 of file mq.c.

References GNUNET_MQ_Handle::current_envelope, GNUNET_MQ_Handle::envelope_head, GNUNET_MQ_Handle::envelope_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_Handle::impl_state, LOG, GNUNET_MQ_Envelope::mh, mq, GNUNET_MQ_Handle::send_impl, GNUNET_MQ_Handle::send_task, and GNUNET_MessageHeader::type.

Referenced by GNUNET_MQ_impl_send_continue().

455 {
456  struct GNUNET_MQ_Handle *mq = cls;
457 
458  mq->send_task = NULL;
459  /* call is only valid if we're actually currently sending
460  * a message */
461  if (NULL == mq->envelope_head)
462  return;
465  mq->envelope_tail,
466  mq->current_envelope);
467 
469  "sending message of type %u from queue\n",
470  ntohs(mq->current_envelope->mh->type));
471 
472  mq->send_impl(mq, mq->current_envelope->mh, mq->impl_state);
473 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader * mh
Actual allocated message header.
Definition: mq.c:50
void * impl_state
Implementation-specific state.
Definition: mq.c:109
struct GNUNET_MQ_Envelope * envelope_tail
Linked list of messages pending to be sent.
Definition: mq.c:134
GNUNET_MQ_SendImpl send_impl
Actual implementation of message sending, called when a message is added.
Definition: mq.c:94
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_SCHEDULER_Task * send_task
Task to asynchronously run impl_send_continue().
Definition: mq.c:124
#define LOG(kind,...)
Definition: mq.c:29
Handle to a message queue.
Definition: mq.c:84
struct GNUNET_MQ_Envelope * current_envelope
Message that is currently scheduled to be sent.
Definition: mq.c:141
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * envelope_head
Linked list of messages pending to be sent.
Definition: mq.c:129
Here is the caller graph for this function: