Sha256: f6e081f563d44766e57f08903f6835d9dd42274b6506ad703401172e7b03e5a1

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

module RubyWolf
  class Connection
    attr_reader :socket, :read_data, :write_data

    def initialize(socket)
      @socket = socket
      @read_data = ''
      @write_data = ''

      @reading = true
    end

    def need_to_read?
      @reading
    end

    def read
      @read_data << socket.read_nonblock(RubyWolf::READ_SIZE)
      @reading = false if @read_data.end_with?(RubyWolf::CRLF)
    rescue EOFError
      @reading = false
    end

    def enqueue_write(data)
      @write_data += data
    end

    def write
      writen = socket.write_nonblock(@write_data)
      @write_data[0..writen] = ''
    end

    def need_to_write?
      !@write_data.length.zero?
    end

    def to_io
      @socket
    end

    def close
      @socket.close
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_wolf-0.2.0 lib/ruby_wolf/connection.rb