From e0ec0036ca2cee7317f63e6462b9631067cf1e38 Mon Sep 17 00:00:00 2001
From: Ryan Dahl
Date: Wed, 23 Sep 2009 15:35:03 +0200
Subject: [PATCH] Add connection.setNoDelay() to disable Nagle algorithm.
---
deps/evcom/evcom.c | 9 +++++++++
deps/evcom/evcom.h | 1 +
doc/api.html | 12 +++++++++++-
doc/api.txt | 4 ++++
doc/node.1 | 13 +++++++++++--
src/net.cc | 15 +++++++++++++++
src/net.h | 5 +++++
test/mjsunit/test-tcp-pingpong.js | 2 ++
8 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/deps/evcom/evcom.c b/deps/evcom/evcom.c
index 4267d351e89..0849f8ad0f3 100644
--- a/deps/evcom/evcom.c
+++ b/deps/evcom/evcom.c
@@ -1205,6 +1205,15 @@ evcom_stream_reset_timeout (evcom_stream *stream, float timeout)
}
}
+void
+evcom_stream_set_no_delay (evcom_stream *stream, int no_delay)
+{
+ if (DUPLEX(stream)) {
+ int flags = no_delay ? 1 : 0;
+ setsockopt(stream->recvfd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
+ }
+}
+
void
evcom_stream_attach (EV_P_ evcom_stream *stream)
{
diff --git a/deps/evcom/evcom.h b/deps/evcom/evcom.h
index 977941692a0..644ec9737c1 100644
--- a/deps/evcom/evcom.h
+++ b/deps/evcom/evcom.h
@@ -192,6 +192,7 @@ void evcom_stream_detach (evcom_stream *);
void evcom_stream_read_resume (evcom_stream *);
void evcom_stream_read_pause (evcom_stream *);
void evcom_stream_reset_timeout (evcom_stream *, float timeout);
+void evcom_stream_set_no_delay (evcom_stream *, int no_delay);
void evcom_stream_write (evcom_stream *, const char *str, size_t len);
/* Once the write buffer is drained, evcom_stream_close will shutdown the
* writing end of the stream and will close the read end once the server
diff --git a/doc/api.html b/doc/api.html
index 8cf60291e35..6f33722f591 100644
--- a/doc/api.html
+++ b/doc/api.html
@@ -1712,6 +1712,16 @@ of 60 seconds (60000 ms).
If timeout is 0, then the idle timeout is disabled.
+
+connection.setNoDelay(noDelay=true)
+
+
+
+Disables the Nagle algorithm. By default TCP connections use the Nagle
+algorithm, they buffer data before sending it off. Setting noDelay will
+immediately fire off data each time connection.send() is called.
+
+
DNS
Here is an example of which resolves "www.google.com" then reverse
@@ -1922,7 +1932,7 @@ init (Handle<Object> target)