Class: FCGI

Inherits:
Object
  • Object
show all
Defined in:
lib/fcgi.rb,
ext/fcgi/fcgi.c

Overview

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

Defined Under Namespace

Classes: Error, Stream

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acceptObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'ext/fcgi/fcgi.c', line 76

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 (select(req->listen_sock+1, &readfds, NULL, NULL, NULL) < 1) {
    return Qnil;
  }

  status = FCGX_Accept_r(req);
  if (status >= 0) {
    fcgi_data *data;
    fcgi_stream_data *stream_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_Make_Struct(cFCGIStream, fcgi_stream_data, fcgi_stream_mark, fcgi_stream_free, stream_data);
    stream_data->stream = req->in;
    stream_data->req = obj;
    data->out = Data_Make_Struct(cFCGIStream, fcgi_stream_data, fcgi_stream_mark, fcgi_stream_free, stream_data);
    stream_data->stream = req->out;
    stream_data->req = obj;
    data->err = Data_Make_Struct(cFCGIStream, fcgi_stream_data, fcgi_stream_mark, fcgi_stream_free, stream_data);
    stream_data->stream = req->err;
    stream_data->req = obj;
    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 {
    FCGX_Free(req, 1);
    free(req);
    return Qnil;
  }
}

.eachObject



146
147
148
149
150
151
152
153
154
# File 'ext/fcgi/fcgi.c', line 146

static VALUE fcgi_s_each(VALUE self)
{
  VALUE fcgi;

  while ((fcgi = fcgi_s_accept(self)) != Qnil) {
    rb_yield(fcgi);
  }
  return Qnil;
}

.each_cgi(*args) ⇒ Object



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/fcgi.rb', line 588

def self.each_cgi(*args)
  require 'cgi'

  eval("  class CGI\n    public :env_table\n    def self.remove_params\n      if (const_defined?(:CGI_PARAMS))\n        remove_const(:CGI_PARAMS)\n        remove_const(:CGI_COOKIES)\n      end\n    end\n  end # ::CGI class\n\n  class FCGI\n    class CGI < ::CGI\n      def initialize(request, *args)\n        ::CGI.remove_params\n        @request = request\n        super(*args)\n        @args = *args\n      end\n      def args\n        @args\n      end\n      def env_table\n        @request.env\n      end\n      def stdinput\n        @request.in\n      end\n      def stdoutput\n        @request.out\n      end\n    end # FCGI::CGI class\n  end # FCGI class\n  EOS\n\n  if FCGI::is_cgi?\n    yield ::CGI.new(*args)\n  else\n    exit_requested = false\n    FCGI::each do |request|\n\n      $stdout, $stderr = request.out, request.err\n\n      yield CGI.new(request, *args)\n\n      request.finish\n    end\n  end\nend\n",TOPLEVEL_BINDING)

.each_requestObject



146
147
148
149
150
151
152
153
154
# File 'ext/fcgi/fcgi.c', line 146

static VALUE fcgi_s_each(VALUE self)
{
  VALUE fcgi;

  while ((fcgi = fcgi_s_accept(self)) != Qnil) {
    rb_yield(fcgi);
  }
  return Qnil;
}

.is_cgi?Boolean

Returns:

  • (Boolean)


156
157
158
159
160
161
162
163
# File 'ext/fcgi/fcgi.c', line 156

static VALUE fcgi_s_iscgi(VALUE self)
{
  if (FCGX_IsCGI()) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

Instance Method Details

#envObject



189
190
191
192
193
194
195
# File 'ext/fcgi/fcgi.c', line 189

static VALUE fcgi_env(VALUE self)
{
  fcgi_data *data;

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

#errObject



181
182
183
184
185
186
187
# File 'ext/fcgi/fcgi.c', line 181

static VALUE fcgi_err(VALUE self)
{
  fcgi_data *data;

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

#finishObject



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/fcgi/fcgi.c', line 197

static VALUE fcgi_finish(VALUE self)
{
  fcgi_data *data;
  fcgi_stream_data *stream_data;

  Data_Get_Struct(self, fcgi_data, data);

  if (Qnil != data->in) {
    Data_Get_Struct(data->in, fcgi_stream_data, stream_data);
    stream_data->req = Qnil; stream_data->stream = NULL;
  }
  if (Qnil != data->out) {
    Data_Get_Struct(data->out, fcgi_stream_data, stream_data);
    stream_data->req = Qnil; stream_data->stream = NULL;
  }
  if (Qnil != data->err) {
    Data_Get_Struct(data->err, fcgi_stream_data, stream_data);
    stream_data->req = Qnil; stream_data->stream = NULL;
  }

  data->in = data->out = data->err = Qnil;
  FCGX_Finish_r(data->req);

  return Qtrue;
}

#inObject



165
166
167
168
169
170
171
# File 'ext/fcgi/fcgi.c', line 165

static VALUE fcgi_in(VALUE self)
{
  fcgi_data *data;

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

#outObject



173
174
175
176
177
178
179
# File 'ext/fcgi/fcgi.c', line 173

static VALUE fcgi_out(VALUE self)
{
  fcgi_data *data;

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