* docs.make, Makefile.am: Build mono-file-formats{.tree,.zip},
[mono.git] / mcs / class / System / System.Net / HttpConnection.cs
index 610de80c9a6a2a6d3b4e1df8093b74b4a850ffbd..6a57e3a6dcc5a2a05e241918a5dc9f9d43a78203 100644 (file)
@@ -54,7 +54,6 @@ namespace System.Net {
                int chunked_uses;
                bool context_bound;
                bool secure;
-               X509Certificate2 cert;
                AsymmetricAlgorithm key;
 
                public HttpConnection (Socket sock, EndPointListener epl, bool secure, X509Certificate2 cert, AsymmetricAlgorithm key)
@@ -62,14 +61,17 @@ namespace System.Net {
                        this.sock = sock;
                        this.epl = epl;
                        this.secure = secure;
-                       this.cert = cert;
                        this.key = key;
                        if (secure == false) {
                                stream = new NetworkStream (sock, false);
                        } else {
+#if EMBEDDED_IN_1_0
+                               throw new NotImplementedException ();
+#else
                                SslServerStream ssl_stream = new SslServerStream (new NetworkStream (sock, false), cert, false, false);
                                ssl_stream.PrivateKeyCertSelectionDelegate += OnPVKSelection;
                                stream = ssl_stream;
+#endif
                        }
                        Init ();
                }
@@ -119,7 +121,11 @@ namespace System.Net {
                {
                        if (buffer == null)
                                buffer = new byte [BufferSize];
-                       stream.BeginRead (buffer, 0, BufferSize, OnRead, this);
+                       try {
+                               stream.BeginRead (buffer, 0, BufferSize, OnRead, this);
+                       } catch {
+                               sock.Close (); // stream disposed
+                       }
                }
 
                public RequestStream GetRequestStream (bool chunked, long contentlength)
@@ -159,7 +165,7 @@ namespace System.Net {
                                nread = stream.EndRead (ares);
                                ms.Write (buffer, 0, nread);
                        } catch (Exception e) {
-                               Console.WriteLine (e);
+                               //Console.WriteLine (e);
                                if (ms.Length > 0)
                                        SendError ();
                                sock.Close ();
@@ -313,10 +319,20 @@ namespace System.Net {
                                        return;
                                }
 
-                               Socket s = sock;
-                               sock = null;
-                               s.Shutdown (SocketShutdown.Both);
-                               s.Close ();
+                               if (context.Response.Headers ["connection"] == "close") {
+                                       Socket s = sock;
+                                       sock = null;
+                                       try {
+                                               s.Shutdown (SocketShutdown.Both);
+                                       } finally {
+                                               s.Close ();
+                                       }
+                               } else {
+                                       Init ();
+                                       BeginReadRequest ();
+                                       return;
+                               }
+
                                if (context_bound)
                                        epl.UnbindContext (context);
                        }