mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
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:
parent
2bc831c889
commit
49d6b4b099
11
evutil.c
11
evutil.c
@ -3313,3 +3313,14 @@ evutil_set_tcp_keepalive(evutil_socket_t fd, int on, int timeout)
|
|||||||
|
|
||||||
return 0;
|
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
|
||||||
|
}
|
||||||
|
@ -348,15 +348,12 @@ static struct options parse_opts(int argc, char **argv)
|
|||||||
return o;
|
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)
|
static void do_term(evutil_socket_t sig, short events, void *arg)
|
||||||
{
|
{
|
||||||
struct event_base *base = arg;
|
struct event_base *base = arg;
|
||||||
event_base_loopexit(base, NULL);
|
event_base_loopexit(base, NULL);
|
||||||
fprintf(stderr, "%s(" EV_SOCK_FMT "), Terminating\n",
|
fprintf(stderr, "%s signal received. Terminating\n",
|
||||||
strsignal(sig), EV_SOCK_ARG(sig));
|
evutil_strsignal(EV_SOCK_ARG(sig)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ev_socklen_t
|
static ev_socklen_t
|
||||||
|
@ -396,7 +396,8 @@ do_term(evutil_socket_t sig, short events, void *arg)
|
|||||||
{
|
{
|
||||||
struct event_base *base = arg;
|
struct event_base *base = arg;
|
||||||
event_base_loopbreak(base);
|
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
|
static int
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#include <event2/ws.h>
|
#include <event2/ws.h>
|
||||||
|
#include "../util-internal.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -206,18 +207,10 @@ err:
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef EVENT__HAVE_STRSIGNAL
|
|
||||||
static inline const char *
|
|
||||||
strsignal(evutil_socket_t sig)
|
|
||||||
{
|
|
||||||
return "Signal";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
signal_cb(evutil_socket_t fd, short event, void *arg)
|
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);
|
event_base_loopbreak(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,6 +520,11 @@ HMODULE evutil_load_windows_system_library_(const TCHAR *library_name);
|
|||||||
#endif
|
#endif
|
||||||
#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
|
EVENT2_EXPORT_SYMBOL
|
||||||
evutil_socket_t evutil_socket_(int domain, int type, int protocol);
|
evutil_socket_t evutil_socket_(int domain, int type, int protocol);
|
||||||
evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr,
|
evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user