2 This file is part of GNUnet.
3 Copyright (C) 2009, 2016 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.
21 * @file util/test_server_with_client_unix.c
22 * @brief tests for server.c and client.c,
23 * specifically disconnect_notify,
24 * client_get_address and receive_done (resume processing)
27 #include "gnunet_util_lib.h"
32 static struct GNUNET_SERVER_Handle *server;
34 static struct GNUNET_MQ_Handle *mq;
36 static struct GNUNET_CONFIGURATION_Handle *cfg;
44 struct GNUNET_SERVER_Client *argclient = cls;
46 GNUNET_assert (ok == 3);
48 GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
54 struct GNUNET_SERVER_Client *argclient,
55 const struct GNUNET_MessageHeader *message)
61 (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
62 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
68 GNUNET_MQ_destroy (mq);
69 GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
81 GNUNET_SERVER_destroy (server);
83 GNUNET_CONFIGURATION_destroy (cfg);
89 * Functions with this signature are called whenever a client
90 * is disconnected on the network level.
93 * @param client identification of the client
96 notify_disconnect (void *cls,
97 struct GNUNET_SERVER_Client *client)
101 GNUNET_assert (ok == 5);
103 (void) GNUNET_SCHEDULER_add_now (&clean_up, NULL);
107 static struct GNUNET_SERVER_MessageHandler handlers[] = {
108 {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)},
116 struct sockaddr_un un;
117 const char *unixpath = "/tmp/testsock";
118 struct sockaddr *sap[2];
120 struct GNUNET_MQ_Envelope *env;
121 struct GNUNET_MessageHeader *msg;
123 memset (&un, 0, sizeof (un));
124 un.sun_family = AF_UNIX;
125 strncpy(un.sun_path, unixpath, sizeof (un.sun_path) - 1);
126 #if HAVE_SOCKADDR_UN_SUN_LEN
127 un.sun_len = (u_char) sizeof (un);
130 sap[0] = (struct sockaddr *) &un;
131 slens[0] = sizeof (un);
135 GNUNET_SERVER_create (NULL, NULL, sap, slens,
136 GNUNET_TIME_relative_multiply
137 (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO);
138 GNUNET_assert (server != NULL);
139 handlers[0].callback_cls = cls;
140 GNUNET_SERVER_add_handlers (server, handlers);
141 GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls);
142 cfg = GNUNET_CONFIGURATION_create ();
144 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath);
145 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
147 mq = GNUNET_CLIENT_connect (cfg,
152 GNUNET_assert (NULL != mq);
154 env = GNUNET_MQ_msg (msg,
158 env = GNUNET_MQ_msg (msg,
166 main (int argc, char *argv[])
168 GNUNET_log_setup ("test_server_with_client_unix",
172 GNUNET_SCHEDULER_run (&task, NULL);
176 /* end of test_server_with_client_unix.c */