Skip to content

Instantly share code, notes, and snippets.

@filiptepper
Created February 10, 2010 14:57
Show Gist options
  • Save filiptepper/300396 to your computer and use it in GitHub Desktop.
Save filiptepper/300396 to your computer and use it in GitHub Desktop.
require "eventmachine"
module Thrift
class EventMachineServer < BaseServer
def initialize(processor)
@em = Class.new(EM::Connection) do
class << self
attr_accessor :processor
end
def receive_data(data)
request = StringIO.new data
response = StringIO.new
transport = Thrift::IOStreamTransport.new request, response
protocol = Thrift::BinaryProtocol.new transport
self.class.processor.process protocol, protocol
send_data response.string
end
end
@em.processor = processor
end
def serve
EM.run do
EM.start_server "0.0.0.0", 9090, @em
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment