Merge pull request #981 from methane/websocket
[mono.git] / mcs / class / System / System.Net / HttpConnection.cs
index 6e7775b5c339105e87d246696bd50b4d3e3c4f92..d554309b695de23d85e86e7df53800aa518248c3 100644 (file)
 
 #if SECURITY_DEP
 
+#if MONOTOUCH || MONODROID
+using Mono.Security.Protocol.Tls;
+#else
+extern alias MonoSecurity;
+using MonoSecurity::Mono.Security.Protocol.Tls;
+#endif
+
 using System.IO;
 using System.Net.Sockets;
 using System.Reflection;
@@ -36,7 +43,6 @@ using System.Text;
 using System.Threading;
 using System.Security.Cryptography;
 using System.Security.Cryptography.X509Certificates;
-using Mono.Security.Protocol.Tls;
 
 namespace System.Net {
        sealed class HttpConnection
@@ -203,6 +209,17 @@ namespace System.Net {
                        return o_stream;
                }
 
+               internal Socket Hijack (out ArraySegment<byte> buffered)
+               {
+                       // TODO: disable normal request/response.
+                       buffered = new ArraySegment<byte> (ms.GetBuffer(), position, (int)ms.Length - position);
+                       RemoveConnection ();
+                       var s = sock;
+                       sock = null;
+                       o_stream = null;
+                       return s;
+               }
+
                static void OnRead (IAsyncResult ares)
                {
                        HttpConnection cnc = (HttpConnection) ares.AsyncState;
@@ -439,7 +456,9 @@ namespace System.Net {
                {
                        if (sock != null) {
                                Stream st = GetResponseStream ();
-                               st.Close ();
+                               if (st != null)
+                                       st.Close ();
+
                                o_stream = null;
                        }