ruby-lsapi 1.7 → 1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/lsapi/lsapilib.c +2 -2
  2. data/ext/lsapi/lsruby.c +82 -37
  3. metadata +1 -1
data/ext/lsapi/lsapilib.c CHANGED
@@ -81,7 +81,7 @@ static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] =
81
81
  "CONTENT_LENGTH", "HTTP_COOKIE", "HTTP_COOKIE2",
82
82
  "HTTP_HOST", "HTTP_PRAGMA",
83
83
  "HTTP_REFERER", "HTTP_USER_AGENT",
84
- "HTTP_CACHE_CTRL",
84
+ "HTTP_CACHE_CONTROL",
85
85
  "HTTP_IF_MODIFIED_SINCE", "HTTP_IF_MATCH",
86
86
  "HTTP_IF_NONE_MATCH",
87
87
  "HTTP_IF_RANGE",
@@ -94,7 +94,7 @@ static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] =
94
94
  };
95
95
 
96
96
  static int CGI_HEADER_LEN[H_TRANSFER_ENCODING+1] =
97
- { 11, 19, 20, 20, 18, 15, 12, 14, 11, 12, 9, 11, 12, 15, 15,
97
+ { 11, 19, 20, 20, 18, 15, 12, 14, 11, 12, 9, 11, 12, 15, 18,
98
98
  22, 13, 18, 13, 24, 14, 10, 20, 8, 22 };
99
99
 
100
100
  static void lsapi_sigpipe( int sig )
data/ext/lsapi/lsruby.c CHANGED
@@ -43,13 +43,14 @@ static VALUE cLSAPI;
43
43
  static VALUE s_req = Qnil;
44
44
  static lsapi_data * s_req_data;
45
45
 
46
- static int s_children = 0;
47
- static int s_cur_children = 0;
46
+ static int s_children = 0;
47
+ static int s_cur_children = 0;
48
48
  static int s_req_processed = 0;
49
- static int s_max_reqs = 1000000;
49
+ static int s_max_reqs = 1000000;
50
50
  static int s_max_idle_secs = 60;
51
- static int s_listenFd = -1;
52
- static int s_ppid = 0;
51
+ static int s_listenFd = -1;
52
+ static int s_ppid = 0;
53
+ static int s_max_grp_idle_secs = 0;
53
54
 
54
55
  static void lsapi_ruby_setenv(const char *name, const char *value)
55
56
  {
@@ -117,21 +118,41 @@ void lsapi_sigchild( int signal )
117
118
  {
118
119
  break;
119
120
  }
120
- --s_cur_children;
121
+ --s_cur_children;
121
122
  }
122
123
 
123
124
  }
124
125
 
126
+ static int lsapi_ruby_accept( int fdListen )
127
+ {
128
+ int fd;
129
+ int nodelay = 1;
130
+ socklen_t len;
131
+ char achPeer[128];
132
+
133
+ len = sizeof( achPeer );
134
+ fd = accept( s_listenFd, (struct sockaddr *)&achPeer, &len );
135
+ if ( fd != -1 )
136
+ {
137
+ if (((struct sockaddr *)&achPeer)->sa_family == AF_INET )
138
+ {
139
+ setsockopt( fd, IPPROTO_TCP, TCP_NODELAY,
140
+ (char *)&nodelay, sizeof(nodelay));
141
+ }
142
+ }
143
+ return fd;
144
+
145
+ }
146
+
125
147
  static int lsapi_fork_child()
126
148
  {
127
- struct sigaction act, old_term, old_quit, old_int, old_usr1, old_child;
149
+ struct sigaction act, old_term, old_quit, old_int,
150
+ old_usr1, old_child;
128
151
 
129
- char achPeer[128];
130
- socklen_t len;
131
- int nodelay = 1;
132
- fd_set readfds;
133
- struct timeval timeout;
134
- int ret;
152
+ int wait_secs = 0;
153
+ int ret;
154
+ fd_set readfds;
155
+ struct timeval timeout;
135
156
 
136
157
  setsid();
137
158
 
@@ -165,10 +186,10 @@ static int lsapi_fork_child()
165
186
 
166
187
  FD_ZERO( &readfds );
167
188
  FD_SET( s_listenFd, &readfds );
168
- timeout.tv_sec = 0; timeout.tv_usec = 100000;
189
+ timeout.tv_sec = 1; timeout.tv_usec = 0;
169
190
  if ((ret = rb_thread_select(s_listenFd+1, &readfds, NULL, NULL, &timeout)) == 1 )
170
191
  {
171
- if ( s_cur_children >= s_children )
192
+ if ( s_cur_children >= 0 )
172
193
  {
173
194
  usleep( 10 );
174
195
  FD_ZERO( &readfds );
@@ -181,17 +202,26 @@ static int lsapi_fork_child()
181
202
  else if ( ret == -1 )
182
203
  break;
183
204
  else
184
- continue;
185
- len = sizeof( achPeer );
186
- g_req.m_fd = accept( s_listenFd,
187
- (struct sockaddr *)&achPeer, &len );
188
- if ( g_req.m_fd != -1 )
189
205
  {
190
- if (((struct sockaddr *)&achPeer)->sa_family == AF_INET )
206
+ if (s_ppid && (kill(s_ppid, 0) == -1)&&(errno == ESRCH))
207
+ break;
208
+ if (s_max_grp_idle_secs)
191
209
  {
192
- setsockopt(g_req.m_fd, IPPROTO_TCP, TCP_NODELAY,
193
- (char *)&nodelay, sizeof(nodelay));
210
+ if ( s_cur_children <= 0 )
211
+ {
212
+ ++wait_secs;
213
+ if ( wait_secs > s_max_grp_idle_secs )
214
+ return -1;
215
+ }
216
+ else
217
+ wait_secs = 0;
194
218
  }
219
+ continue;
220
+ }
221
+
222
+ g_req.m_fd = lsapi_ruby_accept( s_listenFd );
223
+ if ( g_req.m_fd != -1 )
224
+ {
195
225
  int pid = fork();
196
226
  if ( !pid )
197
227
  {
@@ -233,16 +263,14 @@ static int lsapi_fork_child()
233
263
 
234
264
  static VALUE lsapi_s_accept( VALUE self )
235
265
  {
236
- // lsapi_data * req_data;
237
- // VALUE req;
238
- fd_set readfds;
239
- int fd;
240
- int ret;
241
- int wait_secs;
242
- struct timeval timeout;
266
+ int fd;
267
+ int ret;
268
+ int wait_secs;
269
+ fd_set readfds;
270
+ struct timeval timeout;
243
271
 
244
272
  LSAPI_Finish_r( &g_req );
245
- if ( s_children )
273
+ if ( s_children > 1)
246
274
  {
247
275
  if ( s_listenFd != -1 )
248
276
  if ( lsapi_fork_child() == -1 )
@@ -263,11 +291,6 @@ static VALUE lsapi_s_accept( VALUE self )
263
291
  wait_secs = 0;
264
292
  while( LSAPI_IsRunning() )
265
293
  {
266
- if ( s_ppid )
267
- {
268
- if ((kill(s_ppid, 0) == -1)&&(errno == ESRCH))
269
- return Qnil;
270
- }
271
294
  FD_ZERO( &readfds );
272
295
  FD_SET( fd, &readfds );
273
296
  timeout.tv_sec = 1;
@@ -277,6 +300,16 @@ static VALUE lsapi_s_accept( VALUE self )
277
300
  ++wait_secs;
278
301
  if (( s_max_idle_secs > 0 )&&(wait_secs >= s_max_idle_secs ))
279
302
  return Qnil;
303
+ if ( s_ppid &&(kill(s_ppid, 0) == -1)&&(errno == ESRCH))
304
+ return Qnil;
305
+ }
306
+ else if ( fd == s_listenFd )
307
+ {
308
+ g_req.m_fd = lsapi_ruby_accept( s_listenFd );
309
+ if ( g_req.m_fd != -1 )
310
+ {
311
+ break;
312
+ }
280
313
  }
281
314
  else
282
315
  break;
@@ -583,7 +616,7 @@ void Init_lsapi()
583
616
  s_children = atoi( p );
584
617
  unsetenv( "LSAPI_CHILDREN" );
585
618
  }
586
-
619
+
587
620
  p = getenv( "LSAPI_MAX_REQS" );
588
621
  if ( p )
589
622
  {
@@ -601,6 +634,18 @@ void Init_lsapi()
601
634
  unsetenv( "LSAPI_MAX_IDLE" );
602
635
  }
603
636
 
637
+ p = getenv( "LSAPI_PGRP_MAX_IDLE" );
638
+ if ( p )
639
+ {
640
+ s_max_grp_idle_secs = atoi( p );
641
+ unsetenv( "LSAPI_PGRP_MAX_IDLE" );
642
+ }
643
+
644
+ if ( !getenv( "LSAPI_PPID_NO_CHECK" ) )
645
+ s_ppid = getppid();
646
+ else
647
+ unsetenv( "LSAPI_PPID_NO_CHECK" );
648
+
604
649
  orig_stdin = rb_stdin;
605
650
  orig_stdout = rb_stdout;
606
651
  #if RUBY_VERSION_CODE < 180
metadata CHANGED
@@ -3,7 +3,7 @@ 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"
6
+ version: "1.8"
7
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: