mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 13:04:23 -04:00
test-fdleak: Avoid perror, since it does not capture windows socket errors
This commit is contained in:
parent
510839e7db
commit
d7d9f75528
@ -57,6 +57,13 @@ static int num_requests;
|
|||||||
|
|
||||||
static void start_client(struct event_base *base);
|
static void start_client(struct event_base *base);
|
||||||
|
|
||||||
|
static void
|
||||||
|
my_perror(const char *s)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: %s",
|
||||||
|
s, evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===============================================
|
===============================================
|
||||||
Server functions
|
Server functions
|
||||||
@ -79,8 +86,7 @@ static void
|
|||||||
server_event_cb(struct bufferevent *bev, short events, void *ctx)
|
server_event_cb(struct bufferevent *bev, short events, void *ctx)
|
||||||
{
|
{
|
||||||
if (events & BEV_EVENT_ERROR) {
|
if (events & BEV_EVENT_ERROR) {
|
||||||
/* XXX won't capture net errors on windows */
|
my_perror("Error from bufferevent");
|
||||||
perror("Error from bufferevent");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
} else if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
} else if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
@ -120,8 +126,7 @@ start_loop(void)
|
|||||||
LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE,
|
LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE,
|
||||||
-1, (struct sockaddr *)&sin, sizeof(sin));
|
-1, (struct sockaddr *)&sin, sizeof(sin));
|
||||||
if (listener == NULL) {
|
if (listener == NULL) {
|
||||||
/* XXX won't capture net errors on windows */
|
my_perror("Could not create listener!");
|
||||||
perror("Could not create listener!");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fd = evconnlistener_get_fd(listener);
|
fd = evconnlistener_get_fd(listener);
|
||||||
@ -130,8 +135,7 @@ start_loop(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (getsockname(fd, (struct sockaddr *)&ss, &socklen) < 0) {
|
if (getsockname(fd, (struct sockaddr *)&ss, &socklen) < 0) {
|
||||||
printf("getsockname(): %s",
|
my_perror("getsockname()");
|
||||||
evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
memcpy(&sin, &ss, sizeof(sin));
|
memcpy(&sin, &ss, sizeof(sin));
|
||||||
@ -199,8 +203,7 @@ start_client(struct event_base *base)
|
|||||||
|
|
||||||
if (bufferevent_socket_connect(bev, (struct sockaddr *)&sin,
|
if (bufferevent_socket_connect(bev, (struct sockaddr *)&sin,
|
||||||
sizeof(sin)) < 0) {
|
sizeof(sin)) < 0) {
|
||||||
/* XXX won't capture net errors on windows */
|
my_perror("Could not connect!");
|
||||||
perror("Could not connect!");
|
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
@ -215,7 +218,7 @@ main(int argc, char **argv)
|
|||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
rl.rlim_cur = rl.rlim_max = 20;
|
rl.rlim_cur = rl.rlim_max = 20;
|
||||||
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
|
if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {
|
||||||
perror("setrlimit");
|
my_perror("setrlimit");
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user