Sha256: a6dba872c839fb42765afac063be4df4b68646d09895bd82750cd249a3bfa0d6

Contents?: true

Size: 943 Bytes

Versions: 9

Compression:

Stored size: 943 Bytes

Contents

require 'webrick/config'
require 'webrick/server'

module Protobuf
  module Rpc
    class Server < WEBrick::GenericServer
      def initialize(config={:Port => 9999}, default=WEBrick::Config::General)
        super(config, default)
        setup_handlers
      end

      def setup_handlers
        @handlers = {}
      end

      def get_handler(socket)
        @handlers[socket.readline.strip.to_sym]
      end

      def run(socket)
        handler = get_handler socket
        request = handler.request_class.new
        request.parse_from(socket)
        response = handler.response_class.new
        begin
          handler.process_request(request, response)
        rescue StandardError
          @logger.error $!
        ensure
          begin
            response.serialize_to(socket)
          rescue Errno::EPIPE, Errno::ECONNRESET, Errno::ENOTCONN
            @logger.error $!
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruby_protobuf-0.4.11 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.10 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.9 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.8 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.7 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.6 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.5 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.4 lib/protobuf/rpc/server.rb
ruby_protobuf-0.4.1 lib/protobuf/rpc/server.rb