Class: Lumberjack::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/lumberjack/server.rb

Overview

class Parser

Instance Method Summary collapse

Constructor Details

#initialize(fd) ⇒ Connection

Returns a new instance of Connection.



203
204
205
206
207
208
209
210
211
# File 'lib/lumberjack/server.rb', line 203

def initialize(fd)
  super()
  @parser = Parser.new
  @fd = fd
  @last_ack = 0

  # a safe default until we are told by the client what window size to use
  @window_size = 1 
end

Instance Method Details

#data(sequence, map, &block) ⇒ Object



240
241
242
243
244
245
246
# File 'lib/lumberjack/server.rb', line 240

def data(sequence, map, &block)
  block.call(map)
  if (sequence - @last_ack) >= @window_size
    @fd.syswrite(["1A", sequence].pack("A*N"))
    @last_ack = sequence
  end
end

#run(&block) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/lumberjack/server.rb', line 213

def run(&block)
  while true
    # TODO(sissel): Ack on idle.
    # X: - if any unacked, IO.select
    # X:   - on timeout, ack all.
    # X: Doing so will prevent slow streams from retransmitting
    # X: too many events after errors.
    @parser.feed(@fd.sysread(16384)) do |event, *args|
      case event
        when :window_size; window_size(*args, &block)
        when :data; data(*args, &block)
      end
      #send(event, *args)
    end # feed
  end # while true
rescue EOFError, OpenSSL::SSL::SSLError, IOError, Errno::ECONNRESET
  # EOF or other read errors, only action is to shutdown which we'll do in
  # 'ensure'
ensure
  # Try to ensure it's closed, but if this fails I don't care.
  @fd.close rescue nil
end

#window_size(size) ⇒ Object

def run



236
237
238
# File 'lib/lumberjack/server.rb', line 236

def window_size(size)
  @window_size = size
end