diff options
author | UbitUmarov | 2018-12-02 16:17:23 +0000 |
---|---|---|
committer | UbitUmarov | 2018-12-02 16:17:23 +0000 |
commit | ca754b0156a63411730be1d6472a3c4c51c7efc3 (patch) | |
tree | 83fb157380735c44861ddd82ae92aec56caffa40 | |
parent | simplify a bit (diff) | |
download | opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.zip opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.tar.gz opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.tar.bz2 opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.tar.xz |
avoid a data copy
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs | 25 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs | 112 |
2 files changed, 69 insertions, 68 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs b/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs index 92608a6..ef64999 100644 --- a/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs | |||
@@ -139,22 +139,21 @@ namespace OpenSim.Capabilities.Handlers | |||
139 | // if(type != AssetType.Mesh && type != AssetType.Texture) | 139 | // if(type != AssetType.Mesh && type != AssetType.Texture) |
140 | // m_log.Warn("[GETASSETS]: type: " + query); | 140 | // m_log.Warn("[GETASSETS]: type: " + query); |
141 | 141 | ||
142 | responsedata["content_type"] = asset.Metadata.ContentType; | ||
143 | responsedata["bin_response_data"] = asset.Data; | ||
144 | responsedata["int_bytes"] = asset.Data.Length; | ||
145 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; | ||
146 | |||
142 | string range = String.Empty; | 147 | string range = String.Empty; |
143 | if (((Hashtable)request["headers"])["range"] != null) | 148 | if (((Hashtable)request["headers"])["range"] != null) |
144 | range = (string)((Hashtable)request["headers"])["range"]; | 149 | range = (string)((Hashtable)request["headers"])["range"]; |
145 | else if (((Hashtable)request["headers"])["Range"] != null) | 150 | else if (((Hashtable)request["headers"])["Range"] != null) |
146 | range = (string)((Hashtable)request["headers"])["Range"]; | 151 | range = (string)((Hashtable)request["headers"])["Range"]; |
147 | 152 | else | |
148 | responsedata["content_type"] = asset.Metadata.ContentType; | 153 | return responsedata; // full asset |
149 | 154 | ||
150 | if (String.IsNullOrEmpty(range)) | 155 | if (String.IsNullOrEmpty(range)) |
151 | { | 156 | return responsedata; // full asset |
152 | // full asset | ||
153 | responsedata["bin_response_data"] = asset.Data; | ||
154 | responsedata["int_bytes"] = asset.Data.Length; | ||
155 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; | ||
156 | return responsedata; | ||
157 | } | ||
158 | 157 | ||
159 | // range request | 158 | // range request |
160 | int start, end; | 159 | int start, end; |
@@ -181,18 +180,12 @@ namespace OpenSim.Capabilities.Handlers | |||
181 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length); | 180 | headers["Content-Range"] = String.Format("bytes {0}-{1}/{2}", start, end, asset.Data.Length); |
182 | responsedata["headers"] = headers; | 181 | responsedata["headers"] = headers; |
183 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; | 182 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.PartialContent; |
184 | 183 | responsedata["bin_start"] = start; | |
185 | byte[] d = new byte[len]; | ||
186 | Array.Copy(asset.Data, start, d, 0, len); | ||
187 | responsedata["bin_response_data"] = d; | ||
188 | responsedata["int_bytes"] = len; | 184 | responsedata["int_bytes"] = len; |
189 | return responsedata; | 185 | return responsedata; |
190 | } | 186 | } |
191 | 187 | ||
192 | m_log.Warn("[GETASSETS]: Failed to parse a range, sending full asset: " + assetStr); | 188 | m_log.Warn("[GETASSETS]: Failed to parse a range, sending full asset: " + assetStr); |
193 | responsedata["bin_response_data"] = asset.Data; | ||
194 | responsedata["int_bytes"] = asset.Data.Length; | ||
195 | responsedata["int_response_code"] = (int)System.Net.HttpStatusCode.OK; | ||
196 | return responsedata; | 189 | return responsedata; |
197 | } | 190 | } |
198 | } | 191 | } |
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index cf4f835..66fd2c6 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs | |||
@@ -81,44 +81,18 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
81 | 81 | ||
82 | internal void DoHTTPGruntWork(Hashtable responsedata) | 82 | internal void DoHTTPGruntWork(Hashtable responsedata) |
83 | { | 83 | { |
84 | OSHttpResponse response | 84 | if (Request.Body.CanRead) |
85 | = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); | ||
86 | |||
87 | byte[] buffer = srvDoHTTPGruntWork(responsedata, response); | ||
88 | |||
89 | if(Request.Body.CanRead) | ||
90 | Request.Body.Dispose(); | 85 | Request.Body.Dispose(); |
91 | 86 | ||
92 | response.SendChunked = false; | 87 | OSHttpResponse response |
93 | response.ContentLength64 = buffer.Length; | 88 | = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); |
94 | |||
95 | try | ||
96 | { | ||
97 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
98 | response.Send(); | ||
99 | buffer = null; | ||
100 | } | ||
101 | catch (Exception ex) | ||
102 | { | ||
103 | if(ex is System.Net.Sockets.SocketException) | ||
104 | { | ||
105 | // only mute connection reset by peer so we are not totally blind for now | ||
106 | if(((System.Net.Sockets.SocketException)ex).SocketErrorCode != System.Net.Sockets.SocketError.ConnectionReset) | ||
107 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex); | ||
108 | } | ||
109 | else | ||
110 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex); | ||
111 | } | ||
112 | |||
113 | PollServiceArgs.RequestsHandled++; | ||
114 | } | ||
115 | 89 | ||
116 | internal byte[] srvDoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response) | 90 | int responsecode = 200; |
117 | { | ||
118 | int responsecode; | ||
119 | string responseString = String.Empty; | 91 | string responseString = String.Empty; |
120 | byte[] responseBytes = null; | ||
121 | string contentType; | 92 | string contentType; |
93 | byte[] buffer = null; | ||
94 | int rangeStart = 0; | ||
95 | int rangeLen = -1; | ||
122 | 96 | ||
123 | if (responsedata == null) | 97 | if (responsedata == null) |
124 | { | 98 | { |
@@ -132,12 +106,23 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
132 | try | 106 | try |
133 | { | 107 | { |
134 | //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); | 108 | //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response"); |
135 | responsecode = (int)responsedata["int_response_code"]; | 109 | if(responsedata["int_response_code"] != null) |
110 | responsecode = (int)responsedata["int_response_code"]; | ||
136 | 111 | ||
137 | if (responsedata["bin_response_data"] != null) | 112 | if (responsedata["bin_response_data"] != null) |
138 | responseBytes = (byte[])responsedata["bin_response_data"]; | 113 | { |
114 | buffer = (byte[])responsedata["bin_response_data"]; | ||
115 | responsedata["bin_response_data"] = null; | ||
116 | |||
117 | if (responsedata["bin_start"] != null) | ||
118 | rangeStart = (int)responsedata["bin_start"]; | ||
119 | |||
120 | if (responsedata["int_bytes"] != null) | ||
121 | rangeLen = (int)responsedata["int_bytes"]; | ||
122 | } | ||
139 | else | 123 | else |
140 | responseString = (string)responsedata["str_response_string"]; | 124 | responseString = (string)responsedata["str_response_string"]; |
125 | |||
141 | contentType = (string)responsedata["content_type"]; | 126 | contentType = (string)responsedata["content_type"]; |
142 | if (responseString == null) | 127 | if (responseString == null) |
143 | responseString = String.Empty; | 128 | responseString = String.Empty; |
@@ -159,7 +144,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
159 | { | 144 | { |
160 | response.ProtocolVersion = (string)responsedata["http_protocol_version"]; | 145 | response.ProtocolVersion = (string)responsedata["http_protocol_version"]; |
161 | } | 146 | } |
162 | |||
163 | if (responsedata.ContainsKey("keepalive")) | 147 | if (responsedata.ContainsKey("keepalive")) |
164 | { | 148 | { |
165 | bool keepalive = (bool)responsedata["keepalive"]; | 149 | bool keepalive = (bool)responsedata["keepalive"]; |
@@ -170,13 +154,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
170 | if (responsedata.ContainsKey("access_control_allow_origin")) | 154 | if (responsedata.ContainsKey("access_control_allow_origin")) |
171 | response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]); | 155 | response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]); |
172 | 156 | ||
173 | if (string.IsNullOrEmpty(contentType)) | ||
174 | { | ||
175 | contentType = "text/html"; | ||
176 | } | ||
177 | |||
178 | // The client ignores anything but 200 here for web login, so ensure that this is 200 for that | ||
179 | |||
180 | response.StatusCode = responsecode; | 157 | response.StatusCode = responsecode; |
181 | 158 | ||
182 | if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) | 159 | if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) |
@@ -184,7 +161,11 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
184 | response.RedirectLocation = (string)responsedata["str_redirect_location"]; | 161 | response.RedirectLocation = (string)responsedata["str_redirect_location"]; |
185 | } | 162 | } |
186 | 163 | ||
187 | response.AddHeader("Content-Type", contentType); | 164 | if (string.IsNullOrEmpty(contentType)) |
165 | response.AddHeader("Content-Type", "text/html"); | ||
166 | else | ||
167 | response.AddHeader("Content-Type", contentType); | ||
168 | |||
188 | if (responsedata.ContainsKey("headers")) | 169 | if (responsedata.ContainsKey("headers")) |
189 | { | 170 | { |
190 | Hashtable headerdata = (Hashtable)responsedata["headers"]; | 171 | Hashtable headerdata = (Hashtable)responsedata["headers"]; |
@@ -193,13 +174,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
193 | response.AddHeader(header, headerdata[header].ToString()); | 174 | response.AddHeader(header, headerdata[header].ToString()); |
194 | } | 175 | } |
195 | 176 | ||
196 | byte[] buffer; | 177 | if(buffer == null) |
197 | |||
198 | if (responseBytes != null) | ||
199 | { | ||
200 | buffer = responseBytes; | ||
201 | } | ||
202 | else | ||
203 | { | 178 | { |
204 | if (!(contentType.Contains("image") | 179 | if (!(contentType.Contains("image") |
205 | || contentType.Contains("x-shockwave-flash") | 180 | || contentType.Contains("x-shockwave-flash") |
@@ -217,8 +192,41 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
217 | response.ContentEncoding = Encoding.UTF8; | 192 | response.ContentEncoding = Encoding.UTF8; |
218 | } | 193 | } |
219 | 194 | ||
220 | return buffer; | 195 | if (rangeStart < 0 || rangeStart > buffer.Length) |
196 | rangeStart = 0; | ||
197 | |||
198 | if (rangeLen < 0) | ||
199 | rangeLen = buffer.Length; | ||
200 | else if (rangeLen + rangeStart > buffer.Length) | ||
201 | rangeLen = buffer.Length - rangeStart; | ||
202 | |||
203 | response.SendChunked = false; | ||
204 | response.ContentLength64 = rangeLen; | ||
205 | |||
206 | try | ||
207 | { | ||
208 | if(rangeLen > 0) | ||
209 | response.OutputStream.Write(buffer, rangeStart, rangeLen); | ||
210 | |||
211 | buffer = null; | ||
212 | |||
213 | response.Send(); | ||
214 | } | ||
215 | catch (Exception ex) | ||
216 | { | ||
217 | if(ex is System.Net.Sockets.SocketException) | ||
218 | { | ||
219 | // only mute connection reset by peer so we are not totally blind for now | ||
220 | if(((System.Net.Sockets.SocketException)ex).SocketErrorCode != System.Net.Sockets.SocketError.ConnectionReset) | ||
221 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex); | ||
222 | } | ||
223 | else | ||
224 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex); | ||
225 | } | ||
226 | |||
227 | PollServiceArgs.RequestsHandled++; | ||
221 | } | 228 | } |
229 | |||
222 | internal void DoHTTPstop() | 230 | internal void DoHTTPstop() |
223 | { | 231 | { |
224 | OSHttpResponse response | 232 | OSHttpResponse response |