X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_prometheus.c;h=8554580f24e53141b4b27afc8327359a3eb4fb18;hb=2700666217249cd4794dfc17b4ac3b28f3dca56b;hp=9e9ed2e8a93af9238a9314dbf374da35004c0193;hpb=196f5bd17880d91ba0da33a8f5f6168d039cfa0c;p=collectd.git diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 9e9ed2e8..8554580f 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -760,10 +760,25 @@ static int prom_open_socket(int addrfamily) { int fd = -1; for (struct addrinfo *ai = res; ai != NULL; ai = ai->ai_next) { - fd = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC, 0); + int flags = ai->ai_socktype; +#ifdef SOCK_CLOEXEC + flags |= SOCK_CLOEXEC; +#endif + + fd = socket(ai->ai_family, flags, 0); if (fd == -1) continue; + int tmp = 1; + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp)) != 0) { + char errbuf[1024]; + WARNING("write_prometheus: setsockopt(SO_REUSEADDR) failed: %s", + sstrerror(errno, errbuf, sizeof(errbuf))); + close(fd); + fd = -1; + continue; + } + if (bind(fd, ai->ai_addr, ai->ai_addrlen) != 0) { close(fd); fd = -1; @@ -794,8 +809,13 @@ static struct MHD_Daemon *prom_start_daemon() { return NULL; } + unsigned int flags = MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG; +#if MHD_VERSION >= 0x00095300 + flags |= MHD_USE_INTERNAL_POLLING_THREAD; +#endif + struct MHD_Daemon *d = MHD_start_daemon( - MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, httpd_port, + flags, httpd_port, /* MHD_AcceptPolicyCallback = */ NULL, /* MHD_AcceptPolicyCallback arg = */ NULL, http_handler, NULL, MHD_OPTION_LISTEN_SOCKET, fd, MHD_OPTION_EXTERNAL_LOGGER, prom_logger,