aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_mq_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_mq_lib.h')
-rw-r--r--src/include/gnunet_mq_lib.h89
1 files changed, 41 insertions, 48 deletions
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 59b692cf0..54ea806a5 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -53,36 +53,6 @@
53 */ 53 */
54#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type) 54#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
55 55
56/**
57 * Append data to the end of an existing MQ message.
58 * If the operation is successful, mqm is changed to point to the new MQ message,
59 * and GNUNET_OK is returned.
60 * On failure, GNUNET_SYSERR is returned, and the pointer mqm is not changed,
61 * the user of this API must take care of disposing the already allocated message
62 * (either by sending it, or by using GNUNET_MQ_discard)
63 *
64 * @param mqm MQ message to augment with additional data
65 * @param src source buffer for the additional data
66 * @param len length of the additional data
67 * @return GNUNET_SYSERR if nesting the message failed,
68 * GNUNET_OK on success
69 */
70#define GNUNET_MQ_nest(mqm, src, len) GNUNET_MQ_nest_ (&mqm, src, len)
71
72
73/**
74 * Append a message to the end of an existing MQ message.
75 * If the operation is successful, mqm is changed to point to the new MQ message,
76 * and GNUNET_OK is returned.
77 * On failure, GNUNET_SYSERR is returned, and the pointer mqm is not changed,
78 * the user of this API must take care of disposing the already allocated message
79 * (either by sending it, or by using GNUNET_MQ_discard)
80 *
81 * @param mqm MQ message to augment with additional data
82 * @param mh the message to append, must be of type 'struct GNUNET_MessageHeader *'
83 */
84#define GNUNET_MQ_nest_mh(mqm, mh) ((NULL == mh) ? (GNUNET_OK) : GNUNET_MQ_nest((mqm), (mh), ntohs ((mh)->size)))
85
86 56
87/** 57/**
88 * Allocate a GNUNET_MQ_Message, where the message only consists of a header. 58 * Allocate a GNUNET_MQ_Message, where the message only consists of a header.
@@ -105,6 +75,40 @@
105 75
106 76
107/** 77/**
78 * Allocate a GNUNET_MQ_Message, and append a payload message after the given
79 * message struct.
80 *
81 * @param mvar pointer to a message struct, will be changed to point at the newly allocated message,
82 * whose size is 'sizeof(*mvar) + ntohs (mh->size)'
83 * @param type message type of the allocated message, has no effect on the nested message
84 * @param mh message to nest
85 * @return a newly allocated 'struct GNUNET_MQ_Message *'
86 */
87#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) GNUNET_MQ_msg_nested_mh_((((void)(mvar)->header), (struct GNUNET_MessageHeader**) &(mvar)), sizeof (*(mvar)), (type), mh)
88
89
90/**
91 * Return a pointer to the message at the end of the given message.
92 *
93 * @param var pointer to a message struct, the type of the expression determines the base size,
94 * the space after the base size is the nested message
95 * @return a 'struct GNUNET_MessageHeader *' that points at the nested message of the given message,
96 * or NULL if the given message in 'var' does not have any space after the message struct
97 */
98#define GNUNET_MQ_extract_nested_mh(var) GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), sizeof (*(var)))
99
100
101struct GNUNET_MessageHeader *
102GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, uint16_t base_size);
103
104
105struct GNUNET_MQ_Message *
106GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, uint16_t base_size, uint16_t type,
107 const struct GNUNET_MessageHeader *nested_mh);
108
109
110
111/**
108 * End-marker for the handlers array 112 * End-marker for the handlers array
109 */ 113 */
110#define GNUNET_MQ_HANDLERS_END {NULL, 0, 0} 114#define GNUNET_MQ_HANDLERS_END {NULL, 0, 0}
@@ -128,7 +132,8 @@ enum GNUNET_MQ_Error
128 * @param cls closure 132 * @param cls closure
129 * @param msg the received message 133 * @param msg the received message
130 */ 134 */
131typedef void (*GNUNET_MQ_MessageCallback) (void *cls, const struct GNUNET_MessageHeader *msg); 135typedef void
136(*GNUNET_MQ_MessageCallback) (void *cls, const struct GNUNET_MessageHeader *msg);
132 137
133 138
134/** 139/**
@@ -151,10 +156,12 @@ typedef void
151 * 156 *
152 * @param cls closure 157 * @param cls closure
153 */ 158 */
154typedef void (*GNUNET_MQ_NotifyCallback) (void *cls); 159typedef void
160(*GNUNET_MQ_NotifyCallback) (void *cls);
155 161
156 162
157typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error); 163typedef void
164(*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error);
158 165
159 166
160struct GNUNET_MQ_Message 167struct GNUNET_MQ_Message
@@ -287,6 +294,7 @@ struct GNUNET_MQ_Handler
287}; 294};
288 295
289 296
297
290/** 298/**
291 * Create a new message for MQ. 299 * Create a new message for MQ.
292 * 300 *
@@ -300,21 +308,6 @@ GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
300 308
301 309
302/** 310/**
303 * Resize the the mq message pointed to by mqmp,
304 * and append the given data to it.
305 *
306 * @param mqmp pointer to a mq message pointer
307 * @param src source of the data to append
308 * @param len length of the data to append
309 * @return GNUNET_OK on success,
310 * GNUNET_SYSERR on error (e.g. if len is too large)
311 */
312int
313GNUNET_MQ_nest_ (struct GNUNET_MQ_Message **mqmp,
314 const void *src, uint16_t len);
315
316
317/**
318 * Discard the message queue message, free all 311 * Discard the message queue message, free all
319 * allocated resources. Must be called in the event 312 * allocated resources. Must be called in the event
320 * that a message is created but should not actually be sent. 313 * that a message is created but should not actually be sent.