Rails source code analysis (1): RailsFCGIHandler

sponsored links
In accordance with the sequence starting from the beginning CGI

Ruby CGI Doc:

The Common Gateway Interface ( CGI ) Is a simple protocol for passing an HTTP request from a web server to a standalone program, and returning the output to the web browser. Basically, a CGI program is called with the parameters of the request passed in either in the environment (GET) or via $ stdin (POST), and everything it prints to $ stdout is returned to the client.

This class focuses on process! Methods:

  1. def process! (provider = FCGI)
  2. mark_features!
  3. dispatcher_log: info, 'starting'
  4. process_each_request provider
  5. dispatcher_log: info, 'stopping gracefully'
  6. rescue Exception => error
  7. case error
  8. when SystemExit
  9. dispatcher_log: info, 'stopping after explicit exit'
  10. when SignalException
  11. dispatcher_error error, 'stopping after unhandled signal'
  12. else
  13. # Retry if exceptions occur more than 10 seconds apart.
  14. if Time.now - @ last_error_on> 10
  15. @ last_error_on = Time.now
  16. dispatcher_error error, 'retrying after unhandled exception'
  17. retry
  18. else
  19. dispatcher_error error, 'stopping after unhandled exception within 10 seconds of the last'
  20. end
  21. end
  22. end


(1) mark_features!

def mark_features!

@ features = $ ". clone

end

/ / Through the $ "to be all Rails loaded. Rb file name composed of list

(2) process_each_request

  1. def process_each_request (provider)
  2. cgi = nil
  3. catch: exit do
  4. provider.each_cgi do | cgi |
  5. process_request (cgi)
  6. case when_ready
  7. when: reload
  8. reload!
  9. when: restart
  10. close_connection (cgi)
  11. restart!
  12. when: exit
  13. close_connection (cgi)
  14. throw: exit
  15. end
  16. end
  17. end
  18. rescue SignalException => signal
  19. raise unless signal.message == 'SIGUSR1'
  20. close_connection (cgi)
  21. end


(3) process_request

  1. def process_request (cgi)
  2. @ processing, @ when_ready = true, nil
  3. gc_countdown
  4. with_signal_handler 'USR1' do
  5. begin
  6. Dispatcher.dispatch (cgi)
  7. rescue SignalException, SystemExit
  8. raise
  9. rescue Exception => error
  10. dispatcher_error error, 'unhandled dispatch error'
  11. end
  12. end
  13. ensure
  14. @ processing = false
  15. end


Next on the inside of the Dispatcher

  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Rails source code analysis (1): RailsFCGIHandler

  • Using Rails Captcha plug-in, easy implementation Verification Code

    Simple Captcha Plugin Can help us easily in the Rails implementation of Verification Code function. In addition, he has the option to provide sufficient to meet the U.S. requirements for certification, the use of easy. Supported picture and digital authen

  • RSpec troubleshooting

    1.uninitialized constant Dependencies Conditions: In windows under way to install the RSpec gem and rspec-rails. However, in ruby script / spec_server to do the test under the spec your_spec.rb-X will appear uninitialized constant Dependencies (NameE ...

  • Alternative to Java with Ruby to do unit testing interface rest!

    Ruby is long overdue to replace java more flexible and make some necessary changes in a matter of, if not deep-rooted culture of the company's java, I think. . . . . . The following are my Writing for the Rest of the interface used to make the test su

  • Answer: After 2.2 upgrade mysql question-driven

    windows installed after the mysql gem error, error is approximately: ArgumentError (NULL pointer given): (eval): 3: in `each_hash ' (eval): 3: in `all_hashes' This is feeling under the windows of the question if the mysql gem version libmysql ...

  • Workspace run under different Eclipse

    Now do live more and more often required to use eclipse in java and ruby & rails project conducted between the tangential shear from the past, because in the rails project used a coloring Aptana preferences, the results open the java project sour ...

  • Hibernate Inteceptor

    The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

  • FLEX: integrating Spring + Hibernate

    Before a friend also wanted to study development of FLEX. Asked me to help him to be a small sample. Spent a weekend time, to integrate a sampleproject. Client: FLEX Server: Spring2.5 + Hibernate3.2 + Hibernate-annotations3.3.1 + MySQL5 FDS: BlazeDS3 IDE:

  • Oracle instant clent for ruby / rails on cygwin

    Environment: XP: oracle full client, ruby, rails, gem cygwin: ruby rails, gem (the version with the XP version) Needs: for cygwin is installed under the rails platform support oci Steps: <1> download oracle instant client (10.2.0.3 Instant Client Pa

  • Ruby on Rails Routing - Simple Examples

    This article contains a list of ruby on rails routing examples. If you find you have any questions please leave a comment. Routes are processed from the top of routes.rb down. If a route is matched it will stop processing the routes.rb file and use that r

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries