2008-08-22 Zoltan Varga <vargaz@gmail.com>
authorMiguel de Icaza <miguel@gnome.org>
Fri, 22 Aug 2008 21:30:31 +0000 (21:30 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 22 Aug 2008 21:30:31 +0000 (21:30 -0000)
* WebConnectionStream.cs (WriteRequest): For small requests,
cluster together the header + body in a single write call, avoids
the latency problems observed in an TLS application that makes
many web service calls.

2008-08-22  Geoff Norton  <gnorton@novell.com>

* WebConnection.cs: Set NoDelay

svn path=/trunk/mcs/; revision=111430

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/WebConnection.cs
mcs/class/System/System.Net/WebConnectionStream.cs

index 1861cac779d9bb244622e611beb0ff0bafb8b3a0..6c420c48f81897c2d7844e9ed4962b714c1992cc 100644 (file)
@@ -1,3 +1,14 @@
+2008-08-22  Zoltan Varga  <vargaz@gmail.com>
+
+       * WebConnectionStream.cs (WriteRequest): For small requests,
+       cluster together the header + body in a single write call, avoids
+       the latency problems observed in an TLS application that makes
+       many web service calls. 
+
+2008-08-22  Geoff Norton  <gnorton@novell.com>
+
+       * WebConnection.cs: Set NoDelay
+
 2008-08-21  Stephane Delcroix  <sdelcroix@novell.com>
 
        * OpenReadCompletedEventArgs.cs: new Address property for 2.1
index fead6cced226906470cb0717ca6c19439b118a58..06bb55455e6a0798d1afc0b6ed20348392b40911 100644 (file)
@@ -125,6 +125,7 @@ namespace System.Net
                                        IPEndPoint remote = new IPEndPoint (address, sPoint.Address.Port);
 
 #if NET_2_0
+                                       socket.NoDelay = true;
                                        if (!sPoint.CallEndPointDelegate (socket, remote)) {
                                                socket.Close ();
                                                socket = null;
index 0a06005483aca7ea47892657f9519d518d72b009..bf465026870e016edd9f3bc3135c5b53a7cabf62 100644 (file)
@@ -540,26 +540,49 @@ namespace System.Net
                        request.InternalContentLength = length;
                        request.SendRequestHeaders ();
                        requestWritten = true;
-                       if (!cnc.Write (headers, 0, headers.Length))
-                               throw new WebException ("Error writing request.", null, WebExceptionStatus.SendFailure, null);
 
-                       headersSent = true;
-                       if (cnc.Data.StatusCode != 0 && cnc.Data.StatusCode != 100)
-                               return;
-
-                       IAsyncResult result = null;
-                       if (length > 0)
-                               result = cnc.BeginWrite (bytes, 0, length, null, null);
-
-                       if (!initRead) {
-                               initRead = true;
-                               WebConnection.InitRead (cnc);
-                       }
+                       //
+                       // For small requests, make a copy, it will reduce the traffic, for large
+                       // requests, the NoDelay bit on the socket should take effect (set in WebConnection).
+                       //
+                       if (headers.Length + length < 8192){
+                               byte[] b = new byte [headers.Length + length];
 
-                       if (length > 0) 
-                               complete_request_written = cnc.EndWrite (result);
-                       else
+                               headers.CopyTo (b, 0);
+                               bytes.CopyTo (b, headers.Length);
+                               
+                               if (!cnc.Write (b, 0, b.Length))
+                                       throw new WebException ("Error writing request.", null, WebExceptionStatus.SendFailure, null);
+                               
+                               headersSent = true;
                                complete_request_written = true;
+                               
+                               if (!initRead) {
+                                       initRead = true;
+                                       WebConnection.InitRead (cnc);
+                               }                               
+                       } else {
+                               if (!cnc.Write (headers, 0, headers.Length))
+                                       throw new WebException ("Error writing request.", null, WebExceptionStatus.SendFailure, null);
+                               
+                               headersSent = true;
+                               if (cnc.Data.StatusCode != 0 && cnc.Data.StatusCode != 100)
+                                       return;
+                               
+                               IAsyncResult result = null;
+                               if (length > 0)
+                                       result = cnc.BeginWrite (bytes, 0, length, null, null);
+                               
+                               if (!initRead) {
+                                       initRead = true;
+                                       WebConnection.InitRead (cnc);
+                               }
+                               
+                               if (length > 0) 
+                                       complete_request_written = cnc.EndWrite (result);
+                               else
+                                       complete_request_written = true;
+                       }
                }
 
                internal void InternalClose ()