summaryrefslogtreecommitdiff
path: root/evutil.c
diff options
context:
space:
mode:
authorSebastian Sjöberg <Sebastian.Sjoberg@axis.com>2010-04-14 15:42:57 -0400
committerSebastian Sjöberg <Sebastian.Sjoberg@axis.com>2010-04-14 15:42:57 -0400
commit899c1dcc9807650ec90e0d5c847d2997fce9b751 (patch)
tree3d8a5d5eecaa8e29a17471981ad1b7f8122dd900 /evutil.c
parent0861d1708ba6d035ff4c834e2aac0b5855f64afa (diff)
downloadlibevent-899c1dcc9807650ec90e0d5c847d2997fce9b751.tar.gz
Replace EVUTIL_CLOSESOCKET macro with a function
The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your source for POSIX. We might as well turn it into a function: an extra function call is going to be cheap in comparison with the system call. We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new evutil_closesocket() function. (commit message from email by Nick and Sebastian)
Diffstat (limited to 'evutil.c')
-rw-r--r--evutil.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/evutil.c b/evutil.c
index b75a4697..2509f175 100644
--- a/evutil.c
+++ b/evutil.c
@@ -207,7 +207,7 @@ evutil_socketpair(int family, int type, int protocol, evutil_socket_t fd[2])
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)
@@ -228,11 +228,11 @@ evutil_socketpair(int family, int type, int protocol, evutil_socket_t fd[2])
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;
@@ -295,6 +295,16 @@ evutil_make_socket_closeonexec(evutil_socket_t fd)
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)
{
@@ -394,7 +404,7 @@ evutil_socket_connect(evutil_socket_t *fd_ptr, struct sockaddr *sa, int socklen)
err:
if (made_fd) {
- EVUTIL_CLOSESOCKET(*fd_ptr);
+ evutil_closesocket(*fd_ptr);
*fd_ptr = -1;
}
return -1;
@@ -497,7 +507,7 @@ evutil_check_interfaces(int force_recheck)
}
}
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 &&
@@ -521,7 +531,7 @@ evutil_check_interfaces(int force_recheck)
}
if (fd >= 0)
- EVUTIL_CLOSESOCKET(fd);
+ evutil_closesocket(fd);
return 0;
}