diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-16 19:13:45 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-16 19:13:45 +0000 |
commit | bc57c1cebf65b9d10c97961cc0cd8a7bf166d76e (patch) | |
tree | f0d057680247821ccaf769246ba361b94aa1225a /src/util | |
parent | 9df183774b9b2b4cef897cb4f66240bb8c2198ec (diff) | |
download | gnunet-bc57c1cebf65b9d10c97961cc0cd8a7bf166d76e.tar.gz gnunet-bc57c1cebf65b9d10c97961cc0cd8a7bf166d76e.zip |
Add evict functionalty to mq cancellation.
Useful to avoid copying of buffers when canceling a
partially sent message.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/mq.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/util/mq.c b/src/util/mq.c index 7c13265d8..6978f662b 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -82,7 +82,6 @@ struct GNUNET_MQ_Envelope | |||
82 | * Did the application call #GNUNET_MQ_env_set_options()? | 82 | * Did the application call #GNUNET_MQ_env_set_options()? |
83 | */ | 83 | */ |
84 | int have_custom_options; | 84 | int have_custom_options; |
85 | |||
86 | }; | 85 | }; |
87 | 86 | ||
88 | 87 | ||
@@ -187,6 +186,11 @@ struct GNUNET_MQ_Handle | |||
187 | * Number of entries we have in the envelope-DLL. | 186 | * Number of entries we have in the envelope-DLL. |
188 | */ | 187 | */ |
189 | unsigned int queue_length; | 188 | unsigned int queue_length; |
189 | |||
190 | /** | ||
191 | * GNUNET_YES if GNUNET_MQ_impl_evict was called. | ||
192 | */ | ||
193 | int evict_called; | ||
190 | }; | 194 | }; |
191 | 195 | ||
192 | 196 | ||
@@ -1105,6 +1109,8 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
1105 | 1109 | ||
1106 | GNUNET_assert (NULL != mq); | 1110 | GNUNET_assert (NULL != mq); |
1107 | GNUNET_assert (NULL != mq->cancel_impl); | 1111 | GNUNET_assert (NULL != mq->cancel_impl); |
1112 | |||
1113 | mq->evict_called = GNUNET_NO; | ||
1108 | 1114 | ||
1109 | if (mq->current_envelope == ev) | 1115 | if (mq->current_envelope == ev) |
1110 | { | 1116 | { |
@@ -1140,9 +1146,12 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev) | |||
1140 | mq->queue_length--; | 1146 | mq->queue_length--; |
1141 | } | 1147 | } |
1142 | 1148 | ||
1143 | ev->parent_queue = NULL; | 1149 | if (GNUNET_YES != mq->evict_called) |
1144 | ev->mh = NULL; | 1150 | { |
1145 | GNUNET_free (ev); | 1151 | ev->parent_queue = NULL; |
1152 | ev->mh = NULL; | ||
1153 | GNUNET_free (ev); | ||
1154 | } | ||
1146 | } | 1155 | } |
1147 | 1156 | ||
1148 | 1157 | ||
@@ -1285,4 +1294,31 @@ GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle *dnh | |||
1285 | } | 1294 | } |
1286 | 1295 | ||
1287 | 1296 | ||
1297 | /** | ||
1298 | * Get the message that is currently being sent when cancellation of that | ||
1299 | * message is requested. Returns an opaque pointer which contains the memory | ||
1300 | * for the message, as well as some control data used by mq. | ||
1301 | * | ||
1302 | * This function may be called at most once in the cancel_impl | ||
1303 | * function of a message queue. | ||
1304 | * | ||
1305 | * Use this function to avoid copying a half-sent message. | ||
1306 | * | ||
1307 | * @param mq message queue | ||
1308 | * @parem msg pointer to store the message being canceled | ||
1309 | * @return memory block that contains the message, must be freed by the caller | ||
1310 | */ | ||
1311 | void * | ||
1312 | GNUNET_MQ_impl_cancel_evict (struct GNUNET_MQ_Handle *mq, struct GNUNET_MessageHeader **msg) | ||
1313 | { | ||
1314 | GNUNET_assert (GNUNET_NO == mq->evict_called); | ||
1315 | GNUNET_assert (NULL != mq->current_envelope); | ||
1316 | mq->evict_called = GNUNET_YES; | ||
1317 | mq->current_envelope->parent_queue = NULL; | ||
1318 | mq->current_envelope->mh = NULL; | ||
1319 | *msg = mq->current_envelope->mh; | ||
1320 | return mq->current_envelope; | ||
1321 | } | ||
1322 | |||
1323 | |||
1288 | /* end of mq.c */ | 1324 | /* end of mq.c */ |