From 9bf3e2a25745000fc9113c4b00f280fa67460601 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 17 Sep 2014 15:36:22 +0100 Subject: dispose some tmp streams --- OpenSim/Framework/Communications/RestClient.cs | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'OpenSim/Framework/Communications/RestClient.cs') diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs index 42c0b18..de34250 100644 --- a/OpenSim/Framework/Communications/RestClient.cs +++ b/OpenSim/Framework/Communications/RestClient.cs @@ -329,15 +329,16 @@ namespace OpenSim.Framework.Communications return null; } - Stream src = _response.GetResponseStream(); - int length = src.Read(_readbuf, 0, BufferSize); - while (length > 0) + using (Stream src = _response.GetResponseStream()) { - _resource.Write(_readbuf, 0, length); - length = src.Read(_readbuf, 0, BufferSize); + int length = src.Read(_readbuf, 0, BufferSize); + while (length > 0) + { + _resource.Write(_readbuf, 0, length); + length = src.Read(_readbuf, 0, BufferSize); + } } - // TODO! Implement timeout, without killing the server // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); @@ -372,16 +373,19 @@ namespace OpenSim.Framework.Communications m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); src.Seek(0, SeekOrigin.Begin); m_log.Info("[REST]: Seek is ok"); - Stream dst = _request.GetRequestStream(); - m_log.Info("[REST]: GetRequestStream is ok"); - byte[] buf = new byte[1024]; - int length = src.Read(buf, 0, 1024); - m_log.Info("[REST]: First Read is ok"); - while (length > 0) + using (Stream dst = _request.GetRequestStream()) { - dst.Write(buf, 0, length); - length = src.Read(buf, 0, 1024); + m_log.Info("[REST]: GetRequestStream is ok"); + + byte[] buf = new byte[1024]; + int length = src.Read(buf, 0, 1024); + m_log.Info("[REST]: First Read is ok"); + while (length > 0) + { + dst.Write(buf, 0, length); + length = src.Read(buf, 0, 1024); + } } _response = (HttpWebResponse) _request.GetResponse(); -- cgit v1.1