diff options
author | Martin Lucina <mato@kotelna.sk> | 2011-10-03 17:09:06 +0200 |
---|---|---|
committer | Martin Lucina <martin@lucina.net> | 2012-01-23 08:54:33 +0100 |
commit | c3363afa881b46f3df8a6b72ed15cfbac18f4713 (patch) | |
tree | 832e8075a038b49f81e8a7635344f1647007fd15 /src/ip.cpp | |
parent | 88f712b4a31c95caef4f34c4ec65793c392314a6 (diff) | |
parent | 978e33ba253a997b41b331b449b474a5cee7bccc (diff) |
Imported Debian patch 2.1.10-1debian/2.1.10-1
Diffstat (limited to 'src/ip.cpp')
-rw-r--r-- | src/ip.cpp | 50 |
1 files changed, 40 insertions, 10 deletions
@@ -18,23 +18,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "ip.hpp" +#include "err.hpp" +#include "platform.hpp" +#include "stdint.hpp" #include <stdlib.h> #include <string.h> #include <stdlib.h> #include <string> -#include "../include/zmq.h" +#if defined ZMQ_HAVE_WINDOWS +#include "windows.hpp" +#else +#include <fcntl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <unistd.h> +#endif -#include "ip.hpp" -#include "platform.hpp" -#include "err.hpp" -#include "stdint.hpp" +#if defined ZMQ_HAVE_OPENVMS +#include <ioctl.h> +#endif #if defined ZMQ_HAVE_SOLARIS - #include <sys/sockio.h> #include <net/if.h> -#include <unistd.h> // On Solaris platform, network interface name can be queried by ioctl. static int resolve_nic_name (in_addr* addr_, char const *interface_) @@ -93,9 +103,6 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_) } #elif defined ZMQ_HAVE_AIX || ZMQ_HAVE_HPUX || ZMQ_HAVE_ANDROID - -#include <sys/types.h> -#include <unistd.h> #include <sys/ioctl.h> #include <net/if.h> @@ -177,6 +184,29 @@ static int resolve_nic_name (in_addr* addr_, char const *interface_) #endif +int zmq::open_socket (int domain_, int type_, int protocol_) +{ + // Setting this option result in sane behaviour when exec() functions + // are used. Old sockets are closed and don't block TCP ports etc. +#if defined SOCK_CLOEXEC + type_ |= SOCK_CLOEXEC; +#endif + + int s = socket (domain_, type_, protocol_); + if (s == -1) + return -1; + + // If there's no SOCK_CLOEXEC, let's try the second best option. Note that + // race condition can cause socket not to be closed (if fork happens + // between socket creation and this point). +#if !defined SOCK_CLOEXEC && defined FD_CLOEXEC + int rc = fcntl (s, F_SETFD, FD_CLOEXEC); + errno_assert (rc != -1); +#endif + + return s; +} + int zmq::resolve_ip_interface (sockaddr_storage* addr_, socklen_t *addr_len_, char const *interface_) { |