Created
February 10, 2010 14:57
-
-
Save filiptepper/300396 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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