Sha256: bc5c74bd2853fa4bd2c991ad63c81ad20e7382acb8e0cf5e0fe9a4c4cc82fcb6

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

# WARNING: Does not work yet!

require 'cgi'
require 'scgi'
require 'stringio'

require 'nitro/context'
require 'nitro/dispatcher'
require 'nitro/adapter/cgi'

# Speeds things up, more comaptible with OSX.

Socket.do_not_reverse_lookup = true

module Nitro

# SCGI Adaptor.
# No need for connection pooling, SCGI uses processes.

class Scgi

  # A special modification so that we can make the socket and then pass it in.
  # Should generalize this since it will be pretty common.

  class Listener < Myriad::Listener
    def initialize(socket, server_class, *params)
      @socket = socket
      @server_class = server_class
      @params = params
      @tick = [3,0]  # this is just here until I can figure out the signals crap
      Event::set(self, @socket.fileno, Event::READ | Event::TIMEOUT)
      Event::add(self, @tick)
    end
  end    

  class SCGINitro < ::SCGI::SCGIServer
    def process_request(data)
      context = Context.new(Nitro::Server.new)

      context.in = SCGIFixed.new(@request, data)
      context.headers = cgi.env

      CgiUtils.parse_params(context)
      CgiUtils.parse_cookies(context)
      
      context.render(context.path)

      body = ''
      body << CgiUtils.response_headers(context)
      body << context.out

      @trans.write(body)

      super(data)
    end
  end
  
  def self.start(server)
  
    puts '-------------1'
    children = "5"
    host = "127.0.0.0"
    port = "8888"

    socket = TCPServer.new(host, port)
    socket.fcntl(Fcntl::F_SETFL, socket.fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK)

    children.to_i.times do
      pid = fork do
        Event::init(10)
        server = Listener.new(socket, SCGINitro)
        Event::dispatch
      end
      Process.detach(pid)
    end
  end
  
end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.23.0 lib/nitro/adapter/scgi.rb
nitro-0.22.0 lib/nitro/adapter/scgi.rb