From: Christian Grothoff Date: Sat, 2 Mar 2019 10:17:27 +0000 (+0100) Subject: cache PF support results from OS probe (#5553) X-Git-Tag: v0.11.1~203 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=54d83ad059519ca03971b79b8410540d9438b5a8;p=oweals%2Fgnunet.git cache PF support results from OS probe (#5553) --- diff --git a/src/util/network.c b/src/util/network.c index c236292b7..90f8c8640 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -83,24 +83,64 @@ struct GNUNET_NETWORK_Handle int GNUNET_NETWORK_test_pf (int pf) { + static int cache_v4 = -1; + static int cache_v6 = -1; + static int cache_un = -1; int s; + int ret; + switch (pf) + { + case PF_INET: + if (-1 != cache_v4) + return cache_v4; + break; + case PF_INET6: + if (-1 != cache_v6) + return cache_v6; + break; +#ifdef PF_UNIX + case PF_UNIX: + if (-1 != cache_un) + return cache_un; + break; +#endif + } s = socket (pf, SOCK_STREAM, 0); if (-1 == s) { - if (EAFNOSUPPORT == errno) - return GNUNET_NO; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to create test socket: %s\n", - STRERROR (errno)); - return GNUNET_SYSERR; + if (EAFNOSUPPORT != errno) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, + "socket"); + return GNUNET_SYSERR; + } + ret = GNUNET_NO; } + else + { #if WINDOWS - closesocket (s); + closesocket (s); #else - close (s); + close (s); #endif - return GNUNET_OK; + ret = GNUNET_OK; + } + switch (pf) + { + case PF_INET: + cache_v4 = ret; + break; + case PF_INET6: + cache_v6 = ret; + break; +#ifdef PF_UNIX + case PF_UNIX: + cache_un = ret; + break; +#endif + } + return ret; }