[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby-fcgi patches

Brad Hilton

9/25/2003 8:34:00 PM

Hello,

I have two patches that fix / enhance the C version of ruby-fcgi. This
message was sent to the maintainer several days ago, but I haven't
received a response. I'm hoping perhaps he reads this list.

The fix:
fcgi_stream_read() does not free the buff variable, which results in
memory leakage that is most noticeable when handling large file
uploads. Simply doing a:

------------------------
FCGI::each { |request|
until request.in.eof?
request.in.read(1024)
end
}
------------------------

exposes the problem, as the application grows in size with each new
client POST. Calling GC.start does nothing to decrease the size. The
first patch appears to solve this problem.

The second patch adds a new method FCGI::open_socket(socket_path,
tcp_backlog) which allows the library to be used with the
FastCgiExternalServer option of mod_fastcgi for Apache. FCGI::accept()
and FCGI::each() had to be patched to optionally take this new socket
argument. Example usage would be:

sock = FCGI.open_socket('localhost:23443', 10)

FCGI::each(sock) { |request|
...
}

Thank you for considering these patches.

Regards,
-Brad Hilton
--- fcgi.c.orig 2003-09-23 11:20:01.000000000 -0700+++ fcgi.c 2003-09-23 11:20:29.000000000 -0700@@ -389,9 +389,11 @@ static VALUE fcgi_stream_read(int argc, if (n > 0) { rb_str_cat(str, buff, n); } else {+ xfree(buff); return Qnil; } }+ xfree(buff); return str; } @@ -404,9 +406,11 @@ static VALUE fcgi_stream_read(int argc, if (n > 0) { str = rb_str_new(buff, n); OBJ_TAINT(str);+ xfree(buff); return str; } else {+ xfree(buff); return Qnil; } }--- fcgi.c 2003-09-23 11:20:29.000000000 -0700+++ /home/bhilton/fcgi.c.patched 2003-09-23 11:20:50.000000000 -0700@@ -37,15 +37,37 @@ static void fcgi_mark(fcgi_data *data) rb_gc_mark(data->env); } -static VALUE fcgi_s_accept(VALUE self)+static VALUE fcgi_s_open_socket(VALUE self, VALUE path, VALUE backlog)+{+ VALUE fileno;++ fileno = INT2NUM(FCGX_OpenSocket( STR2CSTR(path), NUM2INT(backlog) ));+ return rb_funcall(rb_cIO, rb_intern("new"), 1, fileno);+}++static VALUE fcgi_s_accept(int argc, VALUE *argv, VALUE self) { int status; FCGX_Request *req; fd_set readfds;+ int fileno;++ switch (argc)+ {+ case 1:+ fileno = NUM2INT(rb_funcall(argv[0], rb_intern("fileno"), 0));+ break;+ case 0:+ fileno = 0;+ break;+ default:+ rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");+ break;+ } req = ALLOC(FCGX_Request); - status = FCGX_InitRequest(req,0,0);+ status = FCGX_InitRequest(req,fileno,0); if (status != 0) { rb_raise(eFCGIError, "FCGX_Init() failed"); return Qnil;@@ -89,11 +111,28 @@ static VALUE fcgi_s_accept(VALUE self) } } -static VALUE fcgi_s_each(VALUE self)+static VALUE fcgi_s_each(int argc, VALUE *argv, VALUE self) { VALUE fcgi;+ VALUE socket;+ VALUE args[1];++ switch(argc)+ {+ case 1:+ socket = argv[0];+ break;+ case 0:+ socket = rb_funcall(rb_cIO, rb_intern("new"), 1, INT2NUM(0));+ break;+ default:+ rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");+ break;+ }++ args[0] = socket; - while ((fcgi = fcgi_s_accept(self)) != Qnil) {+ while ((fcgi = fcgi_s_accept(1, args, self)) != Qnil) { rb_yield(fcgi); } return Qnil;@@ -488,9 +527,10 @@ void Init_fcgi() cFCGI = rb_define_class("FCGI", rb_cObject); eFCGIError =rb_define_class_under(cFCGI, "Error", rb_eStandardError);- rb_define_singleton_method(cFCGI, "accept", fcgi_s_accept, 0);- rb_define_singleton_method(cFCGI, "each", fcgi_s_each, 0);- rb_define_singleton_method(cFCGI, "each_request", fcgi_s_each, 0);+ rb_define_singleton_method(cFCGI, "accept", fcgi_s_accept, -1);+ rb_define_singleton_method(cFCGI, "open_socket", fcgi_s_open_socket, 2);+ rb_define_singleton_method(cFCGI, "each", fcgi_s_each, -1);+ rb_define_singleton_method(cFCGI, "each_request", fcgi_s_each, -1); rb_define_singleton_method(cFCGI, "is_cgi?", fcgi_s_iscgi, 0); rb_define_method(cFCGI, "in", fcgi_in, 0); rb_define_method(cFCGI, "out", fcgi_out, 0);
3 Answers

Roger Dewhurst

2/24/2008 5:05:00 PM

0

Andy wrote:
> On 23 Feb, 17:35, "robw" <noddy...@comcast.net> wrote:
>> What's wrong with getting along with people?
>>
>> <alan.acker...@yahoo.com> wrote in message
>>
>> news:20057b22-6e53-4c91-bb0f-6ca12ba172b2@p73g2000hsd.googlegroups.com...
>>
>>> blah blah blah you pretensious queer.
>>> If you love the world so much, why don't you marry it.
>
>
> this "miracle" became a reality. If you genuinely believe something is
> possible- it is!

Balls

>
> So if enough people believe that war can be eliminated , it can be.
> There has been thousands of wars in the history of the world. Parts of
> the world are still at war today. No war ever has, or ever will bring
> lasting peace. Study the history of any conflict, and there's always a
> previous conflict pre-dating it. Take the trouble in Israel/Palestine
> - why was their a Jewish exodus from Europe? WW2. Why did the Germans
> start WW2? Because of the humiliation of WW1.

You cannot trump human nature. We are what we are as a result of
millions of years of evolution. No amount of bleating from the
perpetually wet will alter that.

R

Andy

2/24/2008 7:47:00 PM

0

On 24 Feb, 17:04, Roger Dewhurst <dewhu...@wave.co.nz> wrote:
> Andy wrote:
> > On 23 Feb, 17:35, "robw" <noddy...@comcast.net> wrote:
> >> What's wrong with getting along with people?
>
> >> <alan.acker...@yahoo.com> wrote in message
>
> >>news:20057b22-6e53-4c91-bb0f-6ca12ba172b2@p73g2000hsd.googlegroups.com...
>
> >>> blah blah blah you pretensious queer.
> >>> If you love the world so much, why don't you marry it.
>
> > this "miracle" became a reality. If you genuinely believe something is
> > possible- it is!
>
> Balls
>
>
>
> > So if enough people believe that war can be eliminated , it can be.
> > There has been thousands of wars in the history of the world. Parts of
> > the world are still at war today. No war ever has, or ever will bring
> > lasting peace. Study the history of any conflict, and there's always a
> > previous conflict pre-dating it. Take the trouble in Israel/Palestine
> > - why was their a Jewish exodus from Europe? WW2. Why did the Germans
> > start WW2? Because of the humiliation of WW1.
>
> You cannot trump human nature. We are what we are as a result of
> millions of years of evolution. No amount of bleating from the
> perpetually wet will alter that.
>
> R

But the time has come to evolve IDEAS , as Bill Hicks said "evolution
did not end with us growing thumbs...."

Seriously, do you want "hard" humans , with the best personal survival
skills, or the "soft" variety who believe in overcoming challenging
humanity's problems by working as a team. What is the difference
between a single human individual and an ape? Nothing. It's the way we
work together that benefits our long term survival prospects! So
getting along is not anti-evolution, but the climax of it.

Joe

2/25/2008 9:23:00 PM

0

Andy wrote:
> On 24 Feb, 17:04, Roger Dewhurst <dewhu...@wave.co.nz> wrote:

>> You cannot trump human nature. We are what we are as a result of
>> millions of years of evolution. No amount of bleating from the
>> perpetually wet will alter that.
>>
>> R
>
> But the time has come to evolve IDEAS , as Bill Hicks said "evolution
> did not end with us growing thumbs...."
>
> Seriously, do you want "hard" humans , with the best personal survival
> skills, or the "soft" variety who believe in overcoming challenging
> humanity's problems by working as a team. What is the difference
> between a single human individual and an ape? Nothing. It's the way we
> work together that benefits our long term survival prospects! So
> getting along is not anti-evolution, but the climax of it.

The ideas don't *need* to evolve, they evolved millennia ago. All the
ideas you could ever want are already there for the taking. You can't
even patent them. The Ancient Greeks knew at least as much sociology as
anyone does today. They certainly knew more about democracy than people
living in 'democracies' do now.

Long-term cooperation requires that cheats are *not* *tolerated*. Sorry
about that, but there's nothing 'soft' about successful cooperation.
Cheats prosper in a cooperative grouping, so they multiply, and will
eventually take all of the products of the cooperation. Or would if it
hadn't failed long before. In the UK at the moment, you're seeing the
final end of the cooperative taxpayers, as the parasitic cheats
overwhelm their ability to earn and give. Productive people do not
prosper in an environment where the non-productive are not merely
tolerated, but encouraged.

Don't take my word for it, the theoretical behaviour of cheats among
honest people has long been studied by academics, and forms the basis
for several television game shows. Today's game shows are rather more
sophisticated than 'Take Your Pick', and many of them pit contestants
against each other, requiring them to form honesty/cheating strategies
at various stages of the game. 'The Weakest Link' is a rather crude
example.

Cooperation requires a ruthless will to discipline and if necessary, to
eject or imprison cheats. The West no longer has that will, except in
small pockets known as 'private companies', and certainly not in all of
them. Cooperation requires honesty, trust, and decent and honourable
behaviour within the group, which used to be common in much of the West,
but isn't today. Cooperation requires, *by* *definition*, that promises
and other contracts are honoured. *Always*. You need only look at
today's governments, surely our leaders by example, to see how often
that happens today. Look at our 'Honourable' Members of Parliament, and
on whose behalf they labour mightily, and if you know personally a civil
servant, you'll know where most of their efforts are directed.

When the West's 'great and good', the 'opinion formers' (in their
opinions), the Guardian writers, and, yes, the BBC begin to promote
cooperation, then it stands a chance of happening. As long as they all
favour the cheats, the parasites, the promise breakers, there's no
possibility. As long as they sneer at the honest for being fools, the
decent for being old-fashioned, as long as they look down on productive
skills and talents and look up to people who can talk eloquently or
entertainingly, there's no chance.