listen: use GLib instead of utils.h

This commit is contained in:
Max Kellermann 2009-01-03 14:51:43 +01:00
parent 30f75f7f01
commit 8ebb3196a8
3 changed files with 21 additions and 20 deletions

View File

@ -26,6 +26,9 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#ifdef WIN32
#include <ws2tcpip.h>
@ -89,8 +92,8 @@ static int establishListen(int pf, const struct sockaddr *addrp,
#endif
numberOfListenSockets++;
listenSockets =
xrealloc(listenSockets, sizeof(int) * numberOfListenSockets);
listenSockets = g_realloc(listenSockets, sizeof(listenSockets[0]) *
numberOfListenSockets);
listenSockets[numberOfListenSockets - 1] = sock;
@ -102,6 +105,20 @@ static int establishListen(int pf, const struct sockaddr *addrp,
return 0;
}
static bool ipv6Supported(void)
{
#ifdef HAVE_IPV6
int s;
s = socket(AF_INET6, SOCK_STREAM, 0);
if (s == -1)
return false;
close(s);
return true;
#else
return false;
#endif
}
static void
parseListenConfigParam(G_GNUC_UNUSED unsigned int port, ConfigParam * param)
{
@ -190,7 +207,7 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port, ConfigParam * param)
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
snprintf(service, sizeof(service), "%u", port);
g_snprintf(service, sizeof(service), "%u", port);
ret = getaddrinfo(param->value, service, &hints, &ai);
if (ret != 0)
@ -262,7 +279,7 @@ void closeAllListenSockets(void)
}
numberOfListenSockets = 0;
free(listenSockets);
g_free(listenSockets);
listenSockets = NULL;
}

View File

@ -61,20 +61,6 @@ void my_usleep(long usec)
#endif
}
int ipv6Supported(void)
{
#ifdef HAVE_IPV6
int s;
s = socket(AF_INET6, SOCK_STREAM, 0);
if (s == -1)
return 0;
close(s);
return 1;
#else
return 0;
#endif
}
G_GNUC_MALLOC char *xstrdup(const char *s)
{
char *ret = strdup(s);

View File

@ -40,8 +40,6 @@ void stripReturnChar(char *string);
void my_usleep(long usec);
int ipv6Supported(void);
/* trivial functions, keep them inlined */
static inline void xclose(int fd)
{