public
Description: New and ultra-turbo-crazy-fast backend for Thin
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin-turbo.git
Search Repo:
Add some doc and remove some debug code
macournoyer (author)
Fri May 09 13:40:27 -0700 2008
commit  ba8f86c952e337db6e5f079337a1cd7c092151cf
tree    c348a99946698eafbad28868cbb754f4c6e4e470
parent  edab8a1dbcfcd9c70ab912423a69a5f5767dece6
0
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@ New and ultra-turbo-crazy-fast backend for Thin
0
 
0
 === Usage
0
 
0
- thin start -r lib/thin-turbo -b Thin::Backends::Turbo ...
0
+ thin start -r thin-turbo -b Thin::Backends::Turbo ...
0
 
0
 === License
0
 Ruby License, http://www.ruby-lang.org/en/LICENSE.txt.
0
...
1
2
 
 
3
...
 
1
2
3
4
0
@@ -1 +1,2 @@
0
-* BUG: hangs on file upload 1 time out of 2
0
\ No newline at end of file
0
+* BUG: hangs on file upload 1 time out of 2
0
+* disable timeout when calling the Rack app
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
...
53
54
55
56
57
 
 
58
59
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
66
67
68
 
 
69
70
71
72
0
@@ -1,3 +1,16 @@
0
+/* Functions to handle the requesting of a resource, before the Rack application is called.
0
+ * Basically:
0
+ * 1) request_parse is called each time a chunk of data is red from the socket.
0
+ * 3) request_parse then parse the header into c->env, a Ruby hash.
0
+ * 4) When the header is all parsed, the body is stored into c->read_buffer.
0
+ * 5) c->read_buffer is converted into a Ruby class:
0
+ * - StringIO if < BUFFER_MAX_LEN
0
+ * - File if stored in a tempfile
0
+ * 6) The response is processed by calling response_process.
0
+ *
0
+ * Note that c->read_buffer is also used to store the header and then
0
+ * cleared before storing the body.
0
+ */
0
 #include "thin.h"
0
 
0
 static VALUE buffer_to_ruby_obj(buffer_t *buf)
0
@@ -53,7 +66,7 @@ void request_parse(connection_t *c, char *buf, int len)
0
     /* assign env[rack.input] */
0
     rb_hash_aset(c->env, sRackInput, buffer_to_ruby_obj(&c->read_buffer));
0
     
0
- /* call the Rack app in a Ruby green thread */
0
- rb_thread_create(response_process, (void*) c);
0
+ /* call the Rack app */
0
+ response_process(c);
0
   }
0
 }
...
101
102
103
104
 
105
106
107
 
108
109
110
 
111
112
113
...
136
137
138
 
 
139
140
 
 
 
 
 
 
 
...
101
102
103
 
104
105
 
 
106
107
 
 
108
109
110
111
...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
0
@@ -101,13 +101,11 @@ static void response_send_body(connection_t *c, VALUE body)
0
   }
0
 }
0
 
0
-VALUE response_process(connection_t *c)
0
+static VALUE response_run(connection_t *c)
0
 {
0
- /* Call the app to process the request */
0
- c->backend->thread_count++;
0
+ /* Call the app to process the request */
0
   VALUE response = rb_funcall_rescue(c->backend->app, sInternedCall, 1, c->env);
0
- c->backend->thread_count--;
0
-
0
+
0
   if (response == Qundef) {
0
     /* log any error */
0
     rb_funcall(c->backend->obj, rb_intern("log_last_exception"), 0);
0
@@ -136,5 +134,14 @@ VALUE response_process(connection_t *c)
0
     
0
   }
0
   
0
+ c->backend->thread_count--;
0
+
0
   return Qnil;
0
 }
0
+
0
+void response_process(connection_t *c)
0
+{
0
+ c->backend->thread_count++;
0
+ /* call the Rack app in a Ruby green thread */
0
+ rb_thread_create(response_run, (void*) c);
0
+}
...
127
128
129
 
130
131
 
132
133
134
...
127
128
129
130
131
 
132
133
134
135
0
@@ -127,8 +127,9 @@ void connection_error(connection_t *c, const char *msg);
0
 void connection_errno(connection_t *c);
0
 void connection_close(connection_t *connection);
0
 
0
+/* request & response */
0
 void request_parse(connection_t *connection, char *buf, int len);
0
-VALUE response_process(connection_t *connection);
0
+void response_process(connection_t *connection);
0
 
0
 /* connections */
0
 void connections_init(backend_t *backend);
...
7
8
9
10
11
12
13
14
...
7
8
9
 
 
10
11
12
0
@@ -7,8 +7,6 @@ module Rack
0
       def initialize_with_mutex(*args)
0
         @mutex = Mutex.new
0
         initialize_without_mutex(*args)
0
-
0
- puts "using threaded rails"
0
       end
0
       alias_method :initialize_without_mutex, :initialize
0
       alias_method :initialize, :initialize_with_mutex

Comments

    No one has commented yet.