From 4ffd067ac04c692ffe91cdff6a81fa5a189e73aa Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 20 Oct 2012 15:30:37 -0400 Subject: [PATCH] Added connection::disable_nagle() --- dlib/sockets/sockets_kernel_1.cpp | 14 ++++++++++++++ dlib/sockets/sockets_kernel_1.h | 3 +++ dlib/sockets/sockets_kernel_2.cpp | 15 +++++++++++++++ dlib/sockets/sockets_kernel_2.h | 3 +++ dlib/sockets/sockets_kernel_abstract.h | 13 +++++++++++++ 5 files changed, 48 insertions(+) diff --git a/dlib/sockets/sockets_kernel_1.cpp b/dlib/sockets/sockets_kernel_1.cpp index 6cf3aebff..999c995b5 100644 --- a/dlib/sockets/sockets_kernel_1.cpp +++ b/dlib/sockets/sockets_kernel_1.cpp @@ -266,6 +266,20 @@ namespace dlib delete &connection_socket; } +// ---------------------------------------------------------------------------------------- + + int connection:: + disable_nagle() + { + int flag = 1; + int status = setsockopt( connection_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag) ); + + if (ret == SOCKET_ERROR) + return OTHER_ERROR; + else + return 0; + } + // ---------------------------------------------------------------------------------------- long connection:: diff --git a/dlib/sockets/sockets_kernel_1.h b/dlib/sockets/sockets_kernel_1.h index 2ed36a65a..e3e49c018 100644 --- a/dlib/sockets/sockets_kernel_1.h +++ b/dlib/sockets/sockets_kernel_1.h @@ -141,6 +141,9 @@ namespace dlib // as the SOCKET win the windows API. typedef unsigned_type::type socket_descriptor_type; + int disable_nagle( + ); + socket_descriptor_type get_socket_descriptor ( ) const; diff --git a/dlib/sockets/sockets_kernel_2.cpp b/dlib/sockets/sockets_kernel_2.cpp index 248db4de9..4a84c9b1c 100644 --- a/dlib/sockets/sockets_kernel_2.cpp +++ b/dlib/sockets/sockets_kernel_2.cpp @@ -11,6 +11,7 @@ #include "sockets_kernel_2.h" #include #include "../set.h" +#include @@ -309,6 +310,20 @@ namespace dlib sdr(0) {} +// ---------------------------------------------------------------------------------------- + + int connection:: + disable_nagle() + { + int flag = 1; + if(setsockopt( connection_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag) )) + { + return OTHER_ERROR; + } + + return 0; + } + // ---------------------------------------------------------------------------------------- long connection:: diff --git a/dlib/sockets/sockets_kernel_2.h b/dlib/sockets/sockets_kernel_2.h index 3d9282fea..d1be8e23d 100644 --- a/dlib/sockets/sockets_kernel_2.h +++ b/dlib/sockets/sockets_kernel_2.h @@ -183,6 +183,9 @@ namespace dlib return temp; } + int disable_nagle( + ); + typedef int socket_descriptor_type; socket_descriptor_type get_socket_descriptor ( diff --git a/dlib/sockets/sockets_kernel_abstract.h b/dlib/sockets/sockets_kernel_abstract.h index 6fdfdc4d7..0d7217588 100644 --- a/dlib/sockets/sockets_kernel_abstract.h +++ b/dlib/sockets/sockets_kernel_abstract.h @@ -362,6 +362,19 @@ namespace dlib - returns OTHER_ERROR if there was an error !*/ + int disable_nagle( + ); + /*! + ensures + - Sets the TCP_NODELAY socket option to disable Nagle's algorithm. + This can sometimes reduce transmission latency, however, in almost + all normal cases you don't want to mess with this as the default + setting is usually appropriate. + + - returns 0 upon success + - returns OTHER_ERROR if there was an error + !*/ + typedef platform_specific_type socket_descriptor_type; socket_descriptor_type get_socket_descriptor ( ) const;