diff options
author | Justin Clark-Casey (justincc) | 2013-02-27 00:21:02 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-02-27 00:21:02 +0000 |
commit | 80c19b7cac52a57fd04966169c657400aeee3de8 (patch) | |
tree | 32c48c0d00da28ed091d8c6a671d43d1e9ab8bdb /OpenSim/Services/Connectors | |
parent | minor: Remove unnecessary very old System.Net reference in OpenSim.Region.Scr... (diff) | |
download | opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.zip opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.tar.gz opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.tar.bz2 opensim-SC_OLD-80c19b7cac52a57fd04966169c657400aeee3de8.tar.xz |
Make sure we dispose of WebResponse, StreamReader and Stream in various places where we were not already.
Diffstat (limited to 'OpenSim/Services/Connectors')
4 files changed, 83 insertions, 81 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs index 5c50936..5004d99 100644 --- a/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs | |||
@@ -73,7 +73,6 @@ namespace OpenSim.Services.Connectors | |||
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | |||
77 | public virtual string Helo() | 76 | public virtual string Helo() |
78 | { | 77 | { |
79 | HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); | 78 | HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); |
@@ -82,10 +81,12 @@ namespace OpenSim.Services.Connectors | |||
82 | 81 | ||
83 | try | 82 | try |
84 | { | 83 | { |
85 | WebResponse response = req.GetResponse(); | 84 | using (WebResponse response = req.GetResponse()) |
86 | if (response.Headers.Get("X-Handlers-Provided") == null) // just in case this ever returns a null | 85 | { |
87 | return string.Empty; | 86 | if (response.Headers.Get("X-Handlers-Provided") == null) // just in case this ever returns a null |
88 | return response.Headers.Get("X-Handlers-Provided"); | 87 | return string.Empty; |
88 | return response.Headers.Get("X-Handlers-Provided"); | ||
89 | } | ||
89 | } | 90 | } |
90 | catch (Exception e) | 91 | catch (Exception e) |
91 | { | 92 | { |
@@ -95,6 +96,5 @@ namespace OpenSim.Services.Connectors | |||
95 | // fail | 96 | // fail |
96 | return string.Empty; | 97 | return string.Empty; |
97 | } | 98 | } |
98 | |||
99 | } | 99 | } |
100 | } | 100 | } \ No newline at end of file |
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs index 2f263ae..47d0cce 100644 --- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs | |||
@@ -171,41 +171,45 @@ namespace OpenSim.Services.Connectors.Hypergrid | |||
171 | // Let's wait for the response | 171 | // Let's wait for the response |
172 | //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | 172 | //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); |
173 | 173 | ||
174 | WebResponse webResponse = null; | ||
175 | StreamReader sr = null; | ||
176 | try | 174 | try |
177 | { | 175 | { |
178 | webResponse = AgentCreateRequest.GetResponse(); | 176 | using (WebResponse webResponse = AgentCreateRequest.GetResponse()) |
179 | if (webResponse == null) | ||
180 | { | 177 | { |
181 | m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | 178 | if (webResponse == null) |
182 | } | ||
183 | else | ||
184 | { | ||
185 | |||
186 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
187 | string response = sr.ReadToEnd().Trim(); | ||
188 | m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
189 | |||
190 | if (!String.IsNullOrEmpty(response)) | ||
191 | { | 179 | { |
192 | try | 180 | m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); |
193 | { | 181 | } |
194 | // we assume we got an OSDMap back | 182 | else |
195 | OSDMap r = Util.GetOSDMap(response); | 183 | { |
196 | bool success = r["success"].AsBoolean(); | 184 | using (Stream s = webResponse.GetResponseStream()) |
197 | reason = r["reason"].AsString(); | ||
198 | return success; | ||
199 | } | ||
200 | catch (NullReferenceException e) | ||
201 | { | 185 | { |
202 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | 186 | using (StreamReader sr = new StreamReader(s)) |
203 | 187 | { | |
204 | // check for old style response | 188 | string response = sr.ReadToEnd().Trim(); |
205 | if (response.ToLower().StartsWith("true")) | 189 | m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); |
206 | return true; | 190 | |
207 | 191 | if (!String.IsNullOrEmpty(response)) | |
208 | return false; | 192 | { |
193 | try | ||
194 | { | ||
195 | // we assume we got an OSDMap back | ||
196 | OSDMap r = Util.GetOSDMap(response); | ||
197 | bool success = r["success"].AsBoolean(); | ||
198 | reason = r["reason"].AsString(); | ||
199 | return success; | ||
200 | } | ||
201 | catch (NullReferenceException e) | ||
202 | { | ||
203 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
204 | |||
205 | // check for old style response | ||
206 | if (response.ToLower().StartsWith("true")) | ||
207 | return true; | ||
208 | |||
209 | return false; | ||
210 | } | ||
211 | } | ||
212 | } | ||
209 | } | 213 | } |
210 | } | 214 | } |
211 | } | 215 | } |
@@ -216,11 +220,6 @@ namespace OpenSim.Services.Connectors.Hypergrid | |||
216 | reason = "Destination did not reply"; | 220 | reason = "Destination did not reply"; |
217 | return false; | 221 | return false; |
218 | } | 222 | } |
219 | finally | ||
220 | { | ||
221 | if (sr != null) | ||
222 | sr.Close(); | ||
223 | } | ||
224 | 223 | ||
225 | return true; | 224 | return true; |
226 | 225 | ||
diff --git a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs index 7429293..5948380 100644 --- a/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs +++ b/OpenSim/Services/Connectors/Neighbour/NeighbourServicesConnector.cs | |||
@@ -168,22 +168,27 @@ namespace OpenSim.Services.Connectors | |||
168 | // Let's wait for the response | 168 | // Let's wait for the response |
169 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); | 169 | //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall"); |
170 | 170 | ||
171 | StreamReader sr = null; | ||
172 | try | 171 | try |
173 | { | 172 | { |
174 | WebResponse webResponse = helloNeighbourRequest.GetResponse(); | 173 | using (WebResponse webResponse = helloNeighbourRequest.GetResponse()) |
175 | if (webResponse == null) | ||
176 | { | 174 | { |
177 | m_log.DebugFormat( | 175 | if (webResponse == null) |
178 | "[REST COMMS]: Null reply on DoHelloNeighbourCall post from {0} to {1}", | 176 | { |
179 | thisRegion.RegionName, region.RegionName); | 177 | m_log.DebugFormat( |
178 | "[REST COMMS]: Null reply on DoHelloNeighbourCall post from {0} to {1}", | ||
179 | thisRegion.RegionName, region.RegionName); | ||
180 | } | ||
181 | |||
182 | using (Stream s = webResponse.GetResponseStream()) | ||
183 | { | ||
184 | using (StreamReader sr = new StreamReader(s)) | ||
185 | { | ||
186 | //reply = sr.ReadToEnd().Trim(); | ||
187 | sr.ReadToEnd().Trim(); | ||
188 | //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); | ||
189 | } | ||
190 | } | ||
180 | } | 191 | } |
181 | |||
182 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
183 | //reply = sr.ReadToEnd().Trim(); | ||
184 | sr.ReadToEnd().Trim(); | ||
185 | //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply); | ||
186 | |||
187 | } | 192 | } |
188 | catch (Exception e) | 193 | catch (Exception e) |
189 | { | 194 | { |
@@ -193,11 +198,6 @@ namespace OpenSim.Services.Connectors | |||
193 | 198 | ||
194 | return false; | 199 | return false; |
195 | } | 200 | } |
196 | finally | ||
197 | { | ||
198 | if (sr != null) | ||
199 | sr.Close(); | ||
200 | } | ||
201 | 201 | ||
202 | return true; | 202 | return true; |
203 | } | 203 | } |
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs index 63a32e7..74b980c 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs | |||
@@ -339,36 +339,38 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
339 | // Simian does not require the asset ID to be in the URL because it's in the post data. | 339 | // Simian does not require the asset ID to be in the URL because it's in the post data. |
340 | // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs | 340 | // By appending it to the URL also, we allow caching proxies (squid) to invalidate asset URLs |
341 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString()); | 341 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl + asset.FullID.ToString()); |
342 | |||
343 | HttpWebResponse response = MultipartForm.Post(request, postParameters); | ||
344 | using (Stream responseStream = response.GetResponseStream()) | ||
345 | { | ||
346 | string responseStr = null; | ||
347 | 342 | ||
348 | try | 343 | using (HttpWebResponse response = MultipartForm.Post(request, postParameters)) |
344 | { | ||
345 | using (Stream responseStream = response.GetResponseStream()) | ||
349 | { | 346 | { |
350 | responseStr = responseStream.GetStreamString(); | 347 | string responseStr = null; |
351 | OSD responseOSD = OSDParser.Deserialize(responseStr); | 348 | |
352 | if (responseOSD.Type == OSDType.Map) | 349 | try |
353 | { | 350 | { |
354 | OSDMap responseMap = (OSDMap)responseOSD; | 351 | responseStr = responseStream.GetStreamString(); |
355 | if (responseMap["Success"].AsBoolean()) | 352 | OSD responseOSD = OSDParser.Deserialize(responseStr); |
356 | return asset.ID; | 353 | if (responseOSD.Type == OSDType.Map) |
354 | { | ||
355 | OSDMap responseMap = (OSDMap)responseOSD; | ||
356 | if (responseMap["Success"].AsBoolean()) | ||
357 | return asset.ID; | ||
358 | else | ||
359 | errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | ||
360 | } | ||
357 | else | 361 | else |
358 | errorMessage = "Upload failed: " + responseMap["Message"].AsString(); | 362 | { |
363 | errorMessage = "Response format was invalid:\n" + responseStr; | ||
364 | } | ||
359 | } | 365 | } |
360 | else | 366 | catch (Exception ex) |
361 | { | 367 | { |
362 | errorMessage = "Response format was invalid:\n" + responseStr; | 368 | if (!String.IsNullOrEmpty(responseStr)) |
369 | errorMessage = "Failed to parse the response:\n" + responseStr; | ||
370 | else | ||
371 | errorMessage = "Failed to retrieve the response: " + ex.Message; | ||
363 | } | 372 | } |
364 | } | 373 | } |
365 | catch (Exception ex) | ||
366 | { | ||
367 | if (!String.IsNullOrEmpty(responseStr)) | ||
368 | errorMessage = "Failed to parse the response:\n" + responseStr; | ||
369 | else | ||
370 | errorMessage = "Failed to retrieve the response: " + ex.Message; | ||
371 | } | ||
372 | } | 374 | } |
373 | } | 375 | } |
374 | catch (WebException ex) | 376 | catch (WebException ex) |
@@ -378,6 +380,7 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
378 | 380 | ||
379 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}", | 381 | m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}", |
380 | asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage); | 382 | asset.Name, asset.ID, asset.Metadata.ContentType, errorMessage); |
383 | |||
381 | return null; | 384 | return null; |
382 | } | 385 | } |
383 | 386 | ||