88#include < sys/sockio.h>
99#endif
1010
11+ #if defined(WIN32)
12+ #define SOCK_CLOEXEC 0
13+ #endif
14+
1115#include " resip/stack/Helper.hxx"
1216#include " resip/stack/InternalTransport.hxx"
1317#include " resip/stack/SipMessage.hxx"
@@ -76,17 +80,17 @@ InternalTransport::socket(TransportType type, IpVersion ipVer)
7680 {
7781 case UDP:
7882#ifdef USE_IPV6
79- fd = ::socket (ipVer == V4 ? PF_INET : PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
83+ fd = ::socket (ipVer == V4 ? PF_INET : PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC , IPPROTO_UDP);
8084#else
81- fd = ::socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
85+ fd = ::socket (PF_INET, SOCK_DGRAM | SOCK_CLOEXEC , IPPROTO_UDP);
8286#endif
8387 break ;
8488 case TCP:
8589 case TLS:
8690#ifdef USE_IPV6
87- fd = ::socket (ipVer == V4 ? PF_INET : PF_INET6, SOCK_STREAM, 0 );
91+ fd = ::socket (ipVer == V4 ? PF_INET : PF_INET6, SOCK_STREAM | SOCK_CLOEXEC , 0 );
8892#else
89- fd = ::socket (PF_INET, SOCK_STREAM, 0 );
93+ fd = ::socket (PF_INET, SOCK_STREAM | SOCK_CLOEXEC , 0 );
9094#endif
9195 break ;
9296 default :
@@ -101,6 +105,14 @@ InternalTransport::socket(TransportType type, IpVersion ipVer)
101105 ErrLog (<< " Failed to create socket: " << strerror (e));
102106 throw Transport::Exception (" Can't create TcpBaseTransport" , __FILE__,__LINE__);
103107 }
108+ #if defined(WIN32)
109+ if (!SetHandleInformation ((HANDLE)fd, HANDLE_FLAG_INHERIT, 0 ))
110+ {
111+ int e = getErrno ();
112+ ErrLog (<< " Failed to set handle information: " << strerror (e));
113+ throw Transport::Exception (" Failed SetHandleInformation" , __FILE__, __LINE__);
114+ }
115+ #endif
104116
105117#ifdef USE_IPV6
106118#ifdef __linux__
0 commit comments