Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Merge f8571d5 into 4e80ee2
Browse files Browse the repository at this point in the history
  • Loading branch information
stouset committed Nov 12, 2013
2 parents 4e80ee2 + f8571d5 commit 3f363b4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/reel/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class Server
execute_block_on_receiver :initialize
finalizer :shutdown

# Allow the existing `new` to be called, even though we will
# replace it with a default version that creates HTTP servers over
# TCP sockets.
#
class << self
alias_method :_new, :new
protected :_new
end

# Create a new Reel HTTP server
#
# @param [String] host address to bind to
Expand All @@ -35,7 +44,7 @@ def self.new(host, port, options = {} , &callback)
server.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
server.listen(backlog)

super(server, options, &callback)
self._new(server, options, &callback)
end

# Create a Reel HTTP server over a UNIX socket.
Expand All @@ -46,7 +55,7 @@ def self.new(host, port, options = {} , &callback)
def self.unix(socket_path, options = {}, &callback)
server = Celluloid::IO::UNIXServer.new(socket_path)

super(server, options, &callback)
self._new(server, options, &callback)
end

def initialize(server, options = {}, &callback)
Expand Down
25 changes: 25 additions & 0 deletions spec/reel/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,29 @@

raise ex if ex
end

it 'allows connections over UNIX sockets' do
ex = nil

handler = proc do |connection|
begin
request = connection.request
request.method.should eq 'GET'
connection.respond :ok, request.body.to_s
rescue => ex
end
end

Dir::Tmpname.create('reel-sock') do |path|
begin
server = Reel::Server.unix(path, handler)
sock = Net::BufferedIO.new UNIXSocket.new(path)
request = Net::HTTP::Get.new('/')

request.exec(sock, '1.1', path)
ensure
server.terminate if server && server.alive?
end
end
end
end

0 comments on commit 3f363b4

Please sign in to comment.