aboutsummaryrefslogtreecommitdiff
path: root/src/set/mq.h
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-04-30 00:04:25 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-04-30 00:04:25 +0000
commit85f905805b3f5e72d06b9138b1e63db77b20cb11 (patch)
tree44abae43bdc449b3395f7015bb6b7b930cc39a66 /src/set/mq.h
parent3042006a4c995ffaa8389e7c4106ada1fed69fed (diff)
downloadgnunet-85f905805b3f5e72d06b9138b1e63db77b20cb11.tar.gz
gnunet-85f905805b3f5e72d06b9138b1e63db77b20cb11.zip
implemented most parts of the set service
Diffstat (limited to 'src/set/mq.h')
-rw-r--r--src/set/mq.h81
1 files changed, 70 insertions, 11 deletions
diff --git a/src/set/mq.h b/src/set/mq.h
index 371bb5846..97fb4acc5 100644
--- a/src/set/mq.h
+++ b/src/set/mq.h
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @author Florian Dold 22 * @author Florian Dold
23 * @file mq/mq.h 23 * @file set/mq.h
24 * @brief general purpose request queue 24 * @brief general purpose request queue
25 */ 25 */
26#ifndef MQ_H 26#ifndef MQ_H
@@ -58,14 +58,40 @@
58 */ 58 */
59#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type) 59#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
60 60
61#define GNUNET_MQ_nest(mqm, mh) GNUNET_MQ_nest_ (&mqm, mh) 61/**
62 * Append data to the end of an existing MQ message.
63 * If the operation is successful, mqm is changed to point to the new MQ message,
64 * and GNUNET_OK is returned.
65 * On failure, GNUNET_SYSERR is returned, and the pointer mqm is not changed,
66 * the user of this API must take care of disposing the already allocated message
67 * (either by sending it, or by using GNUNET_MQ_discard)
68 *
69 * @param mqm MQ message to augment with additional data
70 * @param src source buffer for the additional data
71 * @param len length of the additional data
72 */
73#define GNUNET_MQ_nest(mqm, src, len) GNUNET_MQ_nest_ (&mqm, src, len)
74
75
76
77/**
78 * Append a message to the end of an existing MQ message.
79 * If the operation is successful, mqm is changed to point to the new MQ message,
80 * and GNUNET_OK is returned.
81 * On failure, GNUNET_SYSERR is returned, and the pointer mqm is not changed,
82 * the user of this API must take care of disposing the already allocated message
83 * (either by sending it, or by using GNUNET_MQ_discard)
84 *
85 * @param mqm MQ message to augment with additional data
86 * @param mh the message to append, must be of type 'struct GNUNET_MessageHeader *'
87 */
88#define GNUNET_MQ_nest_mh(mqm, mh) ((NULL == mh) ? (GNUNET_OK) : GNUNET_MQ_nest((mqm), (mh), ntohs ((mh)->size)))
89
62 90
63/** 91/**
64 * Allocate a GNUNET_MQ_Message, where the message only consists of a header. 92 * Allocate a GNUNET_MQ_Message, where the message only consists of a header.
65 * The allocated message will already have the type and size field set. 93 * The allocated message will already have the type and size field set.
66 * 94 *
67 * @param mvar variable to store the allocated message in;
68 * must have a header field
69 * @param type type of the message 95 * @param type type of the message
70 */ 96 */
71#define GNUNET_MQ_msg_header(type) GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type) 97#define GNUNET_MQ_msg_header(type) GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
@@ -75,8 +101,7 @@
75 * Allocate a GNUNET_MQ_Message, where the message only consists of a header and extra space. 101 * Allocate a GNUNET_MQ_Message, where the message only consists of a header and extra space.
76 * The allocated message will already have the type and size field set. 102 * The allocated message will already have the type and size field set.
77 * 103 *
78 * @param mvar variable to store the allocated message in; 104 * @param mh pointer that will changed to point at to the allocated message header
79 * must have a header field
80 * @param esize extra space to allocate after the message header 105 * @param esize extra space to allocate after the message header
81 * @param type type of the message 106 * @param type type of the message
82 */ 107 */
@@ -86,7 +111,7 @@
86/** 111/**
87 * End-marker for the handlers array 112 * End-marker for the handlers array
88 */ 113 */
89#define GNUNET_MQ_HANDLERS_END {NULL, 0} 114#define GNUNET_MQ_HANDLERS_END {NULL, 0, 0}
90 115
91/** 116/**
92 * Opaque handle to a message queue 117 * Opaque handle to a message queue
@@ -120,9 +145,17 @@ struct GNUNET_MQ_Handler
120 145
121 146
122 /** 147 /**
123 * Type of the message we are interested in 148 * Type of the message this handler covers.
124 */ 149 */
125 uint16_t type; 150 uint16_t type;
151
152 /**
153 * Expected size of messages of this type. Use 0 for
154 * variable-size. If non-zero, messages of the given
155 * type will be discarded (and the connection closed)
156 * if they do not have the right size.
157 */
158 uint16_t expected_size;
126}; 159};
127 160
128/** 161/**
@@ -146,7 +179,7 @@ GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
146 179
147int 180int
148GNUNET_MQ_nest_ (struct GNUNET_MQ_Message **mqmp, 181GNUNET_MQ_nest_ (struct GNUNET_MQ_Message **mqmp,
149 const struct GNUNET_MessageHeader *m); 182 const void *src, uint16_t len);
150 183
151 184
152/** 185/**
@@ -186,7 +219,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Message *mqm);
186 * 219 *
187 * @param mq message queue, id will be unique for the queue 220 * @param mq message queue, id will be unique for the queue
188 * @param mqm message to associate 221 * @param mqm message to associate
189 * @param data to associate 222 * @param assoc_data to associate
190 */ 223 */
191uint32_t 224uint32_t
192GNUNET_MQ_assoc_add (struct GNUNET_MQ_MessageQueue *mq, 225GNUNET_MQ_assoc_add (struct GNUNET_MQ_MessageQueue *mq,
@@ -234,7 +267,7 @@ GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connecti
234/** 267/**
235 * Create a message queue for a GNUNET_STREAM_Socket. 268 * Create a message queue for a GNUNET_STREAM_Socket.
236 * 269 *
237 * @param param client the client 270 * @param client the client
238 * @return the message queue 271 * @return the message queue
239 */ 272 */
240struct GNUNET_MQ_MessageQueue * 273struct GNUNET_MQ_MessageQueue *
@@ -286,6 +319,32 @@ GNUNET_MQ_notify_sent (struct GNUNET_MQ_Message *mqm,
286 GNUNET_MQ_NotifyCallback cb, 319 GNUNET_MQ_NotifyCallback cb,
287 void *cls); 320 void *cls);
288 321
322/**
323 * Call a callback once all messages queued have been sent,
324 * i.e. the message queue is empty.
325 *
326 * @param mqm the message queue to send the notification for
327 * @param cb the callback to call on an empty queue
328 * @param cls closure for cb
329 */
330void
331GNUNET_MQ_notify_empty (struct GNUNET_MQ_MessageQueue *mqm,
332 GNUNET_MQ_NotifyCallback cb,
333 void *cls);
334
335
336/**
337 * Call a callback if reading encountered an error.
338 *
339 * @param mqm the message queue to send the notification for
340 * @param cb the callback to call on a read error
341 * @param cls closure for cb
342 */
343void
344GNUNET_MQ_notify_read_error (struct GNUNET_MQ_MessageQueue *mqm,
345 GNUNET_MQ_NotifyCallback cb,
346 void *cls);
347
289 348
290/** 349/**
291 * Destroy the message queue. 350 * Destroy the message queue.