rewrite socket to rk_socket of there is SOCK_CLOEXEC and there is linux, prompted by Harald Barth

This commit is contained in:
Love Hornquist Astrand
2010-01-25 23:01:18 -08:00
parent deee0bbad9
commit 2fbdb6a514
2 changed files with 25 additions and 0 deletions

View File

@@ -1033,6 +1033,11 @@ void
rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
#endif
#if defined(__LINUX__) && SOCK_CLOEXEC && !defined(SOCKET_WRAPPER_REPLACE)
#undef socket
#define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
#endif
#ifdef SOCKET_WRAPPER_REPLACE
#include <socket_wrapper.h>
#endif

View File

@@ -315,3 +315,23 @@ socket_to_fd(rk_socket_t sock, int flags)
return _open_osfhandle((intptr_t) sock, flags);
#endif
}
#ifndef HEIMAL_SMALLER
int rk_socket(int, int, int);
int
rk_socket(int domain, int type, int protocol)
{
int s;
s = socket (domain, type, protocol);
#ifdef SOCK_CLOEXEC
if ((SOCK_CLOEXEC & protocol) && s < 0 && errno == EINVAL) {
protocol &= ~SOCK_CLOEXEC;
s = socket (domain, type, protocol);
}
#endif
return s;
}
#endif