Module: Thrift::EventMachineConnection

### Home Classes Methods

### In Files

- lib/thrift_client/event_machine.rb

### Methods

- ::connect
- ::new
- #blocking_read
- #can_read?
- #close
- #connected?
- #connection_completed
- #receive_data
- #trap
- #unbind

### Included Modules

- EM::Deferrable

### Files

- CHANGELOG
- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- ThriftClient
- ThriftClient::NoServersAvailable
- ThriftClient::Simple
- ThriftClient::Simple::ComplexType
- ThriftClient::Simple::ComplexType::Extends
- ThriftClient::Simple::ComplexType::Includes
- ThriftClient::Simple::Field
- ThriftClient::Simple::ThriftException
- ThriftClient::Simple::ThriftService
- ThriftClient::Simple::ThriftStruct
- ThriftClient::Simple::ThriftStruct::Extend
- ThriftClient::Simple::ThriftStruct::Include
- Thrift
- Thrift::BaseTransport
- Thrift::BufferedTransport
- Thrift::Client
- Thrift::EventMachineConnection
- Thrift::EventMachineTransport
- Thrift::FramedTransport
- Connection
- Connection::Base
- Connection::Factory
- Connection::HTTP
- Connection::Socket
- AbstractThriftClient
- AbstractThriftClient::Server

No matching classes.

# Thrift::EventMachineConnection

### Constants

GARBAGE_BUFFER_SIZE

### Public Class Methods

connect(host='localhost', port=9090, timeout=5, &block) click to toggle source

    # File lib/thrift_client/event_machine.rb, line 52
    def self.connect(host='localhost', port=9090, timeout=5, &block)
      EM.connect(host, port, self, host, port) do |conn|
        conn.pending_connect_timeout = timeout
      end
    end

new(host, port=9090) click to toggle source

    # File lib/thrift_client/event_machine.rb, line 67
    def initialize(host, port=9090)
      @host, @port = host, port
      @index = 0
      @disconnected = 'not connected'
      @buf = ''
    end

### Public Instance Methods

blocking_read(size) click to toggle source

    # File lib/thrift_client/event_machine.rb, line 81
    def blocking_read(size)
      raise IOError, "lost connection to #{@host}:#{@port}: #{@disconnected}" if @disconnected
      if can_read?(size)
        yank(size)
      else
        raise ArgumentError, "Unexpected state" if @size or @callback

        fiber = Fiber.current
        @size = size
        @callback = proc { |data|
          fiber.resume(data)
        }
        Fiber.yield
      end
    end

can_read?(size) click to toggle source

    # File lib/thrift_client/event_machine.rb, line 127
    def can_read?(size)
      @buf.size >= @index + size
    end

close() click to toggle source

    # File lib/thrift_client/event_machine.rb, line 74
    def close
      trap do
        @disconnected = 'closed'
        close_connection(true)
      end
    end

connected?() click to toggle source

    # File lib/thrift_client/event_machine.rb, line 110
    def connected?
      !@disconnected
    end

connection_completed() click to toggle source

    # File lib/thrift_client/event_machine.rb, line 114
    def connection_completed
      @disconnected = nil
      succeed
    end

receive_data(data) click to toggle source

    # File lib/thrift_client/event_machine.rb, line 97
    def receive_data(data)
      trap do
        (@buf) << data

        if @callback and can_read?(@size)
          callback = @callback
          data = yank(@size)
          @callback = @size = nil
          callback.call(data)
        end
      end
    end

trap() click to toggle source

    # File lib/thrift_client/event_machine.rb, line 58
    def trap
      begin
        yield
      rescue Exception => ex
        puts ex.message
        puts ex.backtrace.join("\n")
      end
    end

unbind() click to toggle source

    # File lib/thrift_client/event_machine.rb, line 119
    def unbind
      if !@disconnected
        @disconnected = 'unbound'
      else
        fail
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.