refactor: More consistently use using construct within WebUtil to match other existing code there.
parent
1f4f09ad69
commit
5fafea6631
|
@ -794,13 +794,15 @@ namespace OpenSim.Framework
|
|||
if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
|
||||
ht.ServicePoint.ConnectionLimit = maxConnections;
|
||||
|
||||
WebResponse response = null;
|
||||
TResponse deserial = default(TResponse);
|
||||
XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
|
||||
|
||||
request.Method = verb;
|
||||
|
||||
MemoryStream buffer = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (verb == "POST")
|
||||
{
|
||||
request.ContentType = "text/xml";
|
||||
|
@ -825,33 +827,24 @@ namespace OpenSim.Framework
|
|||
|
||||
request.BeginGetRequestStream(delegate(IAsyncResult res)
|
||||
{
|
||||
Stream requestStream = request.EndGetRequestStream(res);
|
||||
|
||||
using (Stream requestStream = request.EndGetRequestStream(res))
|
||||
requestStream.Write(buffer.ToArray(), 0, length);
|
||||
requestStream.Close();
|
||||
|
||||
// capture how much time was spent writing
|
||||
tickdata = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
|
||||
request.BeginGetResponse(delegate(IAsyncResult ar)
|
||||
{
|
||||
response = request.EndGetResponse(ar);
|
||||
Stream respStream = null;
|
||||
using (WebResponse response = request.EndGetResponse(ar))
|
||||
{
|
||||
try
|
||||
{
|
||||
respStream = response.GetResponseStream();
|
||||
deserial = (TResponse)deserializer.Deserialize(
|
||||
respStream);
|
||||
using (Stream respStream = response.GetResponseStream())
|
||||
deserial = (TResponse)deserializer.Deserialize(respStream);
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Let's not close this
|
||||
//buffer.Close();
|
||||
respStream.Close();
|
||||
response.Close();
|
||||
}
|
||||
|
||||
action(deserial);
|
||||
|
@ -867,21 +860,16 @@ namespace OpenSim.Framework
|
|||
{
|
||||
// If the server returns a 404, this appears to trigger a System.Net.WebException even though that isn't
|
||||
// documented in MSDN
|
||||
response = request.EndGetResponse(res2);
|
||||
|
||||
Stream respStream = null;
|
||||
using (WebResponse response = request.EndGetResponse(res2))
|
||||
{
|
||||
try
|
||||
{
|
||||
respStream = response.GetResponseStream();
|
||||
using (Stream respStream = response.GetResponseStream())
|
||||
deserial = (TResponse)deserializer.Deserialize(respStream);
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
respStream.Close();
|
||||
response.Close();
|
||||
}
|
||||
}
|
||||
catch (WebException e)
|
||||
|
@ -962,6 +950,12 @@ namespace OpenSim.Framework
|
|||
reqnum, tickdiff, tickdata);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (buffer != null)
|
||||
buffer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SynchronousRestFormsRequester
|
||||
|
@ -1056,11 +1050,6 @@ namespace OpenSim.Framework
|
|||
"[FORMS]: Exception occured on receiving {0} {1}: {2}{3}",
|
||||
verb, requestUrl, e.Message, e.StackTrace);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (respStream != null)
|
||||
respStream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1145,6 +1134,8 @@ namespace OpenSim.Framework
|
|||
request.Method = verb;
|
||||
MemoryStream buffer = null;
|
||||
|
||||
try
|
||||
{
|
||||
if ((verb == "POST") || (verb == "PUT"))
|
||||
{
|
||||
request.ContentType = "text/xml";
|
||||
|
@ -1167,10 +1158,9 @@ namespace OpenSim.Framework
|
|||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogOutgoingDetail(buffer);
|
||||
|
||||
Stream requestStream = null;
|
||||
try
|
||||
{
|
||||
requestStream = request.GetRequestStream();
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(buffer.ToArray(), 0, length);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -1183,9 +1173,6 @@ namespace OpenSim.Framework
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (requestStream != null)
|
||||
requestStream.Dispose();
|
||||
|
||||
// capture how much time was spent writing
|
||||
tickdata = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
}
|
||||
|
@ -1265,6 +1252,12 @@ namespace OpenSim.Framework
|
|||
"[WEB UTIL]: HTTP OUT {0} took {1}ms, {2}ms writing",
|
||||
reqnum, tickdiff, tickdata);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (buffer != null)
|
||||
buffer.Dispose();
|
||||
}
|
||||
|
||||
return deserial;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue