diff options
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs | 85 |
1 files changed, 69 insertions, 16 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index caf0e98..fefcb20 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | ||
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Text; | 32 | using System.Text; |
32 | using HttpServer; | 33 | using HttpServer; |
@@ -44,6 +45,24 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
44 | public readonly IHttpRequest Request; | 45 | public readonly IHttpRequest Request; |
45 | public readonly int RequestTime; | 46 | public readonly int RequestTime; |
46 | public readonly UUID RequestID; | 47 | public readonly UUID RequestID; |
48 | public int contextHash; | ||
49 | |||
50 | private void GenContextHash() | ||
51 | { | ||
52 | Random rnd = new Random(); | ||
53 | contextHash = 0; | ||
54 | if (Request.Headers["remote_addr"] != null) | ||
55 | contextHash = (Request.Headers["remote_addr"]).GetHashCode() << 16; | ||
56 | else | ||
57 | contextHash = rnd.Next() << 16; | ||
58 | if (Request.Headers["remote_port"] != null) | ||
59 | { | ||
60 | string[] strPorts = Request.Headers["remote_port"].Split(new char[] { ',' }); | ||
61 | contextHash += Int32.Parse(strPorts[0]); | ||
62 | } | ||
63 | else | ||
64 | contextHash += rnd.Next() & 0xffff; | ||
65 | } | ||
47 | 66 | ||
48 | public PollServiceHttpRequest( | 67 | public PollServiceHttpRequest( |
49 | PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) | 68 | PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) |
@@ -53,6 +72,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
53 | Request = pRequest; | 72 | Request = pRequest; |
54 | RequestTime = System.Environment.TickCount; | 73 | RequestTime = System.Environment.TickCount; |
55 | RequestID = UUID.Random(); | 74 | RequestID = UUID.Random(); |
75 | GenContextHash(); | ||
56 | } | 76 | } |
57 | 77 | ||
58 | internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) | 78 | internal void DoHTTPGruntWork(BaseHttpServer server, Hashtable responsedata) |
@@ -62,36 +82,69 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
62 | 82 | ||
63 | byte[] buffer = server.DoHTTPGruntWork(responsedata, response); | 83 | byte[] buffer = server.DoHTTPGruntWork(responsedata, response); |
64 | 84 | ||
85 | if(Request.Body.CanRead) | ||
86 | Request.Body.Dispose(); | ||
87 | |||
65 | response.SendChunked = false; | 88 | response.SendChunked = false; |
66 | response.ContentLength64 = buffer.Length; | 89 | response.ContentLength64 = buffer.Length; |
67 | response.ContentEncoding = Encoding.UTF8; | 90 | response.ContentEncoding = Encoding.UTF8; |
91 | response.ReuseContext = false; | ||
68 | 92 | ||
69 | try | 93 | try |
70 | { | 94 | { |
71 | response.OutputStream.Write(buffer, 0, buffer.Length); | 95 | response.OutputStream.Write(buffer, 0, buffer.Length); |
96 | response.OutputStream.Flush(); | ||
97 | response.Send(); | ||
98 | buffer = null; | ||
72 | } | 99 | } |
73 | catch (Exception ex) | 100 | catch (Exception ex) |
74 | { | 101 | { |
75 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex); | 102 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", ex); |
76 | } | 103 | } |
77 | finally | 104 | |
105 | PollServiceArgs.RequestsHandled++; | ||
106 | } | ||
107 | |||
108 | internal void DoHTTPstop(BaseHttpServer server) | ||
109 | { | ||
110 | OSHttpResponse response | ||
111 | = new OSHttpResponse(new HttpResponse(HttpContext, Request), HttpContext); | ||
112 | |||
113 | if(Request.Body.CanRead) | ||
114 | Request.Body.Dispose(); | ||
115 | |||
116 | response.SendChunked = false; | ||
117 | response.ContentLength64 = 0; | ||
118 | response.ContentEncoding = Encoding.UTF8; | ||
119 | response.ReuseContext = false; | ||
120 | response.KeepAlive = false; | ||
121 | response.SendChunked = false; | ||
122 | response.StatusCode = 503; | ||
123 | |||
124 | try | ||
78 | { | 125 | { |
79 | //response.OutputStream.Close(); | 126 | response.OutputStream.Flush(); |
80 | try | 127 | response.Send(); |
81 | { | ||
82 | response.OutputStream.Flush(); | ||
83 | response.Send(); | ||
84 | |||
85 | //if (!response.KeepAlive && response.ReuseContext) | ||
86 | // response.FreeContext(); | ||
87 | } | ||
88 | catch (Exception e) | ||
89 | { | ||
90 | m_log.Warn("[POLL SERVICE WORKER THREAD]: Error ", e); | ||
91 | } | ||
92 | |||
93 | PollServiceArgs.RequestsHandled++; | ||
94 | } | 128 | } |
129 | catch (Exception e) | ||
130 | { | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | class PollServiceHttpRequestComparer : IEqualityComparer<PollServiceHttpRequest> | ||
136 | { | ||
137 | public bool Equals(PollServiceHttpRequest b1, PollServiceHttpRequest b2) | ||
138 | { | ||
139 | if (b1.contextHash != b2.contextHash) | ||
140 | return false; | ||
141 | bool b = Object.ReferenceEquals(b1.HttpContext, b2.HttpContext); | ||
142 | return b; | ||
143 | } | ||
144 | |||
145 | public int GetHashCode(PollServiceHttpRequest b2) | ||
146 | { | ||
147 | return (int)b2.contextHash; | ||
95 | } | 148 | } |
96 | } | 149 | } |
97 | } \ No newline at end of file | 150 | } \ No newline at end of file |