2 This file is part of GNUnet.
3 Copyright (C) 2012-2014 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Florian Dold
24 * @brief general purpose request queue
27 #include "gnunet_util_lib.h"
29 #define LOG(kind,...) GNUNET_log_from (kind, "mq",__VA_ARGS__)
32 struct GNUNET_MQ_Envelope
35 * Messages are stored in a linked list.
36 * Each queue has its own list of envelopes.
38 struct GNUNET_MQ_Envelope *next;
41 * Messages are stored in a linked list
42 * Each queue has its own list of envelopes.
44 struct GNUNET_MQ_Envelope *prev;
47 * Actual allocated message header,
48 * usually points to the end of the containing GNUNET_MQ_Envelope
50 struct GNUNET_MessageHeader *mh;
53 * Queue the message is queued in, NULL if message is not queued.
55 struct GNUNET_MQ_Handle *parent_queue;
58 * Called after the message was sent irrevocably.
60 GNUNET_MQ_NotifyCallback sent_cb;
63 * Closure for @e send_cb
70 * Handle to a message queue.
72 struct GNUNET_MQ_Handle
75 * Handlers array, or NULL if the queue should not receive messages
77 struct GNUNET_MQ_MessageHandler *handlers;
80 * Actual implementation of message sending,
81 * called when a message is added
83 GNUNET_MQ_SendImpl send_impl;
86 * Implementation-dependent queue destruction function
88 GNUNET_MQ_DestroyImpl destroy_impl;
91 * Implementation-dependent send cancel function
93 GNUNET_MQ_CancelImpl cancel_impl;
96 * Implementation-specific state
101 * Callback will be called when an error occurs.
103 GNUNET_MQ_ErrorHandler error_handler;
106 * Closure for the error handler.
108 void *error_handler_cls;
111 * Linked list of messages pending to be sent
113 struct GNUNET_MQ_Envelope *envelope_head;
116 * Linked list of messages pending to be sent
118 struct GNUNET_MQ_Envelope *envelope_tail;
121 * Message that is currently scheduled to be
122 * sent. Not the head of the message queue, as the implementation
123 * needs to know if sending has been already scheduled or not.
125 struct GNUNET_MQ_Envelope *current_envelope;
128 * Map of associations, lazily allocated
130 struct GNUNET_CONTAINER_MultiHashMap32 *assoc_map;
133 * Task scheduled during #GNUNET_MQ_impl_send_continue.
135 struct GNUNET_SCHEDULER_Task *continue_task;
138 * Next id that should be used for the @e assoc_map,
139 * initialized lazily to a random value together with
145 * Number of entries we have in the envelope-DLL.
147 unsigned int queue_length;
152 * Implementation-specific state for connection to
153 * client (MQ for server).
155 struct ServerClientSocketState
158 * Handle of the client that connected to the server.
160 struct GNUNET_SERVER_Client *client;
163 * Active transmission request to the client.
165 struct GNUNET_SERVER_TransmitHandle *th;
170 * Implementation-specific state for connection to
171 * service (MQ for clients).
173 struct ClientConnectionState
176 * Did we call receive alread alreadyy?
181 * Do we also want to receive?
183 int receive_requested;
186 * Connection to the service.
188 struct GNUNET_CLIENT_Connection *connection;
191 * Active transmission request (or NULL).
193 struct GNUNET_CLIENT_TransmitHandle *th;
198 * Call the message message handler that was registered
199 * for the type of the given message in the given message queue.
201 * This function is indended to be used for the implementation
204 * @param mq message queue with the handlers
205 * @param mh message to dispatch
208 GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
209 const struct GNUNET_MessageHeader *mh)
211 const struct GNUNET_MQ_MessageHandler *handler;
212 int handled = GNUNET_NO;
213 uint16_t ms = ntohs (mh->size);
215 if (NULL == mq->handlers)
217 for (handler = mq->handlers; NULL != handler->cb; handler++)
219 if (handler->type == ntohs (mh->type))
221 handled = GNUNET_YES;
222 if ( (handler->expected_size > ms) ||
223 ( (handler->expected_size != ms) &&
224 (NULL == handler->mv) ) )
226 /* Too small, or not an exact size and
227 no 'mv' handler to check rest */
228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
229 "Received malformed message of type %u\n",
230 (unsigned int) handler->type);
231 GNUNET_MQ_inject_error (mq,
232 GNUNET_MQ_ERROR_MALFORMED);
235 if ( (NULL == handler->mv) ||
237 handler->mv (handler->cls, mh)) )
239 /* message well-formed, pass to handler */
240 handler->cb (handler->cls, mh);
244 /* Message rejected by check routine */
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 "Received malformed message of type %u\n",
247 (unsigned int) handler->type);
248 GNUNET_MQ_inject_error (mq,
249 GNUNET_MQ_ERROR_MALFORMED);
255 if (GNUNET_NO == handled)
256 LOG (GNUNET_ERROR_TYPE_DEBUG,
257 "No handler for message of type %d\n",
263 * Call the error handler of a message queue with the given
264 * error code. If there is no error handler, log a warning.
266 * This function is intended to be used by the implementation
269 * @param mq message queue
270 * @param error the error type
273 GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
274 enum GNUNET_MQ_Error error)
276 if (NULL == mq->error_handler)
278 LOG (GNUNET_ERROR_TYPE_WARNING,
279 "Got error %d, but no handler installed\n",
283 mq->error_handler (mq->error_handler_cls,
289 * Discard the message queue message, free all
290 * allocated resources. Must be called in the event
291 * that a message is created but should not actually be sent.
293 * @param mqm the message to discard
296 GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm)
298 GNUNET_assert (NULL == mqm->parent_queue);
304 * Obtain the current length of the message queue.
306 * @param mq queue to inspect
307 * @return number of queued, non-transmitted messages
310 GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq)
312 return mq->queue_length;
317 * Send a message with the given message queue.
318 * May only be called once per message.
320 * @param mq message queue
321 * @param ev the envelope with the message to send.
324 GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
325 struct GNUNET_MQ_Envelope *ev)
327 GNUNET_assert (NULL != mq);
328 GNUNET_assert (NULL == ev->parent_queue);
330 ev->parent_queue = mq;
331 /* is the implementation busy? queue it! */
332 if (NULL != mq->current_envelope)
334 GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head,
340 mq->current_envelope = ev;
341 mq->send_impl (mq, ev->mh, mq->impl_state);
346 * Send a copy of a message with the given message queue.
347 * Can be called repeatedly on the same envelope.
349 * @param mq message queue
350 * @param ev the envelope with the message to send.
353 GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq,
354 const struct GNUNET_MQ_Envelope *ev)
356 struct GNUNET_MQ_Envelope *env;
359 msize = ntohs (ev->mh->size);
360 env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) +
362 env->mh = (struct GNUNET_MessageHeader *) &env[1];
363 env->sent_cb = ev->sent_cb;
364 env->sent_cls = ev->sent_cls;
365 GNUNET_memcpy (&env[1],
375 * Task run to call the send implementation for the next queued
376 * message, if any. Only useful for implementing message queues,
377 * results in undefined behavior if not used carefully.
379 * @param cls message queue to send the next message with
382 impl_send_continue (void *cls)
384 struct GNUNET_MQ_Handle *mq = cls;
385 struct GNUNET_MQ_Envelope *current_envelope;
387 mq->continue_task = NULL;
388 /* call is only valid if we're actually currently sending
390 current_envelope = mq->current_envelope;
391 GNUNET_assert (NULL != current_envelope);
392 current_envelope->parent_queue = NULL;
393 if (NULL == mq->envelope_head)
395 mq->current_envelope = NULL;
399 mq->current_envelope = mq->envelope_head;
400 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
402 mq->current_envelope);
405 mq->current_envelope->mh,
408 if (NULL != current_envelope->sent_cb)
409 current_envelope->sent_cb (current_envelope->sent_cls);
410 GNUNET_free (current_envelope);
415 * Call the send implementation for the next queued message, if any.
416 * Only useful for implementing message queues, results in undefined
417 * behavior if not used carefully.
419 * @param mq message queue to send the next message with
422 GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
424 GNUNET_assert (NULL == mq->continue_task);
425 mq->continue_task = GNUNET_SCHEDULER_add_now (&impl_send_continue,
431 * Create a message queue for the specified handlers.
433 * @param send function the implements sending messages
434 * @param destroy function that implements destroying the queue
435 * @param cancel function that implements canceling a message
436 * @param impl_state for the queue, passed to 'send' and 'destroy'
437 * @param handlers array of message handlers
438 * @param error_handler handler for read and write errors
439 * @param error_handler_cls closure for @a error_handler
440 * @return a new message queue
442 struct GNUNET_MQ_Handle *
443 GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
444 GNUNET_MQ_DestroyImpl destroy,
445 GNUNET_MQ_CancelImpl cancel,
447 const struct GNUNET_MQ_MessageHandler *handlers,
448 GNUNET_MQ_ErrorHandler error_handler,
449 void *error_handler_cls)
451 struct GNUNET_MQ_Handle *mq;
454 mq = GNUNET_new (struct GNUNET_MQ_Handle);
455 mq->send_impl = send;
456 mq->destroy_impl = destroy;
457 mq->cancel_impl = cancel;
458 if (NULL != handlers)
460 for (i=0;NULL != handlers[i].cb; i++) ;
461 mq->handlers = GNUNET_new_array (i + 1,
462 struct GNUNET_MQ_MessageHandler);
463 GNUNET_memcpy (mq->handlers,
465 i * sizeof (struct GNUNET_MQ_MessageHandler));
467 mq->error_handler = error_handler;
468 mq->error_handler_cls = error_handler_cls;
469 mq->impl_state = impl_state;
476 * Change the closure argument in all of the `handlers` of the
479 * @param mq to modify
480 * @param handlers_cls new closure to use
483 GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq,
488 if (NULL == mq->handlers)
490 for (i=0;NULL != mq->handlers[i].cb; i++)
491 mq->handlers[i].cls = handlers_cls;
496 * Get the message that should currently be sent.
497 * Fails if there is no current message.
498 * Only useful for implementing message queues,
499 * results in undefined behavior if not used carefully.
501 * @param mq message queue with the current message
502 * @return message to send, never NULL
504 const struct GNUNET_MessageHeader *
505 GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq)
507 if (NULL == mq->current_envelope)
509 if (NULL == mq->current_envelope->mh)
511 return mq->current_envelope->mh;
516 * Get the implementation state associated with the
519 * While the GNUNET_MQ_Impl* callbacks receive the
520 * implementation state, continuations that are scheduled
521 * by the implementation function often only have one closure
522 * argument, with this function it is possible to get at the
523 * implementation state when only passing the GNUNET_MQ_Handle
526 * @param mq message queue with the current message
527 * @return message to send, never NULL
530 GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq)
532 return mq->impl_state;
536 struct GNUNET_MQ_Envelope *
537 GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
541 struct GNUNET_MQ_Envelope *mqm;
543 mqm = GNUNET_malloc (sizeof *mqm + size);
544 mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
545 mqm->mh->size = htons (size);
546 mqm->mh->type = htons (type);
554 * Create a new envelope by copying an existing message.
556 * @param hdr header of the message to copy
557 * @return envelope containing @a hdr
559 struct GNUNET_MQ_Envelope *
560 GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr)
562 struct GNUNET_MQ_Envelope *mqm;
563 uint16_t size = ntohs (hdr->size);
565 mqm = GNUNET_malloc (sizeof (*mqm) + size);
566 mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
567 GNUNET_memcpy (mqm->mh,
575 * Implementation of the #GNUNET_MQ_msg_nested_mh macro.
577 * @param mhp pointer to the message header pointer that will be changed to allocate at
578 * the newly allocated space for the message.
579 * @param base_size size of the data before the nested message
580 * @param type type of the message in the envelope
581 * @param nested_mh the message to append to the message after base_size
583 struct GNUNET_MQ_Envelope *
584 GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
587 const struct GNUNET_MessageHeader *nested_mh)
589 struct GNUNET_MQ_Envelope *mqm;
592 if (NULL == nested_mh)
593 return GNUNET_MQ_msg_ (mhp, base_size, type);
595 size = base_size + ntohs (nested_mh->size);
597 /* check for uint16_t overflow */
598 if (size < base_size)
601 mqm = GNUNET_MQ_msg_ (mhp, size, type);
602 GNUNET_memcpy ((char *) mqm->mh + base_size,
604 ntohs (nested_mh->size));
611 * Transmit a queued message to the session's client.
613 * @param cls consensus session
614 * @param size number of bytes available in @a buf
615 * @param buf where the callee should write the message
616 * @return number of bytes written to @a buf
619 transmit_queued (void *cls,
623 struct GNUNET_MQ_Handle *mq = cls;
624 struct ServerClientSocketState *state = GNUNET_MQ_impl_state (mq);
625 const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq);
628 GNUNET_assert (NULL != buf);
629 msg_size = ntohs (msg->size);
630 GNUNET_assert (size >= msg_size);
631 GNUNET_memcpy (buf, msg, msg_size);
634 GNUNET_MQ_impl_send_continue (mq);
641 server_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
644 struct ServerClientSocketState *state = impl_state;
646 if (NULL != state->th)
648 GNUNET_SERVER_notify_transmit_ready_cancel (state->th);
652 GNUNET_assert (NULL != mq);
653 GNUNET_assert (NULL != state);
654 GNUNET_SERVER_client_drop (state->client);
660 server_client_send_impl (struct GNUNET_MQ_Handle *mq,
661 const struct GNUNET_MessageHeader *msg,
664 struct ServerClientSocketState *state = impl_state;
666 GNUNET_assert (NULL != mq);
667 state->th = GNUNET_SERVER_notify_transmit_ready (state->client,
669 GNUNET_TIME_UNIT_FOREVER_REL,
670 &transmit_queued, mq);
674 struct GNUNET_MQ_Handle *
675 GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client)
677 struct GNUNET_MQ_Handle *mq;
678 struct ServerClientSocketState *scss;
680 mq = GNUNET_new (struct GNUNET_MQ_Handle);
681 scss = GNUNET_new (struct ServerClientSocketState);
682 mq->impl_state = scss;
683 scss->client = client;
684 GNUNET_SERVER_client_keep (client);
685 mq->send_impl = &server_client_send_impl;
686 mq->destroy_impl = &server_client_destroy_impl;
692 * Type of a function to call when we receive a message
696 * @param msg message received, NULL on timeout or fatal error
699 handle_client_message (void *cls,
700 const struct GNUNET_MessageHeader *msg)
702 struct GNUNET_MQ_Handle *mq = cls;
703 struct ClientConnectionState *state;
705 state = mq->impl_state;
708 GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ);
711 GNUNET_CLIENT_receive (state->connection,
712 &handle_client_message,
714 GNUNET_TIME_UNIT_FOREVER_REL);
715 GNUNET_MQ_inject_message (mq, msg);
720 * Transmit a queued message to the session's client.
722 * @param cls consensus session
723 * @param size number of bytes available in @a buf
724 * @param buf where the callee should write the message
725 * @return number of bytes written to buf
728 connection_client_transmit_queued (void *cls,
732 struct GNUNET_MQ_Handle *mq = cls;
733 const struct GNUNET_MessageHeader *msg;
734 struct ClientConnectionState *state = mq->impl_state;
737 GNUNET_assert (NULL != mq);
739 msg = GNUNET_MQ_impl_current (mq);
743 GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ);
747 if ( (GNUNET_YES == state->receive_requested) &&
748 (GNUNET_NO == state->receive_active) )
750 state->receive_active = GNUNET_YES;
751 GNUNET_CLIENT_receive (state->connection,
752 &handle_client_message,
754 GNUNET_TIME_UNIT_FOREVER_REL);
757 msg_size = ntohs (msg->size);
758 GNUNET_assert (size >= msg_size);
759 GNUNET_memcpy (buf, msg, msg_size);
762 GNUNET_MQ_impl_send_continue (mq);
769 connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
772 struct ClientConnectionState *state = impl_state;
774 if (NULL != state->th)
776 GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
779 GNUNET_CLIENT_disconnect (state->connection);
780 GNUNET_free (impl_state);
785 connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
786 const struct GNUNET_MessageHeader *msg,
789 struct ClientConnectionState *state = impl_state;
791 GNUNET_assert (NULL != state);
792 GNUNET_assert (NULL == state->th);
794 GNUNET_CLIENT_notify_transmit_ready (state->connection,
796 GNUNET_TIME_UNIT_FOREVER_REL,
798 &connection_client_transmit_queued,
800 GNUNET_assert (NULL != state->th);
805 connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
808 struct ClientConnectionState *state = impl_state;
810 GNUNET_assert (NULL != state->th);
811 GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
816 struct GNUNET_MQ_Handle *
817 GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection,
818 const struct GNUNET_MQ_MessageHandler *handlers,
819 GNUNET_MQ_ErrorHandler error_handler,
820 void *error_handler_cls)
822 struct GNUNET_MQ_Handle *mq;
823 struct ClientConnectionState *state;
826 mq = GNUNET_new (struct GNUNET_MQ_Handle);
827 if (NULL != handlers)
829 for (i=0;NULL != handlers[i].cb; i++) ;
830 mq->handlers = GNUNET_new_array (i + 1,
831 struct GNUNET_MQ_MessageHandler);
832 GNUNET_memcpy (mq->handlers,
834 i * sizeof (struct GNUNET_MQ_MessageHandler));
836 mq->error_handler = error_handler;
837 mq->error_handler_cls = error_handler_cls;
838 state = GNUNET_new (struct ClientConnectionState);
839 state->connection = connection;
840 mq->impl_state = state;
841 mq->send_impl = &connection_client_send_impl;
842 mq->destroy_impl = &connection_client_destroy_impl;
843 mq->cancel_impl = &connection_client_cancel_impl;
844 if (NULL != handlers)
845 state->receive_requested = GNUNET_YES;
852 * Associate the assoc_data in mq with a unique request id.
854 * @param mq message queue, id will be unique for the queue
855 * @param assoc_data to associate
858 GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
863 if (NULL == mq->assoc_map)
865 mq->assoc_map = GNUNET_CONTAINER_multihashmap32_create (8);
869 GNUNET_CONTAINER_multihashmap32_put (mq->assoc_map, id, assoc_data,
870 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
876 GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
879 if (NULL == mq->assoc_map)
881 return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
886 GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
891 if (NULL == mq->assoc_map)
893 val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map,
895 GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map,
902 GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *mqm,
903 GNUNET_MQ_NotifyCallback cb,
912 GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
914 if (NULL != mq->destroy_impl)
916 mq->destroy_impl (mq, mq->impl_state);
918 if (NULL != mq->continue_task)
920 GNUNET_SCHEDULER_cancel (mq->continue_task);
921 mq->continue_task = NULL;
923 while (NULL != mq->envelope_head)
925 struct GNUNET_MQ_Envelope *ev;
927 ev = mq->envelope_head;
928 ev->parent_queue = NULL;
929 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
933 GNUNET_MQ_discard (ev);
935 GNUNET_assert (0 == mq->queue_length);
936 if (NULL != mq->current_envelope)
938 /* we can only discard envelopes that
940 mq->current_envelope->parent_queue = NULL;
941 GNUNET_MQ_discard (mq->current_envelope);
942 mq->current_envelope = NULL;
944 if (NULL != mq->assoc_map)
946 GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map);
947 mq->assoc_map = NULL;
949 GNUNET_free_non_null (mq->handlers);
954 const struct GNUNET_MessageHeader *
955 GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
959 uint16_t nested_size;
960 const struct GNUNET_MessageHeader *nested_msg;
962 whole_size = ntohs (mh->size);
963 GNUNET_assert (whole_size >= base_size);
964 nested_size = whole_size - base_size;
965 if (0 == nested_size)
967 if (nested_size < sizeof (struct GNUNET_MessageHeader))
972 nested_msg = (const struct GNUNET_MessageHeader *) ((char *) mh + base_size);
973 if (ntohs (nested_msg->size) != nested_size)
983 * Cancel sending the message. Message must have been sent with
984 * #GNUNET_MQ_send before. May not be called after the notify sent
985 * callback has been called
987 * @param ev queued envelope to cancel
990 GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
992 struct GNUNET_MQ_Handle *mq = ev->parent_queue;
994 GNUNET_assert (NULL != mq);
995 GNUNET_assert (NULL != mq->cancel_impl);
997 if (mq->current_envelope == ev)
999 // complex case, we already started with transmitting
1001 mq->cancel_impl (mq,
1003 // continue sending the next message, if any
1004 if (NULL == mq->envelope_head)
1006 mq->current_envelope = NULL;
1010 mq->current_envelope = mq->envelope_head;
1011 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
1013 mq->current_envelope);
1016 mq->current_envelope->mh,
1022 // simple case, message is still waiting in the queue
1023 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
1029 ev->parent_queue = NULL;