diff options
Diffstat (limited to 'OpenSim/Framework/WebUtil.cs')
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index af25da9..ead8f46 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -63,6 +63,31 @@ namespace OpenSim.Framework | |||
63 | // a "long" call for warning & debugging purposes | 63 | // a "long" call for warning & debugging purposes |
64 | public const int LongCallTime = 500; | 64 | public const int LongCallTime = 500; |
65 | 65 | ||
66 | // dictionary of end points | ||
67 | private static Dictionary<string,object> m_endpointSerializer = new Dictionary<string,object>(); | ||
68 | |||
69 | |||
70 | private static object EndPointLock(string url) | ||
71 | { | ||
72 | System.Uri uri = new System.Uri(url); | ||
73 | string endpoint = string.Format("{0}:{1}",uri.Host,uri.Port); | ||
74 | |||
75 | lock (m_endpointSerializer) | ||
76 | { | ||
77 | object eplock = null; | ||
78 | |||
79 | if (! m_endpointSerializer.TryGetValue(endpoint,out eplock)) | ||
80 | { | ||
81 | eplock = new object(); | ||
82 | m_endpointSerializer.Add(endpoint,eplock); | ||
83 | // m_log.WarnFormat("[WEB UTIL] add a new host to end point serializer {0}",endpoint); | ||
84 | } | ||
85 | |||
86 | return eplock; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | |||
66 | #region JSONRequest | 91 | #region JSONRequest |
67 | 92 | ||
68 | /// <summary> | 93 | /// <summary> |
@@ -96,6 +121,14 @@ namespace OpenSim.Framework | |||
96 | 121 | ||
97 | public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed) | 122 | public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed) |
98 | { | 123 | { |
124 | lock (EndPointLock(url)) | ||
125 | { | ||
126 | return ServiceOSDRequestWorker(url,data,method,timeout,compressed); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed) | ||
131 | { | ||
99 | int reqnum = m_requestNumber++; | 132 | int reqnum = m_requestNumber++; |
100 | // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); | 133 | // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); |
101 | 134 | ||
@@ -248,6 +281,14 @@ namespace OpenSim.Framework | |||
248 | 281 | ||
249 | public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout) | 282 | public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout) |
250 | { | 283 | { |
284 | lock (EndPointLock(url)) | ||
285 | { | ||
286 | return ServiceFormRequestWorker(url,data,timeout); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | private static OSDMap ServiceFormRequestWorker(string url, NameValueCollection data, int timeout) | ||
291 | { | ||
251 | int reqnum = m_requestNumber++; | 292 | int reqnum = m_requestNumber++; |
252 | string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown"; | 293 | string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown"; |
253 | // m_log.DebugFormat("[WEB UTIL]: <{0}> start form request for {1}, method {2}",reqnum,url,method); | 294 | // m_log.DebugFormat("[WEB UTIL]: <{0}> start form request for {1}, method {2}",reqnum,url,method); |
@@ -469,8 +510,13 @@ namespace OpenSim.Framework | |||
469 | /// <remarks> | 510 | /// <remarks> |
470 | /// Copying begins at the streams' current positions. The positions are | 511 | /// Copying begins at the streams' current positions. The positions are |
471 | /// NOT reset after copying is complete. | 512 | /// NOT reset after copying is complete. |
513 | /// NOTE!! .NET 4.0 adds the method 'Stream.CopyTo(stream, bufferSize)'. | ||
514 | /// This function could be replaced with that method once we move | ||
515 | /// totally to .NET 4.0. For versions before, this routine exists. | ||
516 | /// This routine used to be named 'CopyTo' but the int parameter has | ||
517 | /// a different meaning so this method was renamed to avoid any confusion. | ||
472 | /// </remarks> | 518 | /// </remarks> |
473 | public static int CopyTo(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy) | 519 | public static int CopyStream(this Stream copyFrom, Stream copyTo, int maximumBytesToCopy) |
474 | { | 520 | { |
475 | byte[] buffer = new byte[4096]; | 521 | byte[] buffer = new byte[4096]; |
476 | int readBytes; | 522 | int readBytes; |