Rails source code analysis (1): RailsFCGIHandler

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

分类:Ruby 时间:2009-03-02 人气:731
分享到:
blog comments powered by Disqus

相关文章

  • One of the server source code analysis Tracker: Overview 2010-10-13

    One of the server source code analysis Tracker: Overview Of: Ma Ying-jeou Date :2004-5-29 BT download tracker server is necessary role. Start a BT client and a download in the download process, to keep the server to communicate with the tracker to report

  • Ruby On Rails-2.0.2 source code analysis (1)-Rails Start 2010-11-09

    Preface This article is for Ruby On Rails 2.0.2 source code analysis, learning and research. The tools used NetBean 6.1 Beta, WEBRick, SciTE, ruby-debug-base (0.10.0), ruby-debug-ide (0.1.10). Ruby version is 1.8.6. How analysis should be summarized, is t

  • java Socket introduces multi-threaded server source code 2010-08-18

    java Socket introduces multi-threaded server source code java Socket multithreading in the related study, when we pay attention to emerging problems, here we take a look at the java Socket in the server multi-threaded coding. java Socket multithreadi

  • Tomcat 5.5.26 source code analysis - start the process (2) 2010-03-25

    init method Catalina_Home and Catalina_Base Initialize the system class loader Tomcat's class loader system initClassLoaders code Two questions Catalina Object load method Catalina class command-line arguments Loading process start Method await state

  • (R) linux source code analysis tools, and read more 2010-11-01

    Reprinted from: http://hi.baidu.com/likeadream/blog/item/7664bb349daf0049241f144c.html Reading tool for Windows source code Souce Insight With its ease of use and a variety of programming languages, no doubt in this area, "lead Big Brother." Lin

  • Mysql source code analysis series 2010-03-30

    Mysql source code analysis series (2): the source code structure Mysql source code include the client code, server-side code, testing tools and some database structure, the following directories we do introduce the more important. BUILD This directory is

  • Struts2.2.1 a core source code analysis 2010-11-30

    I. Overview Struts2 is the core of a Filter, Action from the web container can be, then what makes http request and the action associated with, the following source code to our in-depth analysis of how the work under the Struts2. FilterDispatcher API writ

  • struts2 source code analysis - Request Process 2011-07-19

    Struts2 source code to read - Request Process 2009-06-03 19:49:50 | Category: STRUTS | Tags: | font size medium and small subscription Struts package introduced ( http://www.blogjava.net/lzhidj/archive/2008/07/10/213898.html ) (most of the descriptive tex

  • Red5 source code analysis (reproduced semi-sleep) 2010-03-25

    Red5 how to respond to the request rmpt, in the middle What are the key classes involved? To respond to the request process is as follows: 1.Red5 will start calling RTMPMinaTransport the start () method, which will open a socket listening rmtp port (defau

  • Android IPC communication mechanism for source code analysis 2010-06-10

    Android IPC communication mechanism for source code analysis Binder Communications Description: Linux system, inter-process communication methods are: socket, named pipe, message queque, signal, share memory. Java System inter-process communication with s

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.380 (s). 14 q(s)