ruby-lsapi 1.5 → 1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/lsapi/lsruby.c +26 -18
- metadata +2 -2
data/ext/lsapi/lsruby.c
CHANGED
@@ -45,6 +45,8 @@ static int s_cur_children = 0;
|
|
45
45
|
static int s_req_processed = 0;
|
46
46
|
static int s_max_reqs = 1000;
|
47
47
|
static int s_max_idle_secs = 60;
|
48
|
+
static int s_listenFd = -1;
|
49
|
+
static int s_ppid = 0;
|
48
50
|
|
49
51
|
static void lsapi_ruby_setenv(const char *name, const char *value)
|
50
52
|
{
|
@@ -158,17 +160,17 @@ static int lsapi_fork_child()
|
|
158
160
|
}
|
159
161
|
|
160
162
|
FD_ZERO( &readfds );
|
161
|
-
FD_SET(
|
163
|
+
FD_SET( s_listenFd, &readfds );
|
162
164
|
timeout.tv_sec = 0; timeout.tv_usec = 100000;
|
163
|
-
if ((ret = rb_thread_select(
|
165
|
+
if ((ret = rb_thread_select(s_listenFd+1, &readfds, NULL, NULL, &timeout)) == 1 )
|
164
166
|
{
|
165
167
|
if ( s_cur_children >= s_children )
|
166
168
|
{
|
167
169
|
usleep( 10 );
|
168
170
|
FD_ZERO( &readfds );
|
169
|
-
FD_SET(
|
171
|
+
FD_SET( s_listenFd, &readfds );
|
170
172
|
timeout.tv_sec = 0; timeout.tv_usec = 0;
|
171
|
-
if ( select(
|
173
|
+
if ( select(s_listenFd+1, &readfds, NULL, NULL, &timeout) == 0 )
|
172
174
|
continue;
|
173
175
|
}
|
174
176
|
}
|
@@ -177,7 +179,7 @@ static int lsapi_fork_child()
|
|
177
179
|
else
|
178
180
|
continue;
|
179
181
|
len = sizeof( achPeer );
|
180
|
-
g_req.m_fd = accept(
|
182
|
+
g_req.m_fd = accept( s_listenFd,
|
181
183
|
(struct sockaddr *)&achPeer, &len );
|
182
184
|
if ( g_req.m_fd != -1 )
|
183
185
|
{
|
@@ -189,9 +191,8 @@ static int lsapi_fork_child()
|
|
189
191
|
int pid = fork();
|
190
192
|
if ( !pid )
|
191
193
|
{
|
192
|
-
//close( g_req.m_fdListen );
|
193
|
-
//g_req.m_fdListen = -1;
|
194
194
|
s_children = 0;
|
195
|
+
s_ppid = getppid();
|
195
196
|
|
196
197
|
/* don't catch our signals */
|
197
198
|
sigaction( SIGCHLD, &old_child, 0 );
|
@@ -239,23 +240,30 @@ static VALUE lsapi_s_accept( VALUE self )
|
|
239
240
|
LSAPI_Finish_r( &g_req );
|
240
241
|
if ( s_children )
|
241
242
|
{
|
242
|
-
if (
|
243
|
+
if ( s_listenFd != -1 )
|
243
244
|
if ( lsapi_fork_child() == -1 )
|
244
245
|
return Qnil;
|
245
246
|
}
|
246
|
-
if ( s_req_processed
|
247
|
+
if ( s_req_processed >= s_max_reqs )
|
248
|
+
return Qnil;
|
249
|
+
while( 1 )
|
247
250
|
{
|
248
251
|
if ( g_req.m_fd != -1 )
|
249
252
|
{
|
250
253
|
fd = g_req.m_fd;
|
251
254
|
}
|
252
|
-
else if (
|
253
|
-
fd =
|
255
|
+
else if ( s_listenFd != -1 )
|
256
|
+
fd = s_listenFd;
|
254
257
|
else
|
255
258
|
return Qnil;
|
256
259
|
wait_secs = 0;
|
257
260
|
while( LSAPI_IsRunning() )
|
258
261
|
{
|
262
|
+
if ( s_ppid )
|
263
|
+
{
|
264
|
+
if ((kill(s_ppid, 0) == -1)&&(errno == ESRCH))
|
265
|
+
return Qnil;
|
266
|
+
}
|
259
267
|
FD_ZERO( &readfds );
|
260
268
|
FD_SET( fd, &readfds );
|
261
269
|
timeout.tv_sec = 1;
|
@@ -274,17 +282,14 @@ static VALUE lsapi_s_accept( VALUE self )
|
|
274
282
|
|
275
283
|
if ( !ret )
|
276
284
|
{
|
277
|
-
// req = Data_Make_Struct( self, lsapi_data, lsapi_mark, free, req_data );
|
278
|
-
// s_req = req;
|
279
|
-
// req_data->req = &g_req;
|
280
|
-
// rb_stdin = rb_stdout = req;
|
281
|
-
//#if RUBY_VERSION_CODE < 180
|
282
|
-
// rb_defout = req;
|
283
|
-
//#endif
|
284
285
|
++s_req_processed;
|
285
286
|
setup_cgi_env( s_req_data );
|
286
287
|
return s_req;
|
287
288
|
}
|
289
|
+
else if (( g_req.m_fd == -1 )&&( fd != s_listenFd ))
|
290
|
+
continue;
|
291
|
+
else
|
292
|
+
break;
|
288
293
|
}
|
289
294
|
return Qnil;
|
290
295
|
}
|
@@ -601,6 +606,9 @@ void Init_lsapi()
|
|
601
606
|
|
602
607
|
LSAPI_Init();
|
603
608
|
|
609
|
+
s_listenFd = g_req.m_fdListen;
|
610
|
+
g_req.m_fdListen = -1;
|
611
|
+
|
604
612
|
rb_define_global_function("eval_string_wrap", lsapi_eval_string_wrap, 1);
|
605
613
|
|
606
614
|
cLSAPI = rb_define_class("LSAPI", rb_cObject);
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-lsapi
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "1.
|
7
|
-
date: 2006-
|
6
|
+
version: "1.6"
|
7
|
+
date: 2006-08-22 00:00:00 -04:00
|
8
8
|
summary: A ruby extension for fast communication with LiteSpeed Web Server.
|
9
9
|
require_paths:
|
10
10
|
- lib
|