From 90f091abf3be398641446cc6d7c6656d8100f877 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Mon, 14 Nov 2016 11:59:32 +0000 Subject: [PATCH] Problem: IPV6_TCLASS setsockopt fails on IPv4 socket Solution: if setsockopt errors out and errno is set to ENOPROTOOPT (or EINVAL on OSX) ignore it and carry on. --- src/ip.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ip.cpp b/src/ip.cpp index 81607656..7a8d12c4 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -180,9 +180,17 @@ void zmq::set_ip_type_of_service (fd_t s_, int iptos) reinterpret_cast(&iptos), sizeof(iptos)); + // If IPv6 is not enabled ENOPROTOOPT will be returned on Windows and + // Linux, and EINVAL on OSX #ifdef ZMQ_HAVE_WINDOWS - wsa_assert (rc != SOCKET_ERROR); + if (rc == SOCKET_ERROR) { + const int last_error = WSAGetLastError(); + wsa_assert (last_error == WSAENOPROTOOPT); + } #else - errno_assert (rc == 0); + if (rc == -1) { + errno_assert (errno == ENOPROTOOPT || + errno == EINVAL); + } #endif }