changeset 109:0fc3f42a8555

Small improvements, return TCPSocket in HTTPContext if applicable
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 03 Nov 2014 18:29:58 +0100
parents 819fb56a56ea
children df53bdd49507
files Net/HTTP.cs Xml/Socket.cs
diffstat 2 files changed, 12 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Net/HTTP.cs	Mon Oct 27 23:24:32 2014 +0100
+++ b/Net/HTTP.cs	Mon Nov 03 18:29:58 2014 +0100
@@ -99,7 +99,7 @@
 
 		public Socket Socket { get; private set; }
 		public Boolean SuppressStandardHeaders { get; set; }
-		public TCPStream TCPStream { get; private set; }
+		public TCPStream TCPStream { get { return Reader.BaseStream as TCPStream; } }
 
 		private StreamWriter Writer;
 		private PrebufferingStream Reader;
@@ -411,14 +411,10 @@
 				if (socket.ProtocolType == ProtocolType.Tcp) socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
 				if (stream == null) stream = new NetworkStream(socket, true);
 			}
-			Init(stream);
-		}
-
-		private void Init(Stream Stream) {
-			Writer = new StreamWriter(Stream, Encoding.ASCII);
+			Writer = new StreamWriter(stream, Encoding.ASCII);
 			Writer.NewLine = "\r\n";
 			Writer.AutoFlush = true;
-			Reader = new PrebufferingStream(Stream);
+			Reader = new PrebufferingStream(stream);
 			Reader.BeginPrebuffering(PrebufferCallback, null);
 		}
 
--- a/Xml/Socket.cs	Mon Oct 27 23:24:32 2014 +0100
+++ b/Xml/Socket.cs	Mon Nov 03 18:29:58 2014 +0100
@@ -58,18 +58,16 @@
 			return Buffer;
 		}
 		public virtual XmlDocument ReadDocument() {
-				MemoryStream Buffer = ReadRawDocument();
-				try {
-					XmlDocument Doc = new XmlDocument();
-					XmlReader XMLReader = XmlReader.Create(Buffer, pXMLReaderSettings);
-					Doc.Load(XMLReader);
-					XMLReader.Close();
-					return Doc;
-				} catch (Exception ex) {
-					Buffer.Seek(0, SeekOrigin.Begin);
-					throw new IOException("Could not parse XML document: \"" + Encoding.UTF8.GetString(Buffer.ToArray()) + "\"", ex);
-				}
+			MemoryStream Buffer = ReadRawDocument();
+			XmlDocument Doc = new XmlDocument();
+			try {
+				using (XmlReader XMLReader = XmlReader.Create(Buffer, pXMLReaderSettings)) Doc.Load(XMLReader);
+			} catch (Exception ex) {
+				Buffer.Seek(0, SeekOrigin.Begin);
+				throw new IOException("Could not parse XML document: \"" + Encoding.UTF8.GetString(Buffer.ToArray()) + "\"", ex);
 			}
+			return Doc;
+		}
 
 		protected virtual void CreateWriter() {
 			pWriter = XmlWriter.Create(pStream, WriterSettings);