mongrel 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/COPYING +504 -0
  2. data/LICENSE +504 -0
  3. data/README +117 -0
  4. data/Rakefile +30 -0
  5. data/doc/rdoc/classes/Mongrel.html +144 -0
  6. data/doc/rdoc/classes/Mongrel/Error404Handler.html +171 -0
  7. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000023.html +18 -0
  8. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000024.html +18 -0
  9. data/doc/rdoc/classes/Mongrel/HeaderOut.html +167 -0
  10. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000013.html +18 -0
  11. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000014.html +21 -0
  12. data/doc/rdoc/classes/Mongrel/HttpHandler.html +159 -0
  13. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000019.html +17 -0
  14. data/doc/rdoc/classes/Mongrel/HttpParser.html +271 -0
  15. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000001.html +28 -0
  16. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000002.html +29 -0
  17. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000003.html +29 -0
  18. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000004.html +41 -0
  19. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000005.html +27 -0
  20. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000006.html +27 -0
  21. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000007.html +28 -0
  22. data/doc/rdoc/classes/Mongrel/HttpRequest.html +177 -0
  23. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000025.html +30 -0
  24. data/doc/rdoc/classes/Mongrel/HttpResponse.html +202 -0
  25. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000020.html +21 -0
  26. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000021.html +20 -0
  27. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000022.html +25 -0
  28. data/doc/rdoc/classes/Mongrel/HttpServer.html +336 -0
  29. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000008.html +26 -0
  30. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000009.html +58 -0
  31. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000010.html +22 -0
  32. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000011.html +18 -0
  33. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000012.html +18 -0
  34. data/doc/rdoc/classes/Mongrel/URIClassifier.html +257 -0
  35. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000015.html +54 -0
  36. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000016.html +50 -0
  37. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000017.html +36 -0
  38. data/doc/rdoc/classes/Mongrel/URIClassifier.src/M000018.html +73 -0
  39. data/doc/rdoc/created.rid +1 -0
  40. data/doc/rdoc/files/COPYING.html +756 -0
  41. data/doc/rdoc/files/LICENSE.html +756 -0
  42. data/doc/rdoc/files/README.html +273 -0
  43. data/doc/rdoc/files/ext/http11/http11_c.html +101 -0
  44. data/doc/rdoc/files/lib/mongrel_rb.html +111 -0
  45. data/doc/rdoc/fr_class_index.html +35 -0
  46. data/doc/rdoc/fr_file_index.html +31 -0
  47. data/doc/rdoc/fr_method_index.html +51 -0
  48. data/doc/rdoc/index.html +24 -0
  49. data/doc/rdoc/rdoc-style.css +208 -0
  50. data/examples/camping/blog.rb +300 -0
  51. data/examples/camping/tepee.rb +168 -0
  52. data/examples/simpletest.rb +16 -0
  53. data/examples/webrick_compare.rb +20 -0
  54. data/ext/http11/MANIFEST +0 -0
  55. data/ext/http11/ext_help.h +14 -0
  56. data/ext/http11/extconf.rb +6 -0
  57. data/ext/http11/http11.c +436 -0
  58. data/ext/http11/http11_parser.c +918 -0
  59. data/ext/http11/http11_parser.h +37 -0
  60. data/ext/http11/tst.h +40 -0
  61. data/ext/http11/tst_cleanup.c +24 -0
  62. data/ext/http11/tst_delete.c +146 -0
  63. data/ext/http11/tst_grow_node_free_list.c +38 -0
  64. data/ext/http11/tst_init.c +41 -0
  65. data/ext/http11/tst_insert.c +192 -0
  66. data/ext/http11/tst_search.c +54 -0
  67. data/lib/mongrel.rb +298 -0
  68. data/setup.rb +1360 -0
  69. data/test/test_http11.rb +38 -0
  70. data/test/test_response.rb +44 -0
  71. data/test/test_uriclassifier.rb +104 -0
  72. data/test/test_ws.rb +33 -0
  73. data/tools/rakehelp.rb +99 -0
  74. metadata +132 -0
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (Mongrel::HttpResponse)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 108</span>
14
+ 108: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">socket</span>)
15
+ 109: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">socket</span>
16
+ 110: <span class="ruby-ivar">@body</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
17
+ 111: <span class="ruby-ivar">@status</span> = <span class="ruby-value">404</span>
18
+ 112: <span class="ruby-ivar">@header</span> = <span class="ruby-constant">HeaderOut</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>)
19
+ 113: <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>start (Mongrel::HttpResponse)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 115</span>
14
+ 115: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>(<span class="ruby-identifier">status</span>=<span class="ruby-value">200</span>)
15
+ 116: <span class="ruby-ivar">@status</span> = <span class="ruby-identifier">status</span>
16
+ 117: <span class="ruby-keyword kw">yield</span> <span class="ruby-ivar">@header</span>, <span class="ruby-ivar">@body</span>
17
+ 118: <span class="ruby-identifier">finished</span>
18
+ 119: <span class="ruby-keyword kw">end</span></pre>
19
+ </body>
20
+ </html>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>finished (Mongrel::HttpResponse)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 121</span>
14
+ 121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">finished</span>
15
+ 122: <span class="ruby-ivar">@header</span>.<span class="ruby-identifier">out</span>.<span class="ruby-identifier">rewind</span>
16
+ 123: <span class="ruby-ivar">@body</span>.<span class="ruby-identifier">rewind</span>
17
+ 124:
18
+ 125: <span class="ruby-comment cmt"># connection: close is also added to ensure that the client does not pipeline.</span>
19
+ 126: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status]}\r\nContent-Length: #{@body.length}\r\nConnection: close\r\n&quot;</span>)
20
+ 127: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">write</span>(<span class="ruby-ivar">@header</span>.<span class="ruby-identifier">out</span>.<span class="ruby-identifier">read</span>)
21
+ 128: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">write</span>(<span class="ruby-value str">&quot;\r\n&quot;</span>)
22
+ 129: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">write</span>(<span class="ruby-ivar">@body</span>.<span class="ruby-identifier">read</span>)
23
+ 130: <span class="ruby-keyword kw">end</span></pre>
24
+ </body>
25
+ </html>
@@ -0,0 +1,336 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Mongrel::HttpServer</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Mongrel::HttpServer</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/mongrel_rb.html">
59
+ lib/mongrel.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ This is the main driver of <a href="../Mongrel.html">Mongrel</a>, while the
84
+ Mognrel::HttpParser and <a
85
+ href="URIClassifier.html">Mongrel::URIClassifier</a> make up the majority
86
+ of how the server functions. It&#8217;s a very simple class that just has a
87
+ thread accepting connections and a simple <a
88
+ href="HttpServer.html#M000009">HttpServer.process_client</a> function to do
89
+ the heavy lifting with the IO and Ruby.
90
+ </p>
91
+ <p>
92
+ You use it by doing the following:
93
+ </p>
94
+ <pre>
95
+ server = HttpServer.new(&quot;0.0.0.0&quot;, 3000)
96
+ server.register(&quot;/stuff&quot;, MyNifterHandler.new)
97
+ server.run.join
98
+ </pre>
99
+ <p>
100
+ The last line can be just server.run if you don&#8217;t want to join the
101
+ thread used. If you don&#8217;t though Ruby will mysteriously just exit on
102
+ you.
103
+ </p>
104
+ <p>
105
+ Ruby&#8217;s thread implementation is &quot;interesting&quot; to say the
106
+ least. Experiments with <b>many</b> different types of IO processing simply
107
+ cannot make a dent in it. Future releases of <a
108
+ href="../Mongrel.html">Mongrel</a> will find other creative ways to make
109
+ threads faster, but don&#8217;t hold your breath until Ruby 1.9 is actually
110
+ finally useful.
111
+ </p>
112
+
113
+ </div>
114
+
115
+
116
+ </div>
117
+
118
+ <div id="method-list">
119
+ <h3 class="section-bar">Methods</h3>
120
+
121
+ <div class="name-list">
122
+ <a href="#M000008">new</a>&nbsp;&nbsp;
123
+ <a href="#M000009">process_client</a>&nbsp;&nbsp;
124
+ <a href="#M000011">register</a>&nbsp;&nbsp;
125
+ <a href="#M000010">run</a>&nbsp;&nbsp;
126
+ <a href="#M000012">unregister</a>&nbsp;&nbsp;
127
+ </div>
128
+ </div>
129
+
130
+ </div>
131
+
132
+
133
+ <!-- if includes -->
134
+
135
+ <div id="section">
136
+
137
+
138
+ <div id="constants-list">
139
+ <h3 class="section-bar">Constants</h3>
140
+
141
+ <div class="name-list">
142
+ <table summary="Constants">
143
+ <tr class="top-aligned-row context-row">
144
+ <td class="context-item-name">ERROR_404_RESPONSE</td>
145
+ <td>=</td>
146
+ <td class="context-item-value">&quot;HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: Mongrel/0.2\r\n\r\nNOT FOUND&quot;</td>
147
+ <td width="3em">&nbsp;</td>
148
+ <td class="context-item-desc">
149
+ The standard empty 404 response for bad requests. Use Error4040Handler for
150
+ custom stuff.
151
+
152
+ </td>
153
+ </tr>
154
+ <tr class="top-aligned-row context-row">
155
+ <td class="context-item-name">ERROR_503_RESPONSE</td>
156
+ <td>=</td>
157
+ <td class="context-item-value">&quot;HTTP/1.1 503 Service Unavailable\r\n\r\nBUSY&quot;</td>
158
+ </tr>
159
+ <tr class="top-aligned-row context-row">
160
+ <td class="context-item-name">CHUNK_SIZE</td>
161
+ <td>=</td>
162
+ <td class="context-item-value">(16 * 1024)</td>
163
+ <td width="3em">&nbsp;</td>
164
+ <td class="context-item-desc">
165
+ The basic max request size we&#8217;ll try to read.
166
+
167
+ </td>
168
+ </tr>
169
+ <tr class="top-aligned-row context-row">
170
+ <td class="context-item-name">PATH_INFO</td>
171
+ <td>=</td>
172
+ <td class="context-item-value">&quot;PATH_INFO&quot;</td>
173
+ </tr>
174
+ <tr class="top-aligned-row context-row">
175
+ <td class="context-item-name">SCRIPT_NAME</td>
176
+ <td>=</td>
177
+ <td class="context-item-value">&quot;SCRIPT_NAME&quot;</td>
178
+ </tr>
179
+ </table>
180
+ </div>
181
+ </div>
182
+
183
+
184
+
185
+ <div id="attribute-list">
186
+ <h3 class="section-bar">Attributes</h3>
187
+
188
+ <div class="name-list">
189
+ <table>
190
+ <tr class="top-aligned-row context-row">
191
+ <td class="context-item-name">acceptor</td>
192
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
193
+ <td class="context-item-desc"></td>
194
+ </tr>
195
+ </table>
196
+ </div>
197
+ </div>
198
+
199
+
200
+
201
+ <!-- if method_list -->
202
+ <div id="methods">
203
+ <h3 class="section-bar">Public Class methods</h3>
204
+
205
+ <div id="method-M000008" class="method-detail">
206
+ <a name="M000008"></a>
207
+
208
+ <div class="method-heading">
209
+ <a href="HttpServer.src/M000008.html" target="Code" class="method-signature"
210
+ onclick="popupCode('HttpServer.src/M000008.html');return false;">
211
+ <span class="method-name">new</span><span class="method-args">(host, port, num_processors=20)</span>
212
+ </a>
213
+ </div>
214
+
215
+ <div class="method-description">
216
+ <p>
217
+ Creates a working server on host:port (strange things happen if port
218
+ isn&#8217;t a Number). Use HttpServer::run to start the server.
219
+ </p>
220
+ <p>
221
+ The num_processors variable has varying affects on how requests are
222
+ processed. You&#8216;d think adding more processing threads (processors)
223
+ would make the server faster, but that&#8217;s just not true. There&#8217;s
224
+ actually an effect of how Ruby does threads such that the more processors
225
+ waiting on the request queue, the slower the system is to handle each
226
+ request. But, the lower the number of processors the fewer concurrent
227
+ responses the server can make.
228
+ </p>
229
+ <p>
230
+ 20 is the default number of processors and is based on experimentation on a
231
+ few systems. If you find that you overload <a
232
+ href="../Mongrel.html">Mongrel</a> too much try changing it higher. If you
233
+ find that responses are way too slow try lowering it (after you&#8217;ve
234
+ tuned your stuff of course). Future versions of <a
235
+ href="../Mongrel.html">Mongrel</a> will make this more dynamic (hopefully).
236
+ </p>
237
+ </div>
238
+ </div>
239
+
240
+ <h3 class="section-bar">Public Instance methods</h3>
241
+
242
+ <div id="method-M000009" class="method-detail">
243
+ <a name="M000009"></a>
244
+
245
+ <div class="method-heading">
246
+ <a href="HttpServer.src/M000009.html" target="Code" class="method-signature"
247
+ onclick="popupCode('HttpServer.src/M000009.html');return false;">
248
+ <span class="method-name">process_client</span><span class="method-args">(client)</span>
249
+ </a>
250
+ </div>
251
+
252
+ <div class="method-description">
253
+ <p>
254
+ Does the majority of the IO processing. It has been written in Ruby using
255
+ about 7 different IO processing strategies and no matter how it&#8217;s
256
+ done the performance just does not improve. Ruby&#8217;s use of select to
257
+ implement threads means that it will most likely never improve, so the only
258
+ remaining approach is to write all or some of this function in C. That will
259
+ be the focus of future releases.
260
+ </p>
261
+ </div>
262
+ </div>
263
+
264
+ <div id="method-M000011" class="method-detail">
265
+ <a name="M000011"></a>
266
+
267
+ <div class="method-heading">
268
+ <a href="HttpServer.src/M000011.html" target="Code" class="method-signature"
269
+ onclick="popupCode('HttpServer.src/M000011.html');return false;">
270
+ <span class="method-name">register</span><span class="method-args">(uri, handler)</span>
271
+ </a>
272
+ </div>
273
+
274
+ <div class="method-description">
275
+ <p>
276
+ Simply registers a handler with the internal <a
277
+ href="URIClassifier.html">URIClassifier</a>. When the URI is found in the
278
+ prefix of a request then your handler&#8217;s HttpHandler::process method
279
+ is called. See <a
280
+ href="URIClassifier.html#M000016">Mongrel::URIClassifier#register</a> for
281
+ more information.
282
+ </p>
283
+ </div>
284
+ </div>
285
+
286
+ <div id="method-M000010" class="method-detail">
287
+ <a name="M000010"></a>
288
+
289
+ <div class="method-heading">
290
+ <a href="HttpServer.src/M000010.html" target="Code" class="method-signature"
291
+ onclick="popupCode('HttpServer.src/M000010.html');return false;">
292
+ <span class="method-name">run</span><span class="method-args">()</span>
293
+ </a>
294
+ </div>
295
+
296
+ <div class="method-description">
297
+ <p>
298
+ Runs the thing. It returns the thread used so you can &quot;join&quot; it.
299
+ You can also access the HttpServer::acceptor attribute to get the thread
300
+ later.
301
+ </p>
302
+ </div>
303
+ </div>
304
+
305
+ <div id="method-M000012" class="method-detail">
306
+ <a name="M000012"></a>
307
+
308
+ <div class="method-heading">
309
+ <a href="HttpServer.src/M000012.html" target="Code" class="method-signature"
310
+ onclick="popupCode('HttpServer.src/M000012.html');return false;">
311
+ <span class="method-name">unregister</span><span class="method-args">(uri)</span>
312
+ </a>
313
+ </div>
314
+
315
+ <div class="method-description">
316
+ <p>
317
+ Removes any handler registered at the given URI. See <a
318
+ href="URIClassifier.html#M000017">Mongrel::URIClassifier#unregister</a> for
319
+ more information.
320
+ </p>
321
+ </div>
322
+ </div>
323
+
324
+
325
+ </div>
326
+
327
+
328
+ </div>
329
+
330
+
331
+ <div id="validator-badges">
332
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
333
+ </div>
334
+
335
+ </body>
336
+ </html>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>new (Mongrel::HttpServer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 211</span>
14
+ 211: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">num_processors</span>=<span class="ruby-value">20</span>)
15
+ 212: <span class="ruby-ivar">@socket</span> = <span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
16
+ 213: <span class="ruby-ivar">@classifier</span> = <span class="ruby-constant">URIClassifier</span>.<span class="ruby-identifier">new</span>
17
+ 214: <span class="ruby-ivar">@req_queue</span> = <span class="ruby-constant">Queue</span>.<span class="ruby-identifier">new</span>
18
+ 215: <span class="ruby-identifier">num_processors</span>.<span class="ruby-identifier">times</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
19
+ 216: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">client</span> = <span class="ruby-ivar">@req_queue</span>.<span class="ruby-identifier">deq</span>
20
+ 217: <span class="ruby-identifier">process_client</span>(<span class="ruby-identifier">client</span>)
21
+ 218: <span class="ruby-keyword kw">end</span>
22
+ 219: <span class="ruby-keyword kw">end</span>
23
+ 220: }
24
+ 221: <span class="ruby-keyword kw">end</span></pre>
25
+ </body>
26
+ </html>
@@ -0,0 +1,58 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>process_client (Mongrel::HttpServer)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre> <span class="ruby-comment cmt"># File lib/mongrel.rb, line 230</span>
14
+ 230: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_client</span>(<span class="ruby-identifier">client</span>)
15
+ 231: <span class="ruby-keyword kw">begin</span>
16
+ 232: <span class="ruby-identifier">parser</span> = <span class="ruby-constant">HttpParser</span>.<span class="ruby-identifier">new</span>
17
+ 233: <span class="ruby-identifier">params</span> = {}
18
+ 234: <span class="ruby-identifier">data</span> = <span class="ruby-identifier">client</span>.<span class="ruby-identifier">readpartial</span>(<span class="ruby-constant">CHUNK_SIZE</span>)
19
+ 235:
20
+ 236: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
21
+ 237: <span class="ruby-identifier">nread</span> = <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">execute</span>(<span class="ruby-identifier">params</span>, <span class="ruby-identifier">data</span>)
22
+ 238: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">finished?</span>
23
+ 239: <span class="ruby-identifier">script_name</span>, <span class="ruby-identifier">path_info</span>, <span class="ruby-identifier">handler</span> = <span class="ruby-ivar">@classifier</span>.<span class="ruby-identifier">resolve</span>(<span class="ruby-identifier">params</span>[<span class="ruby-constant">PATH_INFO</span>])
24
+ 240:
25
+ 241: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>
26
+ 242: <span class="ruby-identifier">params</span>[<span class="ruby-constant">PATH_INFO</span>] = <span class="ruby-identifier">path_info</span>
27
+ 243: <span class="ruby-identifier">params</span>[<span class="ruby-constant">SCRIPT_NAME</span>] = <span class="ruby-identifier">script_name</span>
28
+ 244:
29
+ 245: <span class="ruby-identifier">request</span> = <span class="ruby-constant">HttpRequest</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">params</span>, <span class="ruby-identifier">data</span>[<span class="ruby-identifier">nread</span> <span class="ruby-operator">...</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">length</span>], <span class="ruby-identifier">client</span>)
30
+ 246: <span class="ruby-identifier">response</span> = <span class="ruby-constant">HttpResponse</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">client</span>)
31
+ 247: <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">process</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">response</span>)
32
+ 248: <span class="ruby-keyword kw">else</span>
33
+ 249: <span class="ruby-identifier">client</span>.<span class="ruby-identifier">write</span>(<span class="ruby-constant">ERROR_404_RESPONSE</span>)
34
+ 250: <span class="ruby-keyword kw">end</span>
35
+ 251:
36
+ 252: <span class="ruby-keyword kw">break</span>
37
+ 253: <span class="ruby-keyword kw">else</span>
38
+ 254: <span class="ruby-comment cmt"># gotta stream and read again until we can get the parser to be character safe</span>
39
+ 255: <span class="ruby-comment cmt"># TODO: make this more efficient since this means we're parsing a lot repeatedly</span>
40
+ 256: <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">reset</span>
41
+ 257: <span class="ruby-identifier">data</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">client</span>.<span class="ruby-identifier">readpartial</span>(<span class="ruby-constant">CHUNK_SIZE</span>)
42
+ 258: <span class="ruby-keyword kw">end</span>
43
+ 259: <span class="ruby-keyword kw">end</span>
44
+ 260: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">EOFError</span>
45
+ 261: <span class="ruby-comment cmt"># ignored</span>
46
+ 262: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNRESET</span>
47
+ 263: <span class="ruby-comment cmt"># ignored</span>
48
+ 264: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EPIPE</span>
49
+ 265: <span class="ruby-comment cmt"># ignored</span>
50
+ 266: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">details</span>
51
+ 267: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;ERROR(#{details.class}): #{details}&quot;</span>
52
+ 268: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">details</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>)
53
+ 269: <span class="ruby-keyword kw">ensure</span>
54
+ 270: <span class="ruby-identifier">client</span>.<span class="ruby-identifier">close</span>
55
+ 271: <span class="ruby-keyword kw">end</span>
56
+ 272: <span class="ruby-keyword kw">end</span></pre>
57
+ </body>
58
+ </html>