From: Raghu Kumar Date: 2007-06-26T17:35:10+09:00 Subject: Re: Timeout errors using Net::HTTP on Windows Hi, Thanks a lot... I was struck with this problem ... now I have no problem. But in my project I have lot of different web pages to scrap, is anything possible to tweak so that responses are fast ? Raghu Ben Brightwell wrote: > Interesting results!!! What an understatement!! How on earth did you > figure that out? It worked like a charm. Initially my problem was just > that the HTTP request took FOREVER... then i started randomly getting > the timeout errors mentioned above. I went into the net/protocol.rb file > and made this change and voila!. Not only did the errors go away, but > the request takes literally 1/30th of the time it did before it > eventually got the data or even timed out.. Marcin Coles, you are the > genius of the day! Thank you! > > Marcin Coles wrote: >> Well, I'm no expert, and I certainly wasn't going to learn another >> language, so I decided to do some tests because this was a problem for >> me too. >> >> I went into protocol.rb, to the rbuf_fill method (where it actually >> starts the timeout thread). >> >> the code there was >> >> def rbuf_fill >> timeout(@read_timeout) { >> @rbuf << @io.sysread(1024) >> } >> end >> >> now timeout takes 2 parameters - a time in seconds(?) and an exception >> class to raise (defaults to Error). >> >> When I changed the code to the following, it started to work for me. >> New code: >> >> def rbuf_fill >> timeout(@read_timeout,ProtocolError) { >> @rbuf << @io.sysread(1024) >> } >> end >> >> Obviously this is not exactly extensively tested - but an interesting >> results. >> >> Marcin -- Posted via http://www.ruby-forum.com/.