ruby-lsapi 3.5 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/lsapi/extconf.rb +3 -0
- data/ext/lsapi/lsapilib.c +79 -11
- data/ext/lsapi/lsapilib.h +4 -0
- data/ext/lsapi/lsruby.c +39 -7
- metadata +2 -2
data/ext/lsapi/extconf.rb
CHANGED
data/ext/lsapi/lsapilib.c
CHANGED
@@ -75,6 +75,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
75
75
|
static int g_inited = 0;
|
76
76
|
static int g_running = 1;
|
77
77
|
static int s_ppid;
|
78
|
+
static int s_slow_req_msecs = 0;
|
78
79
|
LSAPI_Request g_req = { -1, -1 };
|
79
80
|
|
80
81
|
void Flush_RespBuf_r( LSAPI_Request * pReq );
|
@@ -532,11 +533,14 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen )
|
|
532
533
|
return 0;
|
533
534
|
}
|
534
535
|
|
536
|
+
//OPTIMIZATION
|
537
|
+
static int s_accept_notify = 0;
|
538
|
+
|
535
539
|
static struct lsapi_packet_header ack = {'L', 'S',
|
536
540
|
LSAPI_REQ_RECEIVED, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} };
|
537
|
-
static inline int notify_req_received(
|
541
|
+
static inline int notify_req_received( int fd )
|
538
542
|
{
|
539
|
-
if ( write(
|
543
|
+
if ( write( fd, &ack, LSAPI_PACKET_HEADER_LEN )
|
540
544
|
< LSAPI_PACKET_HEADER_LEN )
|
541
545
|
return -1;
|
542
546
|
return 0;
|
@@ -587,7 +591,11 @@ static int readReq( LSAPI_Request * pReq )
|
|
587
591
|
pReq->m_bufProcessed = packetLen;
|
588
592
|
pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER;
|
589
593
|
|
590
|
-
|
594
|
+
//OPTIMIZATION
|
595
|
+
if ( !s_accept_notify )
|
596
|
+
return notify_req_received( pReq->m_fd );
|
597
|
+
else
|
598
|
+
return 0;
|
591
599
|
}
|
592
600
|
|
593
601
|
|
@@ -699,6 +707,9 @@ int LSAPI_Accept_r( LSAPI_Request * pReq )
|
|
699
707
|
setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY,
|
700
708
|
(char *)&nodelay, sizeof(nodelay));
|
701
709
|
}
|
710
|
+
//OPTIMIZATION
|
711
|
+
if ( s_accept_notify )
|
712
|
+
return notify_req_received( pReq->m_fd );
|
702
713
|
}
|
703
714
|
}
|
704
715
|
else
|
@@ -927,24 +938,36 @@ int LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, int len )
|
|
927
938
|
int bufLen;
|
928
939
|
int toWrite;
|
929
940
|
int packetLen;
|
941
|
+
int skip = 0;
|
930
942
|
|
931
943
|
if ( !pReq || !pBuf || (pReq->m_fd == -1) )
|
932
944
|
return -1;
|
933
|
-
if ( len < pReq->m_pRespBufEnd - pReq->m_pRespBufPos )
|
934
|
-
{
|
935
|
-
memmove( pReq->m_pRespBufPos, pBuf, len );
|
936
|
-
pReq->m_pRespBufPos += len;
|
937
|
-
return len;
|
938
|
-
}
|
939
|
-
|
940
945
|
if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER )
|
941
946
|
{
|
942
947
|
LSAPI_FinalizeRespHeaders_r( pReq );
|
948
|
+
/*
|
949
|
+
if ( *pBuf == '\r' )
|
950
|
+
{
|
951
|
+
++skip;
|
952
|
+
}
|
953
|
+
if ( *pBuf == '\n' )
|
954
|
+
{
|
955
|
+
++skip;
|
956
|
+
}
|
957
|
+
*/
|
943
958
|
}
|
944
959
|
pReq->m_reqState |= LSAPI_ST_RESP_BODY;
|
960
|
+
|
961
|
+
if ( (len - skip) < pReq->m_pRespBufEnd - pReq->m_pRespBufPos )
|
962
|
+
{
|
963
|
+
memmove( pReq->m_pRespBufPos, pBuf + skip, len - skip );
|
964
|
+
pReq->m_pRespBufPos += len - skip;
|
965
|
+
return len;
|
966
|
+
}
|
967
|
+
|
945
968
|
|
946
969
|
pHeader = pReq->m_respPktHeader;
|
947
|
-
p = pBuf;
|
970
|
+
p = pBuf + skip;
|
948
971
|
pEnd = pBuf + len;
|
949
972
|
bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf;
|
950
973
|
|
@@ -1384,6 +1407,16 @@ int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, char * pBuf, int len )
|
|
1384
1407
|
return -1;
|
1385
1408
|
if ( pReq->m_respHeader.m_respInfo.m_cntHeaders >= LSAPI_MAX_RESP_HEADERS )
|
1386
1409
|
return -1;
|
1410
|
+
while( len > 0 )
|
1411
|
+
{
|
1412
|
+
char ch = *(pBuf + len - 1 );
|
1413
|
+
if (( ch == '\n' )||( ch == '\r' ))
|
1414
|
+
--len;
|
1415
|
+
else
|
1416
|
+
break;
|
1417
|
+
}
|
1418
|
+
if ( len <= 0 )
|
1419
|
+
return 0;
|
1387
1420
|
if ( pReq->m_pRespHeaderBufPos + len + 1 > pReq->m_pRespHeaderBufEnd )
|
1388
1421
|
{
|
1389
1422
|
int newlen = pReq->m_pRespHeaderBufPos + len + 4096 - pReq->m_pRespHeaderBuf;
|
@@ -1646,6 +1679,9 @@ static int lsapi_accept( int fdListen )
|
|
1646
1679
|
setsockopt( fd, IPPROTO_TCP, TCP_NODELAY,
|
1647
1680
|
(char *)&nodelay, sizeof(nodelay));
|
1648
1681
|
}
|
1682
|
+
//OPTIMIZATION
|
1683
|
+
if ( s_accept_notify )
|
1684
|
+
notify_req_received( fd );
|
1649
1685
|
}
|
1650
1686
|
return fd;
|
1651
1687
|
|
@@ -1955,6 +1991,11 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
|
|
1955
1991
|
|
1956
1992
|
}
|
1957
1993
|
|
1994
|
+
void lsapi_error( char * pMessage, int err_no )
|
1995
|
+
{
|
1996
|
+
fprintf( stderr, "%d: %s, errno: %d (%s)\n", getpid(), pMessage, err_no, strerror( err_no ) );
|
1997
|
+
}
|
1998
|
+
|
1958
1999
|
int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
|
1959
2000
|
{
|
1960
2001
|
int fd;
|
@@ -1989,7 +2030,10 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
|
|
1989
2030
|
else if ( pReq->m_fdListen != -1 )
|
1990
2031
|
fd = pReq->m_fdListen;
|
1991
2032
|
else
|
2033
|
+
{
|
2034
|
+
lsapi_error( "no available fd", 0 );
|
1992
2035
|
return -1;
|
2036
|
+
}
|
1993
2037
|
wait_secs = 0;
|
1994
2038
|
while( 1 )
|
1995
2039
|
{
|
@@ -2037,6 +2081,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
|
|
2037
2081
|
{
|
2038
2082
|
if (( errno == EINTR )||( errno == EAGAIN))
|
2039
2083
|
continue;
|
2084
|
+
lsapi_error( "lsapi_accept() error", errno );
|
2040
2085
|
return -1;
|
2041
2086
|
}
|
2042
2087
|
}
|
@@ -2100,6 +2145,16 @@ void LSAPI_Set_Server_Max_Idle_Secs( int serverMaxIdle )
|
|
2100
2145
|
g_prefork_server->m_iServerMaxIdle = serverMaxIdle;
|
2101
2146
|
}
|
2102
2147
|
|
2148
|
+
void LSAPI_Set_Slow_Req_Msecs( int msecs )
|
2149
|
+
{
|
2150
|
+
s_slow_req_msecs = msecs;
|
2151
|
+
}
|
2152
|
+
|
2153
|
+
int LSAPI_Get_Slow_Req_Msecs()
|
2154
|
+
{
|
2155
|
+
return s_slow_req_msecs;
|
2156
|
+
}
|
2157
|
+
|
2103
2158
|
|
2104
2159
|
void LSAPI_No_Check_ppid()
|
2105
2160
|
{
|
@@ -2154,6 +2209,19 @@ void LSAPI_Init_Env_Parameters( fn_select_t fp )
|
|
2154
2209
|
avoidFork = atoi( p );
|
2155
2210
|
}
|
2156
2211
|
|
2212
|
+
p = getenv( "LSAPI_ACCEPT_NOTIFY" );
|
2213
|
+
if ( p )
|
2214
|
+
{
|
2215
|
+
s_accept_notify = atoi( p );
|
2216
|
+
}
|
2217
|
+
|
2218
|
+
p = getenv( "LSAPI_SLOW_REQ_MSECS" );
|
2219
|
+
if ( p )
|
2220
|
+
{
|
2221
|
+
n = atoi( p );
|
2222
|
+
LSAPI_Set_Slow_Req_Msecs( n );
|
2223
|
+
}
|
2224
|
+
|
2157
2225
|
#if defined( RLIMIT_CORE )
|
2158
2226
|
p = getenv( "LSAPI_ALLOW_CORE_DUMP" );
|
2159
2227
|
if ( !p )
|
data/ext/lsapi/lsapilib.h
CHANGED
@@ -331,6 +331,10 @@ void LSAPI_Set_Max_Process_Time( int secs );
|
|
331
331
|
|
332
332
|
void LSAPI_Init_Env_Parameters( fn_select_t fp );
|
333
333
|
|
334
|
+
void LSAPI_Set_Slow_Req_Msecs( int msecs );
|
335
|
+
|
336
|
+
int LSAPI_Get_Slow_Req_Msecs( );
|
337
|
+
|
334
338
|
#if defined (c_plusplus) || defined (__cplusplus)
|
335
339
|
}
|
336
340
|
#endif
|
data/ext/lsapi/lsruby.c
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
|
2
2
|
#include "ruby.h"
|
3
|
+
|
4
|
+
#ifdef RUBY_19
|
5
|
+
#include <ruby/util.h>
|
6
|
+
#else
|
3
7
|
#include "util.h"
|
8
|
+
#endif
|
4
9
|
|
5
10
|
#include "lsapilib.h"
|
6
11
|
#include <errno.h>
|
@@ -251,10 +256,10 @@ static VALUE lsapi_write( VALUE self, VALUE str )
|
|
251
256
|
lsapi_data *data;
|
252
257
|
int len;
|
253
258
|
Data_Get_Struct(self,lsapi_data, data);
|
254
|
-
/* len = LSAPI_Write_r( data->req,
|
259
|
+
/* len = LSAPI_Write_r( data->req, RSTRING_PTR(str), RSTRING_LEN(str) ); */
|
255
260
|
if (TYPE(str) != T_STRING)
|
256
261
|
str = rb_obj_as_string(str);
|
257
|
-
len = (*data->fn_write)( data->req,
|
262
|
+
len = (*data->fn_write)( data->req, RSTRING_PTR(str), RSTRING_LEN(str) );
|
258
263
|
return INT2NUM( len );
|
259
264
|
}
|
260
265
|
|
@@ -302,14 +307,35 @@ static VALUE lsapi_printf(int argc, VALUE *argv, VALUE out)
|
|
302
307
|
|
303
308
|
static VALUE lsapi_puts _((int, VALUE*, VALUE));
|
304
309
|
|
310
|
+
#ifdef RUBY_19
|
311
|
+
static VALUE lsapi_puts_ary(VALUE ary, VALUE out, int recur )
|
312
|
+
{
|
313
|
+
VALUE tmp;
|
314
|
+
long i;
|
315
|
+
|
316
|
+
if (recur)
|
317
|
+
{
|
318
|
+
tmp = rb_str_new2("[...]");
|
319
|
+
rb_io_puts(1, &tmp, out);
|
320
|
+
return Qnil;
|
321
|
+
}
|
322
|
+
for (i=0; i<RARRAY_LEN(ary); i++)
|
323
|
+
{
|
324
|
+
tmp = RARRAY_PTR(ary)[i];
|
325
|
+
rb_io_puts(1, &tmp, out);
|
326
|
+
}
|
327
|
+
return Qnil;
|
328
|
+
|
329
|
+
}
|
330
|
+
#else
|
305
331
|
static VALUE lsapi_puts_ary(VALUE ary, VALUE out)
|
306
332
|
{
|
307
333
|
VALUE tmp;
|
308
334
|
int i;
|
309
335
|
|
310
|
-
for (i=0; i<
|
336
|
+
for (i=0; i<RARRAY_LEN(ary); i++)
|
311
337
|
{
|
312
|
-
tmp =
|
338
|
+
tmp = RARRAY_PTR(ary)[i];
|
313
339
|
if (rb_inspecting_p(tmp))
|
314
340
|
{
|
315
341
|
tmp = rb_str_new2("[...]");
|
@@ -318,6 +344,7 @@ static VALUE lsapi_puts_ary(VALUE ary, VALUE out)
|
|
318
344
|
}
|
319
345
|
return Qnil;
|
320
346
|
}
|
347
|
+
#endif
|
321
348
|
|
322
349
|
static VALUE lsapi_puts(int argc, VALUE *argv, VALUE out)
|
323
350
|
{
|
@@ -338,7 +365,11 @@ static VALUE lsapi_puts(int argc, VALUE *argv, VALUE out)
|
|
338
365
|
line = rb_str_new2("nil");
|
339
366
|
break;
|
340
367
|
case T_ARRAY:
|
368
|
+
#ifdef RUBY_19
|
369
|
+
rb_exec_recursive(lsapi_puts_ary, argv[i], out);
|
370
|
+
#else
|
341
371
|
rb_protect_inspect(lsapi_puts_ary, argv[i], out);
|
372
|
+
#endif
|
342
373
|
continue;
|
343
374
|
default:
|
344
375
|
line = argv[i];
|
@@ -346,7 +377,7 @@ static VALUE lsapi_puts(int argc, VALUE *argv, VALUE out)
|
|
346
377
|
}
|
347
378
|
line = rb_obj_as_string(line);
|
348
379
|
lsapi_write(out, line);
|
349
|
-
if (
|
380
|
+
if (*( RSTRING_PTR(line) + RSTRING_LEN(line) - 1 ) != '\n')
|
350
381
|
{
|
351
382
|
lsapi_write(out, rb_default_rs);
|
352
383
|
}
|
@@ -410,7 +441,7 @@ static VALUE lsapi_gets( VALUE self )
|
|
410
441
|
rb_str_buf_cat( str, buff, len );
|
411
442
|
|
412
443
|
}
|
413
|
-
if (
|
444
|
+
if (RSTRING_LEN(str) == 0)
|
414
445
|
return Qnil;
|
415
446
|
return str;
|
416
447
|
}
|
@@ -455,7 +486,7 @@ static VALUE lsapi_read(int argc, VALUE *argv, VALUE self)
|
|
455
486
|
break;
|
456
487
|
}
|
457
488
|
}
|
458
|
-
if (
|
489
|
+
if (RSTRING_LEN(str) == 0)
|
459
490
|
return Qnil;
|
460
491
|
return str;
|
461
492
|
}
|
@@ -619,6 +650,7 @@ void Init_lsapi()
|
|
619
650
|
ruby_verbose = Qnil;
|
620
651
|
|
621
652
|
lsapi_env = rb_hash_new();
|
653
|
+
clear_env();
|
622
654
|
/* redefine ENV using a hash table, should be faster than char **environment */
|
623
655
|
rb_define_global_const("ENV", lsapi_env);
|
624
656
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "
|
4
|
+
version: "4.0"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LiteSpeed Technologies Inc.
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-10 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|