0
LIBDIR = File.dirname(__FILE__)
0
VERSION = File.read(LIBDIR + "/../VERSION").gsub(/\s/,'')
0
+ autoload :Runner, LIBDIR + '/ebb/runner'
0
require Ebb::LIBDIR + '/../src/ebb_ext'
0
-require Ebb::LIBDIR + '/daemonizable'
0
+ # "Gasp! No Server class! But this is Object Oriented Programming - we
0
+ # classes for servers!", you say. Not when there always will be
0
+ # exactly one server per virtual machine.
0
+ def self.start_server(app, options={})
0
+ port = (options[:port] || 4001).to_i
0
+ #socket = options[:socket]
0
+ timeout = options[:timeout]
0
+ trap('INT') { @running = false }
0
+ FFI::server_listen_on_port(port)
0
+ puts "Ebb listening at http://0.0.0.0:#{port}/"
0
+ while FFI::server_process_connections() and @running
0
+ unless FFI::waiting_clients.empty?
0
+ if $DEBUG and $ebb_waiting_clients.length > 1
0
+ puts "#{FFI::waiting_clients.length} waiting clients"
0
+ client = FFI::waiting_clients.shift
0
+ process_client(app, client)
0
+ puts "Ebb unlistening"
0
+ FFI::server_unlisten()
0
+ def self.process_client(app, client)
0
+ #puts "Request: #{client.env.inspect}\n"
0
+ status, headers, body = app.call(client.env)
0
+ headers = {'Content-Type' => 'text/plain'}
0
+ body = "Internal Server Error\n"
0
+ client.write_status(status)
0
+ if body.respond_to? :length and status != 304
0
+ headers['Connection'] = 'close'
0
+ headers['Content-Length'] = body.length
0
+ headers.each { |k, v| client.write_header(k,v) }
0
+ # Not many apps use streaming yet so i'll hold off on that feature
0
+ # until the rest of ebb is more developed.
0
+ if body.kind_of?(String)
0
+ body.each { |p| client.write p }
0
+ def self.waiting_clients
0
@@ -66,86 +132,6 @@ module Ebb
0
- def self.run(app, options={})
0
- # port must be an integer
0
- server = self.new(app, options)
0
- yield server if block_given?
0
- def initialize(app, options={})
0
- @socket = options[:socket]
0
- @port = (options[:port] || 4001).to_i
0
- @timeout = options[:timeout]
0
- trap('INT') { @running = false }
0
- FFI::server_listen_on_socket(self, @socket) or raise "Problem listening on socket #{@socket}"
0
- FFI::server_listen_on_port(self, @port) or raise "Problem listening on port #{@port}"
0
- puts "Ebb listening at http://0.0.0.0:#{@port}/"
0
- while FFI::server_process_connections(self) and @running
0
- unless @waiting_clients.empty?
0
- if $DEBUG and @waiting_clients.length > 1
0
- puts "#{@waiting_clients.length} waiting clients"
0
- client = @waiting_clients.shift
0
- process_client(client)
0
- puts "Ebb unlistening"
0
- FFI::server_unlisten(self)
0
- def process_client(client)
0
- #puts "Request: #{client.env.inspect}\n"
0
- status, headers, body = @app.call(client.env)
0
- headers = {'Content-Type' => 'text/plain'}
0
- body = "Internal Server Error\n"
0
- client.write_status(status)
0
- if body.respond_to? :length and status != 304
0
- headers['Connection'] = 'close'
0
- headers['Content-Length'] = body.length
0
- headers.each { |k, v| client.write_header(k,v) }
0
- # Not many apps use streaming yet so i'll hold off on that feature
0
- # until the rest of ebb is more developed.
0
- if body.kind_of?(String)
0
- body.each { |p| client.write p }
0
101 => 'Switching Protocols',