summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ip.cpp24
-rw-r--r--src/ip.hpp7
-rw-r--r--src/tcp_connecter.cpp22
-rw-r--r--src/tcp_listener.cpp21
-rw-r--r--src/vtcp_connecter.cpp4
-rw-r--r--src/vtcp_listener.cpp3
6 files changed, 40 insertions, 41 deletions
diff --git a/src/ip.cpp b/src/ip.cpp
index a4f9562..e643663 100644
--- a/src/ip.cpp
+++ b/src/ip.cpp
@@ -344,3 +344,27 @@ int zmq::resolve_local_path (sockaddr_storage *addr_, socklen_t *addr_len_,
#endif
}
+void zmq::tune_tcp_socket (fd_t s_)
+{
+ // Disable Nagle's algorithm. We are doing data batching on 0MQ level,
+ // so using Nagle wouldn't improve throughput in anyway, but it would
+ // hurt latency.
+ int nodelay = 1;
+ int rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
+ sizeof (int));
+#ifdef ZMQ_HAVE_WINDOWS
+ wsa_assert (rc != SOCKET_ERROR);
+#else
+ errno_assert (rc == 0);
+#endif
+
+#ifdef ZMQ_HAVE_OPENVMS
+ // Disable delayed acknowledgements as they hurt latency is serious manner.
+ int nodelack = 1;
+ rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
+ sizeof (int));
+ errno_assert (rc != SOCKET_ERROR);
+#endif
+}
+
+
diff --git a/src/ip.hpp b/src/ip.hpp
index ec2db43..8a690b0 100644
--- a/src/ip.hpp
+++ b/src/ip.hpp
@@ -22,6 +22,7 @@
#define __ZMQ_IP_HPP_INCLUDED__
#include "platform.hpp"
+#include "fd.hpp"
#ifdef ZMQ_HAVE_WINDOWS
#include "windows.hpp"
@@ -30,6 +31,7 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <netdb.h>
#endif
@@ -60,9 +62,12 @@ namespace zmq
int resolve_ip_hostname (sockaddr_storage *addr_, socklen_t *addr_len_,
const char *hostname_);
- // This function sets up address for UNIX domain transport.
+ // This function sets up address for UNIX domain transport.
int resolve_local_path (sockaddr_storage *addr_, socklen_t *addr_len_,
const char* pathname_);
+
+ // Tunes the supplied TCP socket for the best latency.
+ void tune_tcp_socket (fd_t s_);
}
#endif
diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp
index 76ec0bc..27e56a1 100644
--- a/src/tcp_connecter.cpp
+++ b/src/tcp_connecter.cpp
@@ -26,8 +26,8 @@
#include "io_thread.hpp"
#include "platform.hpp"
#include "random.hpp"
-#include "ip.hpp"
#include "err.hpp"
+#include "ip.hpp"
#if defined ZMQ_HAVE_WINDOWS
#include "windows.hpp"
@@ -106,25 +106,7 @@ void zmq::tcp_connecter_t::out_event ()
return;
}
- // Disable Nagle's algorithm. We are doing data batching on 0MQ level,
- // so using Nagle wouldn't improve throughput in anyway, but it would
- // hurt latency.
- int nodelay = 1;
- int rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
- sizeof (int));
-#ifdef ZMQ_HAVE_WINDOWS
- wsa_assert (rc != SOCKET_ERROR);
-#else
- errno_assert (rc == 0);
-#endif
-
-#ifdef ZMQ_HAVE_OPENVMS
- // Disable delayed acknowledgements as they hurt latency is serious manner.
- int nodelack = 1;
- rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
- sizeof (int));
- errno_assert (rc != SOCKET_ERROR);
-#endif
+ tune_tcp_socket (fd);
// Create the engine object for this connection.
tcp_engine_t *engine = new (std::nothrow) tcp_engine_t (fd, options);
diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp
index 07e2803..1bb6deb 100644
--- a/src/tcp_listener.cpp
+++ b/src/tcp_listener.cpp
@@ -29,6 +29,7 @@
#include "session.hpp"
#include "config.hpp"
#include "err.hpp"
+#include "ip.hpp"
#ifdef ZMQ_HAVE_WINDOWS
#include "windows.hpp"
@@ -86,25 +87,7 @@ void zmq::tcp_listener_t::in_event ()
if (fd == retired_fd)
return;
- // Disable Nagle's algorithm. We are doing data batching on 0MQ level,
- // so using Nagle wouldn't improve throughput in anyway, but it would
- // hurt latency.
- int nodelay = 1;
- int rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char*) &nodelay,
- sizeof (int));
-#ifdef ZMQ_HAVE_WINDOWS
- wsa_assert (rc != SOCKET_ERROR);
-#else
- errno_assert (rc == 0);
-#endif
-
-#ifdef ZMQ_HAVE_OPENVMS
- // Disable delayed acknowledgements as they hurt latency is serious manner.
- int nodelack = 1;
- rc = setsockopt (fd, IPPROTO_TCP, TCP_NODELACK, (char*) &nodelack,
- sizeof (int));
- errno_assert (rc != SOCKET_ERROR);
-#endif
+ tune_tcp_socket (fd);
// Create the engine object for this connection.
tcp_engine_t *engine = new (std::nothrow) tcp_engine_t (fd, options);
diff --git a/src/vtcp_connecter.cpp b/src/vtcp_connecter.cpp
index 3fedd6d..842aa3a 100644
--- a/src/vtcp_connecter.cpp
+++ b/src/vtcp_connecter.cpp
@@ -30,8 +30,8 @@
#include "platform.hpp"
#include "random.hpp"
#include "likely.hpp"
-#include "ip.hpp"
#include "err.hpp"
+#include "ip.hpp"
#if defined ZMQ_HAVE_WINDOWS
#include "windows.hpp"
@@ -220,6 +220,8 @@ zmq::fd_t zmq::vtcp_connecter_t::connect ()
return retired_fd;
}
+ tune_tcp_socket (s);
+
fd_t result = s;
s = retired_fd;
return result;
diff --git a/src/vtcp_listener.cpp b/src/vtcp_listener.cpp
index 60fad8c..8fbefb2 100644
--- a/src/vtcp_listener.cpp
+++ b/src/vtcp_listener.cpp
@@ -30,6 +30,7 @@
#include "session.hpp"
#include "stdint.hpp"
#include "err.hpp"
+#include "ip.hpp"
zmq::vtcp_listener_t::vtcp_listener_t (io_thread_t *io_thread_,
socket_base_t *socket_, options_t &options_) :
@@ -95,6 +96,8 @@ void zmq::vtcp_listener_t::in_event ()
if (fd == retired_fd)
return;
+ tune_tcp_socket (fd);
+
// Create the engine object for this connection.
tcp_engine_t *engine = new (std::nothrow) tcp_engine_t (fd, options);
alloc_assert (engine);