aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_socks.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-05 11:41:23 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-05 11:41:23 +0000
commit904c393e01da94dc9e842b1c3050eea7ae96b4f0 (patch)
tree0ea34440397241e464e2ffbd7ece78ee3026f9bf /src/util/test_socks.c
parentbed74ba115e1ff8501482dcb7f94fc0214e647b8 (diff)
downloadgnunet-904c393e01da94dc9e842b1c3050eea7ae96b4f0.tar.gz
gnunet-904c393e01da94dc9e842b1c3050eea7ae96b4f0.zip
update tests to use new MQ API
Diffstat (limited to 'src/util/test_socks.c')
-rw-r--r--src/util/test_socks.c71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/util/test_socks.c b/src/util/test_socks.c
index 7f1140720..d63cce571 100644
--- a/src/util/test_socks.c
+++ b/src/util/test_socks.c
@@ -29,7 +29,7 @@
29 29
30#define MYNAME "test_sockst" 30#define MYNAME "test_sockst"
31 31
32static struct GNUNET_CLIENT_Connection *client; 32static struct GNUNET_MQ_Handle *mq;
33 33
34static struct GNUNET_SERVER_Handle *server; 34static struct GNUNET_SERVER_Handle *server;
35 35
@@ -93,35 +93,35 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = {
93 93
94 94
95static void 95static void
96recv_bounce (void *cls, const struct GNUNET_MessageHeader *got) 96handle_bounce (void *cls,
97 const struct GNUNET_MessageHeader *got)
97{ 98{
98 int *ok = cls; 99 int *ok = cls;
99 struct GNUNET_MessageHeader msg;
100 100
101 GNUNET_assert (got != NULL); /* timeout */
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "Receiving bounce, checking content\n"); 102 "Receiving bounce, checking content\n");
104 msg.type = htons (MY_TYPE); 103 GNUNET_assert (NULL != got);
105 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 104 GNUNET_MQ_destroy (mq);
106 GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); 105 mq = NULL;
107 GNUNET_CLIENT_disconnect (client);
108 client = NULL;
109 GNUNET_SERVER_destroy (server); 106 GNUNET_SERVER_destroy (server);
110 server = NULL; 107 server = NULL;
111 *ok = 0; 108 *ok = 0;
112} 109}
113 110
114 111
115static size_t 112/**
116make_msg (void *cls, size_t size, void *buf) 113 * Generic error handler, called with the appropriate error code and
114 * the same closure specified at the creation of the message queue.
115 * Not every message queue implementation supports an error handler.
116 *
117 * @param cls closure with the `struct GNUNET_STATISTICS_Handle *`
118 * @param error error code
119 */
120static void
121mq_error_handler (void *cls,
122 enum GNUNET_MQ_Error error)
117{ 123{
118 struct GNUNET_MessageHeader *msg = buf; 124 GNUNET_assert (0); /* should never happen */
119
120 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
121 msg->type = htons (MY_TYPE);
122 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating message for transmission\n");
124 return sizeof (struct GNUNET_MessageHeader);
125} 125}
126 126
127 127
@@ -131,9 +131,15 @@ task (void *cls)
131 struct sockaddr_in sa; 131 struct sockaddr_in sa;
132 struct sockaddr *sap[2]; 132 struct sockaddr *sap[2];
133 socklen_t slens[2]; 133 socklen_t slens[2];
134 134 struct GNUNET_MQ_Envelope *env;
135 /* test that ill-configured client fails instantly */ 135 struct GNUNET_MessageHeader *msg;
136 GNUNET_assert (NULL == GNUNET_CLIENT_connect ("invalid-service", cfg)); 136 GNUNET_MQ_hd_fixed_size (bounce,
137 MY_TYPE,
138 struct GNUNET_MessageHeader);
139 struct GNUNET_MQ_MessageHandler chandlers[] = {
140 make_bounce_handler (cls),
141 GNUNET_MQ_handler_end ()
142 };
137 143
138 /* test IPC between client and server */ 144 /* test IPC between client and server */
139 sap[0] = (struct sockaddr *) &sa; 145 sap[0] = (struct sockaddr *) &sa;
@@ -154,19 +160,16 @@ task (void *cls)
154 handlers[0].callback_cls = cls; 160 handlers[0].callback_cls = cls;
155 handlers[1].callback_cls = cls; 161 handlers[1].callback_cls = cls;
156 GNUNET_SERVER_add_handlers (server, handlers); 162 GNUNET_SERVER_add_handlers (server, handlers);
157 client = GNUNET_CLIENT_connect (MYNAME, cfg); 163 mq = GNUNET_CLIENT_connecT (cfg,
158 GNUNET_assert (client != NULL); 164 MYNAME,
159 GNUNET_assert (NULL != 165 chandlers,
160 GNUNET_CLIENT_notify_transmit_ready (client, 166 &mq_error_handler,
161 sizeof (struct 167 NULL);
162 GNUNET_MessageHeader), 168 GNUNET_assert (NULL != mq);
163 GNUNET_TIME_relative_multiply 169 env = GNUNET_MQ_msg (msg,
164 (GNUNET_TIME_UNIT_SECONDS,5), 170 MY_TYPE);
165 GNUNET_NO, &make_msg, 171 GNUNET_MQ_send (mq,
166 NULL)); 172 env);
167 GNUNET_CLIENT_receive (client, &recv_bounce, cls,
168 GNUNET_TIME_relative_multiply
169 (GNUNET_TIME_UNIT_MILLISECONDS, 10000));
170} 173}
171 174
172 175