diff options
author | Martin Willi <martin@revosec.ch> | 2013-11-21 16:27:21 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 15:53:04 +0200 |
commit | efcf249aebe395e196237e87bd34232f84559112 (patch) | |
tree | 6c49cd1da946b51c3eee318e9bcfc15ea5735e99 /src | |
parent | 740404d48193dece09047608c7d8362c5a7536e8 (diff) | |
download | strongswan-efcf249aebe395e196237e87bd34232f84559112.tar.bz2 strongswan-efcf249aebe395e196237e87bd34232f84559112.tar.xz |
windows: Provide a close(2) that can close both file handles and sockets
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/utils/windows.c | 16 | ||||
-rw-r--r-- | src/libstrongswan/utils/windows.h | 6 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c index 48a70b6c2..492821d53 100644 --- a/src/libstrongswan/utils/windows.c +++ b/src/libstrongswan/utils/windows.c @@ -334,6 +334,22 @@ static bool check_dontwait(int *flags) /** * See header */ +#undef close +int windows_close(int fd) +{ + int ret; + + ret = close(fd); + if (ret == -1 && errno == EBADF) + { /* Winsock socket? */ + ret = wserr(closesocket(fd)); + } + return ret; +} + +/** + * See header + */ #undef recv ssize_t windows_recv(int sockfd, void *buf, size_t len, int flags) { diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index d57b5dc1d..3e317ce59 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -265,6 +265,12 @@ int socketpair(int domain, int type, int protocol, int sv[2]); #define ECONNRESET ENXIO /** + * close(2) working for file handles and Winsock sockets + */ +#define close windows_close +int windows_close(int fd); + +/** * recv(2) with support for MSG_DONTWAIT */ #define recv windows_recv |