diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-06-05 16:16:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-06-05 16:16:46 +0000 |
commit | 69a23725d6937db68fc8ca2fd1e8490220edc7de (patch) | |
tree | b4a4060dfb25ccf18254e0b726120c9b6bef9ee5 /src/util/client.c | |
parent | cf96e25a7a3c3864bb936b1b82fd086ca8d16a5e (diff) | |
download | gnunet-69a23725d6937db68fc8ca2fd1e8490220edc7de.tar.gz gnunet-69a23725d6937db68fc8ca2fd1e8490220edc7de.zip |
UNIX domain socket support
Diffstat (limited to 'src/util/client.c')
-rw-r--r-- | src/util/client.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/util/client.c b/src/util/client.c index f964b7322..c7853d146 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -250,19 +250,55 @@ struct GNUNET_CLIENT_Connection | |||
250 | * Are we ignoring shutdown signals? | 250 | * Are we ignoring shutdown signals? |
251 | */ | 251 | */ |
252 | int ignore_shutdown; | 252 | int ignore_shutdown; |
253 | |||
254 | /** | ||
255 | * How often have we tried to connect? | ||
256 | */ | ||
257 | unsigned int attempts; | ||
253 | 258 | ||
254 | }; | 259 | }; |
255 | 260 | ||
256 | 261 | ||
262 | /** | ||
263 | * Try to connect to the service. | ||
264 | * | ||
265 | * @param sched scheduler to use | ||
266 | * @param service_name name of service to connect to | ||
267 | * @param cfg configuration to use | ||
268 | * @param attempt counter used to alternate between IP and UNIX domain sockets | ||
269 | * @return NULL on error | ||
270 | */ | ||
257 | static struct GNUNET_CONNECTION_Handle * | 271 | static struct GNUNET_CONNECTION_Handle * |
258 | do_connect (struct GNUNET_SCHEDULER_Handle *sched, | 272 | do_connect (struct GNUNET_SCHEDULER_Handle *sched, |
259 | const char *service_name, | 273 | const char *service_name, |
260 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 274 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
275 | unsigned int attempt) | ||
261 | { | 276 | { |
262 | struct GNUNET_CONNECTION_Handle *sock; | 277 | struct GNUNET_CONNECTION_Handle *sock; |
263 | char *hostname; | 278 | char *hostname; |
279 | char *unixpath; | ||
264 | unsigned long long port; | 280 | unsigned long long port; |
265 | 281 | ||
282 | #if AF_UNIX | ||
283 | if (0 == attempt % 2) | ||
284 | { | ||
285 | /* on even rounds, try UNIX */ | ||
286 | if (GNUNET_OK == | ||
287 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
288 | service_name, | ||
289 | "UNIXPATH", &unixpath)) | ||
290 | { | ||
291 | sock = GNUNET_CONNECTION_create_from_connect_to_unixpath (sched, | ||
292 | cfg, | ||
293 | unixpath, | ||
294 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
295 | GNUNET_free (unixpath); | ||
296 | if (sock != NULL) | ||
297 | return sock; | ||
298 | } | ||
299 | } | ||
300 | #endif | ||
301 | |||
266 | if ((GNUNET_OK != | 302 | if ((GNUNET_OK != |
267 | GNUNET_CONFIGURATION_get_value_number (cfg, | 303 | GNUNET_CONFIGURATION_get_value_number (cfg, |
268 | service_name, | 304 | service_name, |
@@ -314,10 +350,13 @@ GNUNET_CLIENT_connect (struct GNUNET_SCHEDULER_Handle *sched, | |||
314 | struct GNUNET_CLIENT_Connection *ret; | 350 | struct GNUNET_CLIENT_Connection *ret; |
315 | struct GNUNET_CONNECTION_Handle *sock; | 351 | struct GNUNET_CONNECTION_Handle *sock; |
316 | 352 | ||
317 | sock = do_connect (sched, service_name, cfg); | 353 | sock = do_connect (sched, |
354 | service_name, | ||
355 | cfg, 0); | ||
318 | if (sock == NULL) | 356 | if (sock == NULL) |
319 | return NULL; | 357 | return NULL; |
320 | ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection)); | 358 | ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection)); |
359 | ret->attempts = 1; | ||
321 | ret->sock = sock; | 360 | ret->sock = sock; |
322 | ret->sched = sched; | 361 | ret->sched = sched; |
323 | ret->service_name = GNUNET_strdup (service_name); | 362 | ret->service_name = GNUNET_strdup (service_name); |
@@ -770,7 +809,9 @@ client_notify (void *cls, size_t size, void *buf) | |||
770 | /* auto-retry */ | 809 | /* auto-retry */ |
771 | GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); | 810 | GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO); |
772 | th->sock->sock = do_connect (th->sock->sched, | 811 | th->sock->sock = do_connect (th->sock->sched, |
773 | th->sock->service_name, th->sock->cfg); | 812 | th->sock->service_name, |
813 | th->sock->cfg, | ||
814 | th->sock->attempts++); | ||
774 | GNUNET_assert (NULL != th->sock->sock); | 815 | GNUNET_assert (NULL != th->sock->sock); |
775 | GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, | 816 | GNUNET_CONNECTION_ignore_shutdown (th->sock->sock, |
776 | th->sock->ignore_shutdown); | 817 | th->sock->ignore_shutdown); |