Add connection.setNoDelay() to disable Nagle algorithm.

This commit is contained in:
Ryan Dahl committed 2009-09-23 15:36:34 +02:00
1 parent 2df13c7310
commit e0ec0036ca
8 files changed
+58 -3

No files matched your search

+9
View File
@@ -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)
{
+1
View File
@@ -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
+11 -1
View File
@@ -1712,6 +1712,16 @@ of 60 seconds (60000 ms).
</p>
<div class="paragraph"><p>If <tt>timeout</tt> is 0, then the idle timeout is disabled.</p></div>
</dd>
<dt class="hdlist1">
<tt>connection.setNoDelay(noDelay=true)</tt>
</dt>
<dd>
<p>
Disables the Nagle algorithm. By default TCP connections use the Nagle
algorithm, they buffer data before sending it off. Setting <tt>noDelay</tt> will
immediately fire off data each time <tt>connection.send()</tt> is called.
</p>
</dd>
</dl></div>
<h3 id="_dns">DNS</h3><div style="clear:left"></div>
<div class="paragraph"><p>Here is an example of which resolves <tt>"www.google.com"</tt> then reverse
@@ -1922,7 +1932,7 @@ init (Handle&lt;Object&gt; target)
<div id="footer">
<div id="footer-text">
Version 0.1.11<br />
Last updated 2009-09-21 12:26:35 CEST
Last updated 2009-09-23 15:35:53 CEST
</div>
</div>
</body>
+4
View File
@@ -1081,6 +1081,10 @@ 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
+11 -2
View File
@@ -1,11 +1,11 @@
.\" Title: node
.\" Author:
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\" Date: 09/21/2009
.\" Date: 09/23/2009
.\" Manual:
.\" Source:
.\"
.TH "NODE" "1" "09/21/2009" "" ""
.TH "NODE" "1" "09/23/2009" "" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
@@ -1639,6 +1639,15 @@ If
timeout
is 0, then the idle timeout is disabled\.
.RE
.PP
connection\.setNoDelay(noDelay=true)
.RS 4
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\.
.RE
.RE
.SS "DNS"
Here is an example of which resolves "www\.google\.com" then reverse resolves the IP addresses which are returned\.
+15
View File
@@ -64,6 +64,7 @@ void Connection::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "readPause", ReadPause);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "readResume", ReadResume);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setTimeout", SetTimeout);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setNoDelay", SetNoDelay);
constructor_template->PrototypeTemplate()->SetAccessor(
READY_STATE_SYMBOL,
@@ -332,6 +333,20 @@ Handle<Value> Connection::ForceClose(const Arguments& args) {
return Undefined();
}
Handle<Value> Connection::SetNoDelay(const Arguments& args) {
HandleScope scope;
Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
bool no_delay = true;
if (args.Length() > 0) {
no_delay = args[0]->IsTrue();
}
connection->SetNoDelay(no_delay);
return Undefined();
}
Handle<Value> Connection::Send(const Arguments& args) {
HandleScope scope;
Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
+5
View File
@@ -28,6 +28,7 @@ class Connection : public EventEmitter {
static v8::Handle<v8::Value> ReadPause(const v8::Arguments& args);
static v8::Handle<v8::Value> ReadResume(const v8::Arguments& args);
static v8::Handle<v8::Value> SetTimeout(const v8::Arguments& args);
static v8::Handle<v8::Value> SetNoDelay(const v8::Arguments& args);
static v8::Handle<v8::Value> ReadyStateGetter(v8::Local<v8::String> _,
const v8::AccessorInfo& info);
@@ -70,6 +71,10 @@ class Connection : public EventEmitter {
evcom_stream_reset_timeout(&stream_, timeout);
}
void SetNoDelay(bool no_delay) {
evcom_stream_set_no_delay(&stream_, no_delay);
}
virtual void OnConnect();
virtual void OnReceive(const void *buf, size_t len);
virtual void OnEOF();
+2
View File
@@ -17,9 +17,11 @@ function pingPongTest (port, host, on_complete) {
assertEquals(socket.remoteAddress, "127.0.0.1");
socket.setEncoding("utf8");
socket.setNoDelay();
socket.timeout = 0;
socket.addListener("receive", function (data) {
puts("server got: " + JSON.stringify(data));
assertEquals("open", socket.readyState);
assertTrue(count <= N);
if (/PING/.exec(data)) {