aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-19 18:50:00 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-19 18:50:00 +0000
commit2042d867f71e3cb1d7ade6b3d474ce0c1f5f87bd (patch)
tree58be8b2e7321a91015df8ab3281a9f89a26cec1f /src/util
parentd8d3021ad9af2abe551fd6cd0fe2529a99d3683c (diff)
downloadgnunet-2042d867f71e3cb1d7ade6b3d474ce0c1f5f87bd.tar.gz
gnunet-2042d867f71e3cb1d7ade6b3d474ce0c1f5f87bd.zip
redefine GNUNET_MQ_queue_for_connection_client to capture client handle
Diffstat (limited to 'src/util')
-rw-r--r--src/util/client.c30
-rw-r--r--src/util/mq.c12
-rw-r--r--src/util/test_mq_client.c27
3 files changed, 52 insertions, 17 deletions
diff --git a/src/util/client.c b/src/util/client.c
index d00e8bbd0..e30ce6589 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -404,6 +404,36 @@ do_connect (const char *service_name,
404 404
405 405
406/** 406/**
407 * Create a message queue to connect to a GNUnet service.
408 * If handlers are specfied, receive messages from the connection.
409 *
410 * @param connection the client connection
411 * @param handlers handlers for receiving messages, can be NULL
412 * @param error_handler error handler
413 * @param error_handler_cls closure for the @a error_handler
414 * @return the message queue, NULL on error
415 */
416struct GNUNET_MQ_Handle *
417GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
418 const char *service_name,
419 const struct GNUNET_MQ_MessageHandler *handlers,
420 GNUNET_MQ_ErrorHandler error_handler,
421 void *error_handler_cls)
422{
423 struct GNUNET_CLIENT_Connection *c;
424
425 c = GNUNET_CLIENT_connect (service_name,
426 cfg);
427 if (NULL == c)
428 return NULL;
429 return GNUNET_MQ_queue_for_connection_client (c,
430 handlers,
431 error_handler,
432 error_handler_cls);
433}
434
435
436/**
407 * Get a connection with a service. 437 * Get a connection with a service.
408 * 438 *
409 * @param service_name name of the service 439 * @param service_name name of the service
diff --git a/src/util/mq.c b/src/util/mq.c
index 4170338ad..c14b4b91d 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -206,7 +206,7 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
206 const struct GNUNET_MQ_MessageHandler *handler; 206 const struct GNUNET_MQ_MessageHandler *handler;
207 int handled = GNUNET_NO; 207 int handled = GNUNET_NO;
208 uint16_t ms = ntohs (mh->size); 208 uint16_t ms = ntohs (mh->size);
209 209
210 if (NULL == mq->handlers) 210 if (NULL == mq->handlers)
211 goto done; 211 goto done;
212 for (handler = mq->handlers; NULL != handler->cb; handler++) 212 for (handler = mq->handlers; NULL != handler->cb; handler++)
@@ -665,6 +665,9 @@ static void
665connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, 665connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
666 void *impl_state) 666 void *impl_state)
667{ 667{
668 struct ClientConnectionState *state = impl_state;
669
670 GNUNET_CLIENT_disconnect (state->connection);
668 GNUNET_free (impl_state); 671 GNUNET_free (impl_state);
669} 672}
670 673
@@ -692,6 +695,7 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
692 void *impl_state) 695 void *impl_state)
693{ 696{
694 struct ClientConnectionState *state = impl_state; 697 struct ClientConnectionState *state = impl_state;
698
695 GNUNET_assert (NULL != state->th); 699 GNUNET_assert (NULL != state->th);
696 GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); 700 GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
697 state->th = NULL; 701 state->th = NULL;
@@ -723,9 +727,9 @@ GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connecti
723 state = GNUNET_new (struct ClientConnectionState); 727 state = GNUNET_new (struct ClientConnectionState);
724 state->connection = connection; 728 state->connection = connection;
725 mq->impl_state = state; 729 mq->impl_state = state;
726 mq->send_impl = connection_client_send_impl; 730 mq->send_impl = &connection_client_send_impl;
727 mq->destroy_impl = connection_client_destroy_impl; 731 mq->destroy_impl = &connection_client_destroy_impl;
728 mq->cancel_impl = connection_client_cancel_impl; 732 mq->cancel_impl = &connection_client_cancel_impl;
729 if (NULL != handlers) 733 if (NULL != handlers)
730 state->receive_requested = GNUNET_YES; 734 state->receive_requested = GNUNET_YES;
731 735
diff --git a/src/util/test_mq_client.c b/src/util/test_mq_client.c
index f894c3912..27458ec0a 100644
--- a/src/util/test_mq_client.c
+++ b/src/util/test_mq_client.c
@@ -32,8 +32,6 @@
32 32
33static struct GNUNET_SERVER_Handle *server; 33static struct GNUNET_SERVER_Handle *server;
34 34
35static struct GNUNET_CLIENT_Connection *client;
36
37static struct GNUNET_CONFIGURATION_Handle *cfg; 35static struct GNUNET_CONFIGURATION_Handle *cfg;
38 36
39static int ok; 37static int ok;
@@ -44,13 +42,15 @@ static int received = 0;
44 42
45 43
46static void 44static void
47recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, 45recv_cb (void *cls,
46 struct GNUNET_SERVER_Client *argclient,
48 const struct GNUNET_MessageHeader *message) 47 const struct GNUNET_MessageHeader *message)
49{ 48{
50 received++; 49 received++;
51 if (received == 2) 50 if (received == 2)
52 { 51 {
53 GNUNET_SERVER_receive_done (argclient, GNUNET_NO); 52 GNUNET_SERVER_receive_done (argclient,
53 GNUNET_NO);
54 return; 54 return;
55 } 55 }
56 56
@@ -79,7 +79,8 @@ clean_up (void *cls)
79 * @param client identification of the client 79 * @param client identification of the client
80 */ 80 */
81static void 81static void
82notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 82notify_disconnect (void *cls,
83 struct GNUNET_SERVER_Client *client)
83{ 84{
84 if (client == NULL) 85 if (client == NULL)
85 return; 86 return;
@@ -110,11 +111,15 @@ send_trap_cb (void *cls)
110 111
111 112
112static void 113static void
113test_mq (struct GNUNET_CLIENT_Connection *client) 114test_mq ()
114{ 115{
116 struct GNUNET_CLIENT_Connection *client;
115 struct GNUNET_MQ_Handle *mq; 117 struct GNUNET_MQ_Handle *mq;
116 struct GNUNET_MQ_Envelope *mqm; 118 struct GNUNET_MQ_Envelope *mqm;
117 119
120 client = GNUNET_CLIENT_connect ("test", cfg);
121 GNUNET_assert (client != NULL);
122
118 /* FIXME: test handling responses */ 123 /* FIXME: test handling responses */
119 mq = GNUNET_MQ_queue_for_connection_client (client, NULL, NULL, NULL); 124 mq = GNUNET_MQ_queue_for_connection_client (client, NULL, NULL, NULL);
120 125
@@ -122,14 +127,13 @@ test_mq (struct GNUNET_CLIENT_Connection *client)
122 GNUNET_MQ_send (mq, mqm); 127 GNUNET_MQ_send (mq, mqm);
123 128
124 mqm = GNUNET_MQ_msg_header (MY_TYPE); 129 mqm = GNUNET_MQ_msg_header (MY_TYPE);
125 GNUNET_MQ_notify_sent (mqm, send_trap_cb, NULL); 130 GNUNET_MQ_notify_sent (mqm, &send_trap_cb, NULL);
126 GNUNET_MQ_send (mq, mqm); 131 GNUNET_MQ_send (mq, mqm);
127 GNUNET_MQ_send_cancel (mqm); 132 GNUNET_MQ_send_cancel (mqm);
128 133
129 mqm = GNUNET_MQ_msg_header (MY_TYPE); 134 mqm = GNUNET_MQ_msg_header (MY_TYPE);
130 GNUNET_MQ_notify_sent (mqm, send_cb, NULL); 135 GNUNET_MQ_notify_sent (mqm, &send_cb, NULL);
131 GNUNET_MQ_send (mq, mqm); 136 GNUNET_MQ_send (mq, mqm);
132
133} 137}
134 138
135 139
@@ -163,10 +167,7 @@ task (void *cls)
163 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); 167 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
164 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 168 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
165 "localhost"); 169 "localhost");
166 client = GNUNET_CLIENT_connect ("test", cfg); 170 test_mq ();
167 GNUNET_assert (client != NULL);
168
169 test_mq (client);
170} 171}
171 172
172 173