/* delete this in case non-blocking connect was used */
event_del(&bev->ev_write);
if (bev_p->options & BEV_OPT_CLOSE_ON_FREE)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
_bufferevent_del_generic_timeout_cbs(bev);
}
freesock:
_bufferevent_run_eventcb(bev, BEV_EVENT_ERROR);
if (ownfd)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
/* do something about the error? */
done:
_bufferevent_decref_and_unlock(bev);
EVLOCK_ASSERT_LOCKED((base)->lock)
#endif
-#define CLOSE_SOCKET(s) EVUTIL_CLOSESOCKET(s)
-
static const char *
debug_ntoa(u32 address)
{
EVUTIL_ASSERT(!port->refcnt);
EVUTIL_ASSERT(!port->pending_replies);
if (port->socket > 0) {
- CLOSE_SOCKET(port->socket);
+ evutil_closesocket(port->socket);
port->socket = -1;
}
(void) event_del(&port->event);
if (evtimer_initialized(&server->timeout_event))
(void) evtimer_del(&server->timeout_event);
if (server->socket >= 0)
- CLOSE_SOCKET(server->socket);
+ evutil_closesocket(server->socket);
mm_free(server);
if (next == started_at)
break;
return 0;
out2:
- CLOSE_SOCKET(ns->socket);
+ evutil_closesocket(ns->socket);
out1:
event_debug_unassign(&ns->event);
mm_free(ns);
evdns_nameserver_free(struct nameserver *server)
{
if (server->socket >= 0)
- CLOSE_SOCKET(server->socket);
+ evutil_closesocket(server->socket);
(void) event_del(&server->event);
event_debug_unassign(&server->event);
if (server->state == 0)
goto tidy_up_and_fail;
if (size != sizeof(listen_addr))
goto abort_tidy_up_and_fail;
- EVUTIL_CLOSESOCKET(listener);
+ evutil_closesocket(listener);
/* Now check we are talking to ourself by matching port and host on the
two sockets. */
if (getsockname(connector, (struct sockaddr *) &connect_addr, &size) == -1)
if (saved_errno < 0)
saved_errno = WSAGetLastError();
if (listener != -1)
- EVUTIL_CLOSESOCKET(listener);
+ evutil_closesocket(listener);
if (connector != -1)
- EVUTIL_CLOSESOCKET(connector);
+ evutil_closesocket(connector);
if (acceptor != -1)
- EVUTIL_CLOSESOCKET(acceptor);
+ evutil_closesocket(acceptor);
EVUTIL_SET_SOCKET_ERROR(saved_errno);
return -1;
return 0;
}
+int
+evutil_closesocket(evutil_socket_t sock)
+{
+#ifndef WIN32
+ return close(sock);
+#else
+ return closesocket(sock);
+#endif
+}
+
ev_int64_t
evutil_strtoll(const char *s, char **endptr, int base)
{
err:
if (made_fd) {
- EVUTIL_CLOSESOCKET(*fd_ptr);
+ evutil_closesocket(*fd_ptr);
*fd_ptr = -1;
}
return -1;
}
}
if (fd >= 0)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
if ((fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) >= 0 &&
connect(fd, (struct sockaddr*)&sin6, sizeof(sin6)) == 0 &&
}
if (fd >= 0)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return 0;
}
bufferevent_free(evcon->bufev);
if (evcon->fd != -1)
- EVUTIL_CLOSESOCKET(evcon->fd);
+ evutil_closesocket(evcon->fd);
if (evcon->bind_address != NULL)
mm_free(evcon->bind_address);
if (evhttp_connected(evcon) && evcon->closecb != NULL)
(*evcon->closecb)(evcon, evcon->closecb_arg);
- EVUTIL_CLOSESOCKET(evcon->fd);
+ evutil_closesocket(evcon->fd);
evcon->fd = -1;
}
if (listen(fd, 128) == -1) {
event_sock_warn(fd, "%s: listen", __func__);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return (NULL);
}
evcon = evhttp_get_request_connection(http, fd, sa, salen);
if (evcon == NULL) {
event_sock_warn(fd, "%s: cannot get connection on %d", __func__, fd);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return;
}
out:
serrno = EVUTIL_SOCKET_ERROR();
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
EVUTIL_SET_SOCKET_ERROR(serrno);
return (-1);
}
*/
int evutil_make_socket_closeonexec(evutil_socket_t sock);
-#ifdef WIN32
-/** Do the platform-specific call needed to close a socket returned from
- socket() or accept(). */
-#define EVUTIL_CLOSESOCKET(s) closesocket(s)
-#else
/** Do the platform-specific call needed to close a socket returned from
- socket() or accept(). */
-#define EVUTIL_CLOSESOCKET(s) close(s)
-#endif
+ socket() or accept().
+
+ @param sock The socket to be closed
+ @return 0 on success, -1 on failure
+ */
+int evutil_closesocket(evutil_socket_t sock);
+#define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s)
/* Winsock handles socket errors differently from the rest of the world.
* Elsewhere, a socket error is like any other error and is stored in errno.
return NULL;
if (evutil_make_socket_nonblocking(fd) < 0) {
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return NULL;
}
if (flags & LEV_OPT_CLOSE_ON_EXEC) {
if (evutil_make_socket_closeonexec(fd) < 0) {
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return NULL;
}
}
if (sa) {
if (bind(fd, sa, socklen)<0) {
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return NULL;
}
}
listener = evconnlistener_new(base, cb, ptr, flags, backlog, fd);
if (!listener) {
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return NULL;
}
event_del(&lev_e->listener);
if (lev->flags & LEV_OPT_CLOSE_ON_FREE)
- EVUTIL_CLOSESOCKET(event_get_fd(&lev_e->listener));
+ evutil_closesocket(event_get_fd(&lev_e->listener));
event_debug_unassign(&lev_e->listener);
}
}
if (base->sig.ev_signal_pair[0] != -1) {
- EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]);
+ evutil_closesocket(base->sig.ev_signal_pair[0]);
base->sig.ev_signal_pair[0] = -1;
}
if (base->sig.ev_signal_pair[1] != -1) {
- EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]);
+ evutil_closesocket(base->sig.ev_signal_pair[1]);
base->sig.ev_signal_pair[1] = -1;
}
base->sig.sh_old_max = 0;
if (ev[i])
event_free(ev[i]);
if (sock[i] >= 0)
- EVUTIL_CLOSESOCKET(sock[i]);
+ evutil_closesocket(sock[i]);
}
#undef MANY
}
evbuffer_validate(src);
end:
- EVUTIL_CLOSESOCKET(pair[0]);
- EVUTIL_CLOSESOCKET(pair[1]);
+ evutil_closesocket(pair[0]);
+ evutil_closesocket(pair[1]);
evbuffer_free(src);
}
#endif
{
evutil_socket_t *fdp = arg;
if (*fdp >= 0) {
- EVUTIL_CLOSESOCKET(*fdp);
+ evutil_closesocket(*fdp);
*fdp = -1;
}
}
end:
if (fake_listener >= 0)
- EVUTIL_CLOSESOCKET(fake_listener);
+ evutil_closesocket(fake_listener);
if (bev)
bufferevent_free(bev);
if (port)
evdns_close_server_port(port);
if (sock >= 0)
- EVUTIL_CLOSESOCKET(sock);
+ evutil_closesocket(sock);
if (base)
evdns_base_free(base, 0);
}
if (listener)
evconnlistener_free(listener);
if (server_fd>=0)
- EVUTIL_CLOSESOCKET(server_fd);
+ evutil_closesocket(server_fd);
if (port)
evdns_close_server_port(port);
if (dns)
}
if (base)
event_base_free(base);
- EVUTIL_CLOSESOCKET(pair[0]);
- EVUTIL_CLOSESOCKET(pair[1]);
+ evutil_closesocket(pair[0]);
+ evutil_closesocket(pair[1]);
}
struct testcase_t edgetriggered_testcases[] = {
/* connect to the second port */
bufferevent_free(bev);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
fd = http_connect("127.0.0.1", port + 1);
event_dispatch();
bufferevent_free(bev);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
evhttp_free(http);
event_dispatch();
bufferevent_free(bev);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
if (test_ok != 0) {
fprintf(stdout, "FAILED\n");
event_dispatch();
bufferevent_free(bev);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
evhttp_free(http);
event_dispatch();
bufferevent_free(bev);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
evhttp_free(http);
event_base_dispatch(base);
bufferevent_free(bev);
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
evhttp_free(http);
bufferevent_free(bev);
if (use_timeout) {
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
}
evhttp_free(http);
if (bev)
bufferevent_free(bev);
if (fd >= 0)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
if (http)
evhttp_free(http);
}
{
struct terminate_state *state = arg;
bufferevent_free(state->bev);
- EVUTIL_CLOSESOCKET(state->fd);
+ evutil_closesocket(state->fd);
}
static void
end:
if (fd >= 0)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
if (http)
evhttp_free(http);
}
int *ptr = arg;
--*ptr;
TT_BLATHER(("Got one for %p", ptr));
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
if (! *ptr)
evconnlistener_disable(listener);
if (testcase->flags & TT_NEED_SOCKETPAIR) {
if (data->pair[0] != -1)
- EVUTIL_CLOSESOCKET(data->pair[0]);
+ evutil_closesocket(data->pair[0]);
if (data->pair[1] != -1)
- EVUTIL_CLOSESOCKET(data->pair[1]);
+ evutil_closesocket(data->pair[1]);
}
if (testcase->flags & TT_NEED_DNS) {
if (dns_port)
evdns_close_server_port(dns_port);
if (dns_sock >= 0)
- EVUTIL_CLOSESOCKET(dns_sock);
+ evutil_closesocket(dns_sock);
}
void
if (logmsg)
free(logmsg);
if (fd >= 0)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
}
static void
bufferevent_free(bev2);
if (pair[0] >= 0)
- EVUTIL_CLOSESOCKET(pair[0]);
+ evutil_closesocket(pair[0]);
if (pair[1] >= 0)
- EVUTIL_CLOSESOCKET(pair[1]);
+ evutil_closesocket(pair[1]);
}
if (len > 0) {
if (!called)
event_add(arg, NULL);
- EVUTIL_CLOSESOCKET(pair[0]);
+ evutil_closesocket(pair[0]);
} else if (called == 1)
test_okay = 0;