Class: Fluent::PluginHelper::Server::CallbackSocket
- Inherits:
-
Object
- Object
- Fluent::PluginHelper::Server::CallbackSocket
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.
374
375
376
377
378
379
380
|
# File 'lib/fluent/plugin_helper/server.rb', line 374
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
#close ⇒ Object
402
403
404
|
# File 'lib/fluent/plugin_helper/server.rb', line 402
def close
@sock.close if @close_socket
end
|
#data(&callback) ⇒ Object
406
407
408
|
# File 'lib/fluent/plugin_helper/server.rb', line 406
def data(&callback)
on(:data, &callback)
end
|
#on(event, &callback) ⇒ Object
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
# File 'lib/fluent/plugin_helper/server.rb', line 410
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_addr ⇒ Object
382
383
384
|
# File 'lib/fluent/plugin_helper/server.rb', line 382
def remote_addr
@peeraddr[3]
end
|
#remote_host ⇒ Object
386
387
388
|
# File 'lib/fluent/plugin_helper/server.rb', line 386
def remote_host
@peeraddr[2]
end
|
#remote_port ⇒ Object
390
391
392
|
# File 'lib/fluent/plugin_helper/server.rb', line 390
def remote_port
@peeraddr[1]
end
|
#send(data, flags = 0) ⇒ Object
394
395
396
|
# File 'lib/fluent/plugin_helper/server.rb', line 394
def send(data, flags = 0)
@sock.send(data, flags)
end
|
#write(data) ⇒ Object
398
399
400
|
# File 'lib/fluent/plugin_helper/server.rb', line 398
def write(data)
raise "not implemented here"
end
|