Parent

FCGI

There is no C version of 'each_cgi' Note: for ruby-1.6.8 at least, the constants CGI_PARAMS/CGI_COOKIES are defined within module 'CGI', even if you have subclassed it

Public Class Methods

accept() click to toggle source
static VALUE fcgi_s_accept(VALUE self)
{
  int status;
  FCGX_Request *req;
  fd_set readfds;
  
  req = ALLOC(FCGX_Request);
  
  status = FCGX_InitRequest(req,0,0);
  if (status != 0) {
    rb_raise(eFCGIError, "FCGX_Init() failed");
    return Qnil;
  }

  FD_ZERO(&readfds);
  FD_SET(req->listen_sock, &readfds);
  if (rb_thread_select(req->listen_sock+1, &readfds, NULL, NULL, NULL) < 1) {
    return Qnil;
  }
  
  status = FCGX_Accept_r(req);
  if (status >= 0) {
    fcgi_data *data;
    char      **env;
    VALUE     obj,key, value;
    char      *pkey,*pvalue;
    int       flags, fd;

    /* Unset NONBLOCKING */
    fd = ((FCGX_Request*) req)->ipcFd;
    flags = fcntl(fd, F_GETFL);

    if (flags & O_NONBLOCK) {
       fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
    }
    
    obj = Data_Make_Struct(self, fcgi_data, fcgi_mark, fcgi_free_req, data);
    data->req = req;
    data->in  = Data_Wrap_Struct(cFCGIStream, 0, 0, req->in);
    data->out = Data_Wrap_Struct(cFCGIStream, 0, 0, req->out);
    data->err = Data_Wrap_Struct(cFCGIStream, 0, 0, req->err);
    data->env = rb_hash_new();
    env = req->envp;
    for (; *env; env++) {
      int size = 0;
      pkey = *env;
      pvalue = pkey;
      while( *(pvalue++) != '=') size++;
      key   = rb_str_new(pkey, size);
      value = rb_str_new2(pvalue);
      OBJ_TAINT(key);
      OBJ_TAINT(value);
      rb_hash_aset(data->env, key, value);
    }
    
    return obj;
  } else {
    return Qnil;
  }
}
default_connection() click to toggle source
# File lib/fcgi.rb, line 48
def self::default_connection
  ::Socket.for_fd($stdin.fileno)
end
each(&block) click to toggle source
# File lib/fcgi.rb, line 34
def self::each(&block)
  f = default_connection()
  Server.new(f).each_request(&block)
ensure
  f.close if f
end
each_cgi(*args) click to toggle source
# File lib/fcgi.rb, line 567
def self::each_cgi(*args)
  require 'cgi'
  
  eval(    class CGI      public :env_table      def self::remove_params        if (const_defined?(:CGI_PARAMS))          remove_const(:CGI_PARAMS)          remove_const(:CGI_COOKIES)        end      end    end # ::CGI class    class FCGI      class CGI < ::CGI        def initialize(request, *args)          ::CGI.remove_params          @request = request          super(*args)          @args = *args        end        def args          @args        end        def env_table          @request.env        end        def stdinput          @request.in        end        def stdoutput          @request.out        end      end # FCGI::CGI class    end # FCGI class,TOPLEVEL_BINDING)
  
  if FCGI::is_cgi?
    yield ::CGI.new(*args)
  else
    exit_requested = false
    FCGI::each {|request|
      $stdout, $stderr = request.out, request.err

      yield CGI.new(request, *args)
      
      request.finish
    }
  end
end
each_request(&block) click to toggle source
# File lib/fcgi.rb, line 41
def self::each_request(&block)
  f = default_connection()
  Server.new(f).each_request(&block)
ensure
  f.close if f
end
is_cgi?() click to toggle source
# File lib/fcgi.rb, line 22
def self::is_cgi?
  begin
    s = Socket.for_fd($stdin.fileno)
    s.getpeername
    false
  rescue Errno::ENOTCONN
    false
  rescue Errno::ENOTSOCK, Errno::EINVAL
    true
  end
end

Public Instance Methods

env() click to toggle source
static VALUE fcgi_env(VALUE self)
{
  fcgi_data *data;

  Data_Get_Struct(self, fcgi_data, data);
  return data->env;
}
err() click to toggle source
static VALUE fcgi_err(VALUE self)
{
  fcgi_data *data;

  Data_Get_Struct(self, fcgi_data, data);
  return data->err;
}
finish() click to toggle source
static VALUE fcgi_finish(VALUE self)
{
  fcgi_data *data;
  
  Data_Get_Struct(self, fcgi_data, data);
  
  FCGX_Finish_r(data->req);
  
  return Qtrue;
}
in() click to toggle source
static VALUE fcgi_in(VALUE self)
{
  fcgi_data *data;

  Data_Get_Struct(self, fcgi_data, data);
  return data->in;
}
out() click to toggle source
static VALUE fcgi_out(VALUE self)
{
  fcgi_data *data;

  Data_Get_Struct(self, fcgi_data, data);
  return data->out;
}

[Validate]

Generated with the Darkfish Rdoc Generator 2.