samples: use evutil_socket_t instead and handle 64 bit Windows (#1682)

* Use evutil_socket_t instead in http server sample and handle 64 bit Windows

* Update http-server.c

* consistently using EV_SOCK_FMT for Windows compatibility

* code review: fix missing symbol strsignal

* Add evutil_strsignal() helper instead of strsignal() macro

---------

Co-authored-by: Hernan Martinez <hernan.c.martinez@gmail.com>
Co-authored-by: Azat Khuzhin <azat@libevent.org>
This commit is contained in:
Cœur 2024-07-08 10:10:42 +02:00 committed by GitHub
parent 2bc831c889
commit 49d6b4b099
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 15 deletions

View File

@ -3313,3 +3313,14 @@ evutil_set_tcp_keepalive(evutil_socket_t fd, int on, int timeout)
return 0;
}
const char * evutil_strsignal(int sig)
{
#if !defined(EVENT__HAVE_STRSIGNAL)
static char buf[10];
evutil_snprintf(buf, 10, "%d", sig);
return buf;
#else
return strsignal(sig);
#endif
}

View File

@ -348,15 +348,12 @@ static struct options parse_opts(int argc, char **argv)
return o;
}
#ifndef EVENT__HAVE_STRSIGNAL
static inline const char* strsignal(evutil_socket_t sig) { return "Signal"; }
#endif
static void do_term(evutil_socket_t sig, short events, void *arg)
{
struct event_base *base = arg;
event_base_loopexit(base, NULL);
fprintf(stderr, "%s(" EV_SOCK_FMT "), Terminating\n",
strsignal(sig), EV_SOCK_ARG(sig));
fprintf(stderr, "%s signal received. Terminating\n",
evutil_strsignal(EV_SOCK_ARG(sig)));
}
static ev_socklen_t

View File

@ -396,7 +396,8 @@ do_term(evutil_socket_t sig, short events, void *arg)
{
struct event_base *base = arg;
event_base_loopbreak(base);
fprintf(stderr, "Got %i, Terminating\n", sig);
fprintf(stderr, "%s signal received. Terminating\n",
evutil_strsignal(EV_SOCK_ARG(sig)));
}
static int

View File

@ -3,6 +3,7 @@
#include <event2/event.h>
#include <event2/http.h>
#include <event2/ws.h>
#include "../util-internal.h"
#include <fcntl.h>
#include <signal.h>
@ -206,18 +207,10 @@ err:
close(fd);
}
#ifndef EVENT__HAVE_STRSIGNAL
static inline const char *
strsignal(evutil_socket_t sig)
{
return "Signal";
}
#endif
static void
signal_cb(evutil_socket_t fd, short event, void *arg)
{
printf("%s signal received\n", strsignal(fd));
printf("%s signal received. Terminating\n", evutil_strsignal(EV_SOCK_ARG(fd)));
event_base_loopbreak(arg);
}

View File

@ -520,6 +520,11 @@ HMODULE evutil_load_windows_system_library_(const TCHAR *library_name);
#endif
#endif
/* Either a mapping for strsignal() or snprintf("%d", sig)
* NOTE: MT-Unsafe*/
EVENT2_EXPORT_SYMBOL
const char * evutil_strsignal(int sig);
EVENT2_EXPORT_SYMBOL
evutil_socket_t evutil_socket_(int domain, int type, int protocol);
evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr,