aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorUbitUmarov2018-12-02 16:17:23 +0000
committerUbitUmarov2018-12-02 16:17:23 +0000
commitca754b0156a63411730be1d6472a3c4c51c7efc3 (patch)
tree83fb157380735c44861ddd82ae92aec56caffa40 /OpenSim/Framework
parentsimplify a bit (diff)
downloadopensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.zip
opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.tar.gz
opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.tar.bz2
opensim-SC-ca754b0156a63411730be1d6472a3c4c51c7efc3.tar.xz
avoid a data copy
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs112
1 files changed, 60 insertions, 52 deletions
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