Class: Fluent::PluginHelper::Server::CallbackSocket

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

Instance Method Summary collapse

Constructor Details

#initialize(server_type, sock, enabled_events = [], close_socket: true) ⇒ CallbackSocket

Returns a new instance of CallbackSocket.



403
404
405
406
407
408
409
# File 'lib/fluent/plugin_helper/server.rb', line 403

def initialize(server_type, sock, enabled_events = [], close_socket: true)
  @server_type = server_type
  @sock = sock
  @peeraddr = nil
  @enabled_events = enabled_events
  @close_socket = close_socket
end

Instance Method Details

#closeObject



435
436
437
# File 'lib/fluent/plugin_helper/server.rb', line 435

def close
  @sock.close if @close_socket
end

#close_after_write_completeObject



431
432
433
# File 'lib/fluent/plugin_helper/server.rb', line 431

def close_after_write_complete
  @sock.close_after_write_complete = true
end

#data(&callback) ⇒ Object



439
440
441
# File 'lib/fluent/plugin_helper/server.rb', line 439

def data(&callback)
  on(:data, &callback)
end

#on(event, &callback) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/fluent/plugin_helper/server.rb', line 443

def on(event, &callback)
  raise "BUG: this event is disabled for #{@server_type}: #{event}" unless @enabled_events.include?(event)
  case event
  when :data
    @sock.data(&callback)
  when :write_complete
    cb = ->(){ callback.call(self) }
    @sock.on_write_complete(&cb)
  when :close
    cb = ->(){ callback.call(self) }
    @sock.on_close(&cb)
  else
    raise "BUG: unknown event: #{event}"
  end
end

#remote_addrObject



411
412
413
# File 'lib/fluent/plugin_helper/server.rb', line 411

def remote_addr
  @peeraddr[3]
end

#remote_hostObject



415
416
417
# File 'lib/fluent/plugin_helper/server.rb', line 415

def remote_host
  @peeraddr[2]
end

#remote_portObject



419
420
421
# File 'lib/fluent/plugin_helper/server.rb', line 419

def remote_port
  @peeraddr[1]
end

#send(data, flags = 0) ⇒ Object



423
424
425
# File 'lib/fluent/plugin_helper/server.rb', line 423

def send(data, flags = 0)
  @sock.send(data, flags)
end

#write(data) ⇒ Object



427
428
429
# File 'lib/fluent/plugin_helper/server.rb', line 427

def write(data)
  raise "not implemented here"
end