Browse Source

cosmetics

UbitUmarov 3 years ago
parent
commit
612632f945

+ 1 - 1
OpenSim/Addons/Groups/GroupsMessagingModule.cs

@@ -296,13 +296,13 @@ namespace OpenSim.Groups
 
             // In V2 we always only send to online members.
             // Sending to offline members is not an option.
-            string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray();
 
             // We cache in order not to overwhelm the presence service on large grids with many groups.  This does
             // mean that members coming online will not see all group members until after m_usersOnlineCacheExpirySeconds has elapsed.
             // (assuming this is the same across all grid simulators).
             if (!m_usersOnlineCache.TryGetValue(groupID, out onlineAgents))
             {
+                string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray();
                 onlineAgents = m_presenceService.GetAgents(t1);
                 m_usersOnlineCache.Add(groupID, onlineAgents, m_usersOnlineCacheExpirySeconds);
             }

+ 2 - 3
OpenSim/ConsoleClient/Requester.cs

@@ -67,9 +67,8 @@ namespace OpenSim.ConsoleClient
                     {
                         try
                         {
-                            using (Stream s = response.GetResponseStream())
-                                using (StreamReader r = new StreamReader(s))
-                                    reply = r.ReadToEnd();
+                            using (StreamReader r = new StreamReader(response.GetResponseStream()))
+                                reply = r.ReadToEnd();
 
                         }
                         catch (System.InvalidOperationException)

+ 29 - 20
OpenSim/Framework/RestClient.cs

@@ -325,20 +325,20 @@ namespace OpenSim.Framework
         {
             lock (_lock)
             {
-                _request = (HttpWebRequest) WebRequest.Create(buildUri());
-                _request.ContentType = "application/xml";
-                _request.Timeout = 90000;
-                _request.Method = RequestMethod;
-                _asyncException = null;
-                if (auth != null)
-                    auth.AddAuthorization(_request.Headers);
-
                 int reqnum = WebUtil.RequestNumber++;
-                if (WebUtil.DebugLevel >= 3)
-                    m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} REST {1} to {2}", reqnum, _request.Method, _request.RequestUri);
-
                 try
                 {
+                    _request = (HttpWebRequest) WebRequest.Create(buildUri());
+                    _request.ContentType = "application/xml";
+                    _request.Timeout = 90000;
+                    _request.Method = RequestMethod;
+                    _asyncException = null;
+                    if (auth != null)
+                        auth.AddAuthorization(_request.Headers);
+
+                    if (WebUtil.DebugLevel >= 3)
+                        m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} REST {1} to {2}", reqnum, _request.Method, _request.RequestUri);
+
                     using (_response = (HttpWebResponse) _request.GetResponse())
                     {
                         using (Stream src = _response.GetResponseStream())
@@ -388,16 +388,25 @@ namespace OpenSim.Framework
         // just post data, ignoring result
         public async Task AsyncPOSTRequest(byte[] src, IServiceAuth auth)
         {
-            _request = (HttpWebRequest)WebRequest.Create(buildUri());
-            _request.ContentType = "application/xml";
-            _request.Timeout = 90000;
-            _request.Method = "POST";
-            _asyncException = null;
-            _request.ContentLength = src.Length;
-            if (auth != null)
-                auth.AddAuthorization(_request.Headers);
-
             int reqnum = WebUtil.RequestNumber++;
+            try
+            {
+                _request = (HttpWebRequest)WebRequest.Create(buildUri());
+                _request.ContentType = "application/xml";
+                _request.Timeout = 90000;
+                _request.Method = "POST";
+                _asyncException = null;
+                _request.ContentLength = src.Length;
+                if (auth != null)
+                    auth.AddAuthorization(_request.Headers);
+            }
+            catch (Exception e)
+            {
+                m_log.WarnFormat("[REST]: AsyncPOST {0} failed with exception {1} {2}",
+                                _request.RequestUri, e.Message, e.StackTrace);
+                return;
+            }
+
             try
             {
                 using (Stream dst = _request.GetRequestStream())

+ 2 - 8
OpenSim/Framework/Util.cs

@@ -1318,11 +1318,8 @@ namespace OpenSim.Framework
             if(String.IsNullOrWhiteSpace(dnsAddress))
                 return null;
 
-            if(dnscache.TryGetValue(dnsAddress, out IPAddress ia) && ia != null)
-            {
-                dnscache.AddOrUpdate(dnsAddress, ia, 300);
+            if(dnscache.TryGetValue(dnsAddress, 300000, out IPAddress ia) && ia != null)
                 return ia;
-            }
 
             ia = null;
             // If it is already an IP, don't let GetHostEntry see it
@@ -1386,11 +1383,8 @@ namespace OpenSim.Framework
             if(String.IsNullOrWhiteSpace(hostname))
                 return null;
 
-            if(dnscache.TryGetValue(hostname, out IPAddress ia) && ia != null)
-            {
-                dnscache.AddOrUpdate(hostname, ia, 300);
+            if(dnscache.TryGetValue(hostname, 300000, out IPAddress ia) && ia != null)
                 return getEndPoint(ia, port);
-            }
 
             ia = null;
 

+ 217 - 254
OpenSim/Framework/WebUtil.cs

@@ -196,28 +196,36 @@ namespace OpenSim.Framework
 
             string errorMessage = "unknown error";
             int tickstart = Util.EnvironmentTickCount();
-            int compsize = 0;
-            string strBuffer = null;
-
+            int sendlen = 0;
+            int rcvlen = 0;
+            HttpWebRequest request = null;
             try
             {
-                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+                request = (HttpWebRequest)WebRequest.Create(url);
                 request.Method = method;
                 request.Timeout = timeout;
                 request.KeepAlive = keepalive;
                 request.MaximumAutomaticRedirections = 10;
                 request.ReadWriteTimeout = timeout / 2;
                 request.Headers[OSHeaderRequestID] = reqnum.ToString();
+            }
+            catch (Exception ex)
+            {
+                errorMessage = ex.Message;
+                m_log.Debug("[WEB UTIL]: ServiceOSD error creating request " + ex.Message);
+                return ErrorResponseMap(errorMessage);
+            }
 
+            try
+            {
                 // If there is some input, write it into the request
                 if (data != null)
                 {
-                    strBuffer = OSDParser.SerializeJsonString(data);
-
+                    string strBuffer = OSDParser.SerializeJsonString(data);
                     if (DebugLevel >= 5)
-                        LogOutgoingDetail("SEND", reqnum, strBuffer);
+                        LogOutgoingDetail(method, reqnum, strBuffer);
 
-                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
+                    byte[] buffer = Util.UTF8Getbytes(strBuffer);
 
                     request.ContentType = rpc ? "application/json-rpc" : "application/json";
 
@@ -231,35 +239,25 @@ namespace OpenSim.Framework
                             {
                                 comp.Write(buffer, 0, buffer.Length);
                              }
-                            byte[] buf = ms.ToArray();
-
-                            request.ContentLength = buf.Length;   //Count bytes to send
-                            compsize = buf.Length;
-                            using (Stream requestStream = request.GetRequestStream())
-                                requestStream.Write(buf, 0, (int)buf.Length);
+                            buffer = ms.ToArray();
                         }
                     }
-                    else
-                    {
-                        compsize = buffer.Length;
 
-                        request.ContentLength = buffer.Length;   //Count bytes to send
-                        using (Stream requestStream = request.GetRequestStream())
-                            requestStream.Write(buffer, 0, buffer.Length);         //Send it
-                    }
+                    sendlen = buffer.Length;
+                    request.ContentLength = buffer.Length;   //Count bytes to send
+                    using (Stream requestStream = request.GetRequestStream())
+                        requestStream.Write(buffer, 0, buffer.Length);         //Send it
                 }
 
                 using (WebResponse response = request.GetResponse())
                 {
-                    using (Stream responseStream = response.GetResponseStream())
+                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                     {
-                        using (StreamReader reader = new StreamReader(responseStream))
-                        {
-                            string responseStr = reader.ReadToEnd();
-                            if (WebUtil.DebugLevel >= 5)
-                                WebUtil.LogResponseDetail(reqnum, responseStr);
-                            return CanonicalizeResults(responseStr);
-                        }
+                        string responseStr = reader.ReadToEnd();
+                        if (WebUtil.DebugLevel >= 5)
+                            WebUtil.LogResponseDetail(reqnum, responseStr);
+                        rcvlen = responseStr.Length;
+                        return CanonicalizeResults(responseStr);
                     }
                 }
             }
@@ -283,16 +281,8 @@ namespace OpenSim.Framework
                 if (tickdiff > LongCallTime)
                 {
                     m_log.InfoFormat(
-                        "[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4} bytes ({5} uncomp): {6}",
-                        reqnum,
-                        method,
-                        url,
-                        tickdiff,
-                        compsize,
-                        strBuffer != null ? strBuffer.Length : 0,
-                        strBuffer != null
-                            ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
-                            : "");
+                        "[WEB UTIL]: ServiceOSD request {0} {1} {2} took {3}ms, {4}/{5}bytes",
+                        reqnum, method, url, tickdiff, sendlen, rcvlen );
                 }
                 else if (DebugLevel >= 4)
                 {
@@ -301,8 +291,7 @@ namespace OpenSim.Framework
                 }
             }
 
-            m_log.DebugFormat(
-                "[LOGHTTP]: JSON-RPC request {0} {1} to {2} FAILED: {3}", reqnum, method, url, errorMessage);
+            m_log.DebugFormat("[LOGHTTP]: JSON request {0} {1} to {2} FAILED: {3}", reqnum, method, url, errorMessage);
 
             return ErrorResponseMap(errorMessage);
         }
@@ -377,22 +366,30 @@ namespace OpenSim.Framework
 
             string errorMessage = "unknown error";
             int tickstart = Util.EnvironmentTickCount();
-            int tickdata = 0;
-            string queryString = null;
+            int sendlen = 0;
+            int rcvlen = 0;
 
+            HttpWebRequest request = null;
             try
             {
-                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
+                request = (HttpWebRequest)HttpWebRequest.Create(url);
                 request.Method = "POST";
                 request.Timeout = timeout;
                 request.KeepAlive = false;
                 request.MaximumAutomaticRedirections = 10;
                 request.ReadWriteTimeout = timeout / 2;
                 request.Headers[OSHeaderRequestID] = reqnum.ToString();
+            }
+            catch (Exception ex)
+            {
+                return ErrorResponseMap(ex.Message);
+            }
 
+            try
+            {
                 if (data != null)
                 {
-                    queryString = BuildQueryString(data);
+                    string queryString = BuildQueryString(data);
 
                     if (DebugLevel >= 5)
                         LogOutgoingDetail("SEND", reqnum, queryString);
@@ -400,29 +397,25 @@ namespace OpenSim.Framework
                     byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString);
 
                     request.ContentLength = buffer.Length;
+                    sendlen = buffer.Length;
                     request.ContentType = "application/x-www-form-urlencoded";
                     using (Stream requestStream = request.GetRequestStream())
                         requestStream.Write(buffer, 0, buffer.Length);
+                    buffer = null;
                 }
 
-                // capture how much time was spent writing, this may seem silly
-                // but with the number concurrent requests, this often blocks
-                tickdata = Util.EnvironmentTickCountSubtract(tickstart);
-
                 using (WebResponse response = request.GetResponse())
                 {
-                    using (Stream responseStream = response.GetResponseStream())
+                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                     {
-                        using (StreamReader reader = new StreamReader(responseStream))
-                        {
-                            string responseStr = reader.ReadToEnd();
-                            if (WebUtil.DebugLevel >= 5)
-                                WebUtil.LogResponseDetail(reqnum, responseStr);
-                            OSD responseOSD = OSDParser.Deserialize(responseStr);
-
-                            if (responseOSD.Type == OSDType.Map)
-                                return (OSDMap)responseOSD;
-                        }
+                        string responseStr = reader.ReadToEnd();
+                        rcvlen = responseStr.Length;
+                        if (WebUtil.DebugLevel >= 5)
+                            WebUtil.LogResponseDetail(reqnum, responseStr);
+                        OSD responseOSD = OSDParser.Deserialize(responseStr);
+
+                        if (responseOSD.Type == OSDType.Map)
+                            return (OSDMap)responseOSD;
                     }
                 }
             }
@@ -445,16 +438,13 @@ namespace OpenSim.Framework
                 if (tickdiff > LongCallTime)
                 {
                     m_log.InfoFormat(
-                        "[LOGHTTP]: Slow ServiceForm request {0} '{1}' to {2} took {3}ms, {4}ms writing, {5}",
-                        reqnum, method, url, tickdiff, tickdata,
-                        queryString != null
-                            ? (queryString.Length > MaxRequestDiagLength) ? queryString.Remove(MaxRequestDiagLength) : queryString
-                            : "");
+                        "[LOGHTTP]: Slow ServiceForm request {0} '{1}' to {2} took {3}ms, {4}/{5}bytes",
+                        reqnum, method, url, tickdiff, sendlen, rcvlen);
                 }
                 else if (DebugLevel >= 4)
                 {
-                    m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
-                        reqnum, tickdiff, tickdata);
+                    m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
+                        reqnum, tickdiff);
                 }
             }
 
@@ -779,14 +769,13 @@ namespace OpenSim.Framework
 
             Type type = typeof(TRequest);
 
-            WebRequest request = WebRequest.Create(requestUrl);
-            HttpWebRequest ht = (HttpWebRequest)request;
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
 
             if (auth != null)
-                auth.AddAuthorization(ht.Headers);
+                auth.AddAuthorization(request.Headers);
 
-            if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
-                ht.ServicePoint.ConnectionLimit = maxConnections;
+            if (maxConnections > 0 && request.ServicePoint.ConnectionLimit < maxConnections)
+                request.ServicePoint.ConnectionLimit = maxConnections;
 
             TResponse deserial = default(TResponse);
 
@@ -971,29 +960,33 @@ namespace OpenSim.Framework
                     reqnum, verb, requestUrl);
 
             int tickstart = Util.EnvironmentTickCount();
-            int tickdata = 0;
-
-            WebRequest request = WebRequest.Create(requestUrl);
-            request.Method = verb;
-            if (timeoutsecs > 0)
-                request.Timeout = timeoutsecs * 1000;
-            if(!keepalive && request is HttpWebRequest)
-                ((HttpWebRequest)request).KeepAlive = false;
-
-            if (auth != null)
-                auth.AddAuthorization(request.Headers);
 
-            string respstring = String.Empty;
-
-            int tickset = Util.EnvironmentTickCountSubtract(tickstart);
-
-            if ((verb == "POST") || (verb == "PUT"))
+            HttpWebRequest request = null;
+            try
             {
+                request = (HttpWebRequest)WebRequest.Create(requestUrl);
+                request.Method = verb;
+                request.AllowWriteStreamBuffering = false;
+                if (timeoutsecs > 0)
+                    request.Timeout = timeoutsecs * 1000;
+                if(!keepalive)
+                    request.KeepAlive = false;
+                if (auth != null)
+                    auth.AddAuthorization(request.Headers);
                 request.ContentType = "application/x-www-form-urlencoded";
+            }
+            catch (Exception e)
+            {
+                m_log.InfoFormat("[FORMS]: Error creating {0} request to : {1}. Request: {2}", verb, requestUrl, e.Message);
+                throw e;
+            }
 
+            int sendlen = 0;
+            if (obj.Length > 0 && (verb == "POST") || (verb == "PUT"))
+            {
                 byte[] data = Util.UTF8NBGetbytes(obj);
-                int length = data.Length;
-                request.ContentLength = length;
+                sendlen = data.Length;
+                request.ContentLength = sendlen;
 
                 if (WebUtil.DebugLevel >= 5)
                     WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
@@ -1001,63 +994,49 @@ namespace OpenSim.Framework
                 try
                 {
                     using(Stream requestStream = request.GetRequestStream())
-                        requestStream.Write(data, 0, length);
+                        requestStream.Write(data, 0, sendlen);
                 }
                 catch (Exception e)
                 {
-                    m_log.InfoFormat("[FORMS]: Error sending request to {0}: {1}. Request: {2}", requestUrl, e.Message,
-                        obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
+                    m_log.InfoFormat("[FORMS]: Error sending {0} request to: {1}. {2}", verb,requestUrl, e.Message);
                     throw e;
                 }
-                finally
-                {
-                    // capture how much time was spent writing
-                    tickdata = Util.EnvironmentTickCountSubtract(tickstart);
-                    data = null;
-                }
             }
 
+            int rcvlen = 0;
+            string respstring = String.Empty;
             try
             {
                 using (WebResponse resp = request.GetResponse())
                 {
                     if (resp.ContentLength != 0)
                     {
-                        using (Stream respStream = resp.GetResponseStream())
-                            using (StreamReader reader = new StreamReader(respStream))
-                                respstring = reader.ReadToEnd();
+                        using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
+                            respstring = reader.ReadToEnd();
+                        rcvlen = respstring.Length;
                     }
                 }
             }
             catch (Exception e)
             {
-                m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}. Request: {2}", requestUrl, e.Message,
-                    obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
+                m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}.", requestUrl, e.Message);
                 throw e;
             }
 
             int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
             if (tickdiff > WebUtil.LongCallTime)
             {
-                m_log.InfoFormat(
-                    "[FORMS]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}",
-                    reqnum,
-                    verb,
-                    requestUrl,
-                    tickdiff,
-                    tickset,
-                    tickdata,
-                    obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
+                m_log.InfoFormat("[FORMS]: request {0} {1} {2} took {3}ms, {4)/{5}bytes",
+                    reqnum, verb, requestUrl, tickdiff, sendlen, rcvlen);
             }
             else if (WebUtil.DebugLevel >= 4)
             {
-                m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
-                    reqnum, tickdiff, tickdata);
+                m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
+                    reqnum, tickdiff);
+                if (WebUtil.DebugLevel >= 5)
+                    WebUtil.LogResponseDetail(reqnum, respstring);
             }
 
-            if (WebUtil.DebugLevel >= 5)
-                WebUtil.LogResponseDetail(reqnum, respstring);
-
             return respstring;
         }
 
@@ -1078,23 +1057,28 @@ namespace OpenSim.Framework
 
             int tickstart = Util.EnvironmentTickCount();
 
-            WebRequest request = WebRequest.Create(requestUrl);
-            request.Method = "POST";
-            if (timeoutsecs > 0)
-                request.Timeout = timeoutsecs * 1000;
-            if (!keepalive && request is HttpWebRequest)
-                ((HttpWebRequest)request).KeepAlive = false;
-
-            if (auth != null)
-                auth.AddAuthorization(request.Headers);
-
-            string respstring = String.Empty;
-
-            request.ContentType = "application/x-www-form-urlencoded";
+            HttpWebRequest request = null;
+            try
+            {
+                request = (HttpWebRequest)WebRequest.Create(requestUrl);
+                request.Method = "POST";
+                if (timeoutsecs > 0)
+                    request.Timeout = timeoutsecs * 1000;
+                if (!keepalive)
+                    request.KeepAlive = false;
+                if (auth != null)
+                    auth.AddAuthorization(request.Headers);
+                request.ContentType = "application/x-www-form-urlencoded";
+            }
+            catch (Exception e)
+            {
+                m_log.InfoFormat("[FORMS]: Error creating POST request to {0}: {1}", requestUrl, e.Message);
+                throw e;
+            }
 
             byte[] data = Util.UTF8NBGetbytes(obj);
-            int length = data.Length;
-            request.ContentLength = length;
+            int sendlen = data.Length;
+            request.ContentLength = sendlen;
 
             if (WebUtil.DebugLevel >= 5)
                 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
@@ -1102,16 +1086,17 @@ namespace OpenSim.Framework
             try
             {
                 using (Stream requestStream = request.GetRequestStream())
-                    requestStream.Write(data, 0, length);
+                    requestStream.Write(data, 0, sendlen);
                 data = null;
             }
             catch (Exception e)
             {
-                m_log.InfoFormat("[FORMS]: Error sending request to {0}: {1}. Request: {2}", requestUrl, e.Message,
-                    obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
+                m_log.InfoFormat("[FORMS]: Error sending POST request to {0}: {1}", requestUrl, e.Message);
                 throw e;
             }
 
+            string respstring = String.Empty;
+            int rcvlen = 0;
             try
             {
                 using (WebResponse resp = request.GetResponse())
@@ -1126,30 +1111,24 @@ namespace OpenSim.Framework
             }
             catch (Exception e)
             {
-                m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}. Request: {2}", requestUrl, e.Message,
-                    obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
+                m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}", requestUrl, e.Message);
                 throw e;
             }
 
             int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
             if (tickdiff > WebUtil.LongCallTime)
             {
-                m_log.InfoFormat(
-                    "[FORMS]: Slow request {0} POST {1} took {2}ms {3}",
-                    reqnum,
-                    requestUrl,
-                    tickdiff,
-                    obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
+                m_log.InfoFormat("[FORMS]: request {0} POST {1} took {2}ms {3}/{4}bytes",
+                    reqnum, requestUrl, tickdiff, sendlen, rcvlen);
             }
             else if (WebUtil.DebugLevel >= 4)
             {
                 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
                     reqnum, tickdiff);
+                if (WebUtil.DebugLevel >= 5)
+                    WebUtil.LogResponseDetail(reqnum, respstring);
             }
 
-            if (WebUtil.DebugLevel >= 5)
-                WebUtil.LogResponseDetail(reqnum, respstring);
-
             return respstring;
         }
     }
@@ -1240,25 +1219,34 @@ namespace OpenSim.Framework
                     reqnum, verb, requestUrl);
 
             int tickstart = Util.EnvironmentTickCount();
-            int tickdata = 0;
 
-            Type type = typeof(TRequest);
             TResponse deserial = default(TResponse);
 
-            WebRequest request = WebRequest.Create(requestUrl);
-            HttpWebRequest ht = (HttpWebRequest)request;
+            HttpWebRequest request = null;
+            try
+            {
+                request = (HttpWebRequest)WebRequest.Create(requestUrl);
 
-            if (auth != null)
-                auth.AddAuthorization(ht.Headers);
+                if (auth != null)
+                    auth.AddAuthorization(request.Headers);
 
-            if (pTimeout != 0)
-                request.Timeout = pTimeout;
+                if (pTimeout != 0)
+                    request.Timeout = pTimeout;
 
-            if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
-                ht.ServicePoint.ConnectionLimit = maxConnections;
+                if (maxConnections > 0 && request.ServicePoint.ConnectionLimit < maxConnections)
+                    request.ServicePoint.ConnectionLimit = maxConnections;
 
-            request.Method = verb;
-            MemoryStream buffer = null;
+                request.AllowWriteStreamBuffering = false;
+                request.Method = verb;
+            }
+            catch (Exception e)
+            {
+                m_log.DebugFormat("[SynchronousRestObjectRequester]: Exception in creating request {0} {1}: {2}{3}",
+                    verb, requestUrl, e.Message, e.StackTrace);
+                return deserial;
+            }
+
+            int sendlen = 0;
 
             try
             {
@@ -1271,130 +1259,105 @@ namespace OpenSim.Framework
                     using (MemoryStream ms = new MemoryStream())
                     using (XmlWriter writer = XmlWriter.Create(ms, settings))
                     {
-                        XmlSerializer serializer = new XmlSerializer(type);
+                        XmlSerializer serializer = new XmlSerializer(typeof(TRequest));
                         serializer.Serialize(writer, obj);
                         writer.Flush();
                         data = ms.ToArray();
                     }
 
-                    int length = data.Length;
-                    request.ContentLength = length;
+                    sendlen = data.Length;
+                    request.ContentLength = sendlen;
 
                     if (WebUtil.DebugLevel >= 5)
                         WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
 
-                    try
-                    {
-                        using (Stream requestStream = request.GetRequestStream())
-                            requestStream.Write(data, 0, length);
-                    }
-                    catch (Exception e)
-                    {
-                        m_log.DebugFormat(
-                            "[SynchronousRestObjectRequester]: Exception in making request {0} {1}: {2}{3}",
-                            verb, requestUrl, e.Message, e.StackTrace);
-
-                        return deserial;
-                    }
-                    finally
-                    {
-                        // capture how much time was spent writing
-                        tickdata = Util.EnvironmentTickCountSubtract(tickstart);
-                    }
+                    using (Stream requestStream = request.GetRequestStream())
+                        requestStream.Write(data, 0, sendlen);
+                    data = null;
                 }
+            }
+            catch (Exception e)
+            {
+                m_log.DebugFormat(
+                    "[SynchronousRestObjectRequester]: Exception in making request {0} {1}: {2}{3}",
+                    verb, requestUrl, e.Message, e.StackTrace);
 
-                try
+                return deserial;
+            }
+
+
+            int rcvlen = 0;
+            try
+            {
+                using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
                 {
-                    using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
+                    if (resp.ContentLength != 0)
                     {
-                        if (resp.ContentLength != 0)
-                        {
-                            using (Stream respStream = resp.GetResponseStream())
-                            {
-                                deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(
-                                    reqnum, respStream, resp.ContentLength);
-                            }
-                        }
-                        else
+                        rcvlen = (int)resp.ContentLength;
+                        using (Stream respStream = resp.GetResponseStream())
                         {
-                            m_log.DebugFormat(
-                                "[SynchronousRestObjectRequester]: Oops! no content found in response stream from {0} {1}",
-                                verb, requestUrl);
+                            deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(
+                                reqnum, respStream, resp.ContentLength);
                         }
                     }
-                }
-                catch (WebException e)
-                {
-                    using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
+                    else
                     {
-                        if (hwr != null)
-                        {
-                            if (hwr.StatusCode == HttpStatusCode.NotFound)
-                                return deserial;
-
-                            if (hwr.StatusCode == HttpStatusCode.Unauthorized)
-                            {
-                                m_log.ErrorFormat("[SynchronousRestObjectRequester]: Web request {0} requires authentication",
-                                    requestUrl);
-                            }
-                            else
-                            {
-                                m_log.WarnFormat("[SynchronousRestObjectRequester]: Web request {0} returned error: {1}",
-                                    requestUrl, hwr.StatusCode);
-                            }
-                        }
-                        else
-                            m_log.ErrorFormat(
-                                "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} {3}",
-                                verb, requestUrl, typeof(TResponse).ToString(), e.Message);
-
-                       return deserial;
+                        m_log.DebugFormat("[SynchronousRestObjectRequester]: Oops! no content found in response stream from {0} {1}",
+                            verb, requestUrl);
                     }
                 }
-                catch (System.InvalidOperationException)
-                {
-                    // This is what happens when there is invalid XML
-                    m_log.DebugFormat(
-                        "[SynchronousRestObjectRequester]: Invalid XML from {0} {1} {2}",
-                        verb, requestUrl, typeof(TResponse).ToString());
-                }
-                catch (Exception e)
-                {
-                    m_log.Debug(string.Format(
-                        "[SynchronousRestObjectRequester]: Exception on response from {0} {1} ",
-                        verb, requestUrl), e);
-                }
-
-                int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
-                if (tickdiff > WebUtil.LongCallTime)
+            }
+            catch (WebException e)
+            {
+                using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
                 {
-                    string originalRequest = null;
-
-                    if (buffer != null)
+                    if (hwr != null)
                     {
-                        originalRequest = Encoding.UTF8.GetString(buffer.ToArray());
+                        if (hwr.StatusCode == HttpStatusCode.NotFound)
+                            return deserial;
 
-                        if (originalRequest.Length > WebUtil.MaxRequestDiagLength)
-                            originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength);
+                        if (hwr.StatusCode == HttpStatusCode.Unauthorized)
+                        {
+                            m_log.ErrorFormat("[SynchronousRestObjectRequester]: Web request {0} requires authentication",
+                                requestUrl);
+                        }
+                        else
+                        {
+                            m_log.WarnFormat("[SynchronousRestObjectRequester]: Web request {0} returned error: {1}",
+                                requestUrl, hwr.StatusCode);
+                        }
                     }
+                    else
+                        m_log.ErrorFormat(
+                            "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} {3}",
+                            verb, requestUrl, typeof(TResponse).ToString(), e.Message);
 
-                    m_log.InfoFormat(
-                        "[LOGHTTP]: Slow SynchronousRestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
-                        reqnum, verb, requestUrl, tickdiff, tickdata,
-                        originalRequest);
-                }
-                else if (WebUtil.DebugLevel >= 4)
-                {
-                    m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
-                        reqnum, tickdiff, tickdata);
+                    return deserial;
                 }
             }
-            finally
+            catch (System.InvalidOperationException)
+            {
+                // This is what happens when there is invalid XML
+                m_log.DebugFormat("[SynchronousRestObjectRequester]: Invalid XML from {0} {1} {2}",
+                    verb, requestUrl, typeof(TResponse).ToString());
+            }
+            catch (Exception e)
             {
-                if (buffer != null)
-                    buffer.Dispose();
+                m_log.DebugFormat("[SynchronousRestObjectRequester]: Exception on response from {0} {1}: {2}",
+                    verb, requestUrl, e.Message);
             }
 
+            int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
+            if (tickdiff > WebUtil.LongCallTime)
+            {
+                m_log.InfoFormat("[LOGHTTP]: Slow SynchronousRestObject request {0} {1} to {2} took {3}ms, {4}/{5}bytes",
+                    reqnum, verb, requestUrl, tickdiff, sendlen, rcvlen);
+            }
+            else if (WebUtil.DebugLevel >= 4)
+            {
+                m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
+                    reqnum, tickdiff);
+            }
             return deserial;
         }
     }

+ 4 - 13
OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs

@@ -46,7 +46,6 @@ using OpenSim.Region.Framework.Interfaces;
 using OpenSim.Region.Framework.Scenes;
 using OpenSim.Services.Interfaces;
 
-
 using AssetLandmark = OpenSim.Framework.AssetLandmark;
 using Caps = OpenSim.Framework.Capabilities.Caps;
 using PermissionMask = OpenSim.Framework.PermissionMask;
@@ -314,9 +313,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
         // LLClientView Only
         public delegate void BinaryGenericMessage(Object sender, string method, byte[][] args);
 
-        /// <summary>Used to adjust Sun Orbit values so Linden based viewers properly position sun</summary>
-        private const float m_sunPainDaHalfOrbitalCutoff = 4.712388980384689858f;
-
         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
         private static string LogHeader = "[LLCLIENTVIEW]";
 
@@ -361,7 +357,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
         /// </value>
         protected List<uint> m_killRecord;
 
-//        protected HashSet<uint> m_attachmentsSent;
+        //protected HashSet<uint> m_attachmentsSent;
 
         private bool m_SendLogoutPacketWhenClosing = true;
 
@@ -477,7 +473,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
         /// <summary>
         /// Used to synchronise threads when client is being closed.
         /// </summary>
-        public Object CloseSyncLock { get; private set; }
+        public object CloseSyncLock { get;} = new object();
 
         public bool IsLoggingOut { get; set; }
 
@@ -507,7 +503,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
         {
 //            DebugPacketLevel = 1;
 
-            CloseSyncLock = new Object();
             SelectedObjects = new List<uint>();
 
             RegisterInterface<IClientIM>(this);
@@ -610,7 +605,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                 OutPacket(disable, ThrottleOutPacketType.Unknown);
             }
 
-
             // Fire the callback for this connection closing
             if (OnConnectionClosed != null)
                 OnConnectionClosed(this);
@@ -7938,9 +7932,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
 
         #endregion
 
-        /// <summary>
-        /// This is a different way of processing packets then ProcessInPacket
-        /// </summary>
         protected virtual void RegisterLocalPacketHandlers()
         {
             AddLocalPacketHandler(PacketType.LogoutRequest, HandleLogout);
@@ -13160,9 +13151,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
 
         public bool TryGet<T>(out T iface)
         {
-            if (m_clientInterfaces.ContainsKey(typeof(T)))
+            if(m_clientInterfaces.TryGetValue(typeof(T), out object o))
             {
-                iface = (T)m_clientInterfaces[typeof(T)];
+                iface = (T)o;
                 return true;
             }
             iface = default(T);

+ 1 - 13
OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs

@@ -262,19 +262,7 @@ namespace OpenMetaverse
 
                 try
                 {
-                    // This udp socket flag is not supported under mono,
-                    // so we'll catch the exception and continue
-                    // Try does not protect some mono versions on mac
-                    // this may work now on all platforms
-                    //if(Util.IsWindows())
-                    //{
-                        m_udpSocket.IOControl(SIO_UDP_CONNRESET, new byte[] { 0 }, null);
-                        m_log.Debug("[UDPBASE]: SIO_UDP_CONNRESET flag set");
-                    //}               
-                    //else
-                    //{
-                    //    m_log.Debug("[UDPBASE]: SIO_UDP_CONNRESET flag not supported on this platform, ignoring");
-                    //}
+                    m_udpSocket.IOControl(SIO_UDP_CONNRESET, new byte[] { 0 }, null);
                 }
                 catch
                 {

+ 1 - 3
OpenSim/Region/CoreModules/Avatar/BakedTextures/XBakesModule.cs

@@ -114,9 +114,7 @@ namespace OpenSim.Region.CoreModules.Avatar.BakedTextures
             using (RestClient rc = new RestClient(m_URL))
             {
                 List<WearableCacheItem> ret = new List<WearableCacheItem>();
-                rc.AddResourcePath("bakes");
-                rc.AddResourcePath(id.ToString());
-
+                rc.AddResourcePath("bakes/" + id.ToString());
                 rc.RequestMethod = "GET";
 
                 try

+ 8 - 10
OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs

@@ -73,7 +73,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
         internal IJ2KDecoder m_imgDecoder;
 
         // caches per rendering 
-        private Dictionary<string, warp_Texture> m_warpTextures = new Dictionary<string, warp_Texture>();
+        private Dictionary<UUID, warp_Texture> m_warpTextures = new Dictionary<UUID, warp_Texture>();
         private Dictionary<UUID, int> m_colors = new Dictionary<UUID, int>();
 
         private IConfigSource m_config;
@@ -518,13 +518,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
                 if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero)
                 {
                     // Try fetchinng the asset
-                    byte[] sculptAsset = m_scene.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
+                    AssetBase sculptAsset = m_scene.AssetService.Get(omvPrim.Sculpt.SculptTexture.ToString());
                     if (sculptAsset != null)
                     {
                         // Is it a mesh?
                         if (omvPrim.Sculpt.Type == SculptType.Mesh)
                         {
-                            AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
+                            AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset.Data);
                             FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, lod, out renderMesh);
                             meshAsset = null;
                         }
@@ -532,7 +532,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
                         {
                             if (m_imgDecoder != null)
                             {
-                                Image sculpt = m_imgDecoder.DecodeToImage(sculptAsset);
+                                Image sculpt = m_imgDecoder.DecodeToImage(sculptAsset.Data);
                                 if (sculpt != null)
                                 {
                                     renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, lod);
@@ -784,17 +784,15 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
             warp_Texture ret = null;
             if (id == UUID.Zero)
                 return ret;
-
-            if (m_warpTextures.TryGetValue(id.ToString(), out ret))
+            if (m_warpTextures.TryGetValue(id, out ret))
                 return ret;
 
-            byte[] asset = m_scene.AssetService.GetData(id.ToString());
-
+            AssetBase asset = m_scene.AssetService.Get(id.ToString());
             if (asset != null)
             {
                 try
                 {
-                    using (Bitmap img = (Bitmap)m_imgDecoder.DecodeToImage(asset))
+                    using (Bitmap img = (Bitmap)m_imgDecoder.DecodeToImage(asset.Data))
                         ret = new warp_Texture(img, 8); // reduce textures size to 256x256
                 }
                 catch (Exception e)
@@ -806,7 +804,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
                 m_log.WarnFormat("[Warp3D]: missing texture {0} data for prim {1} at {2}",
                     id.ToString(), sop.Name, sop.GetWorldPosition().ToString());
 
-            m_warpTextures[id.ToString()] = ret;
+            m_warpTextures[id] = ret;
             return ret;
         }
 

+ 1 - 3
OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs

@@ -832,9 +832,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
 
             if (httpserver == null || httpserver.Length == 0)
             {
-                uint x = 0, y = 0;
-                Util.RegionHandleToWorldLoc(regionhandle, out x, out y);
-
+                Util.RegionHandleToWorldLoc(regionhandle, out uint x, out uint y);
                 GridRegion mreg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
 
                 if (mreg != null)

+ 8 - 1
OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs

@@ -263,7 +263,14 @@ namespace OpenSim.Services.Connectors.Simulation
                 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
                 args["context"] = ctx.Pack();
 
-                OSDMap result = WebUtil.PutToServiceCompressed(uri, args, timeout);
+                OSDMap result;
+                if (ctx.OutboundVersion >= 0.3)
+                {
+                    result = WebUtil.PutToServiceCompressed(uri, args, timeout);
+                    return result["Success"].AsBoolean();
+                }
+
+                result = WebUtil.PutToServiceCompressed(uri, args, timeout);
                 if (result["Success"].AsBoolean())
                     return true;
                 if(ctx.OutboundVersion < 0.2)