Class: Nl::Connection
- Inherits:
-
Object
- Object
- Nl::Connection
- Defined in:
- nl/lib/nl/connection.rb
Overview
Owns one Netlink socket and the facilities shared by families using it.
Constant Summary collapse
- DEFAULT_NOTIFICATION_CAPACITY =
1_024
Instance Method Summary collapse
- #add_memberships(group_ids) ⇒ Object
- #async_capable? ⇒ Boolean
- #close ⇒ Object
- #drop_memberships(group_ids) ⇒ Object
- #exchange ⇒ Object
- #exchange_async ⇒ Object
-
#initialize(protocol:, executor: nil, notification_capacity: DEFAULT_NOTIFICATION_CAPACITY) ⇒ Connection
constructor
A new instance of Connection.
- #receive_notification(endpoint, timeout: nil) ⇒ Object
- #register_notifications(endpoint, classes) ⇒ Object
Constructor Details
#initialize(protocol:, executor: nil, notification_capacity: DEFAULT_NOTIFICATION_CAPACITY) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'nl/lib/nl/connection.rb', line 11 def initialize(protocol:, executor: nil, notification_capacity: DEFAULT_NOTIFICATION_CAPACITY) socket = Socket.new(protocol.protonum) socket.bind(Socket.sockaddr_nl(0, 0)) notifications = NotificationRouter.new( protocol:, capacity: notification_capacity, ) @socket = socket @notifications = notifications @transport = if executor Async::Dispatcher.new(socket, protocol:, executor:, notifications:) else BlockingTransport.new(socket, protocol:, notifications:) end rescue Exception @transport ? @transport.close : socket&.close notifications&.close raise end |
Instance Method Details
#add_memberships(group_ids) ⇒ Object
40 41 42 43 |
# File 'nl/lib/nl/connection.rb', line 40 def add_memberships(group_ids) group_ids.each { @socket.add_membership(it) } nil end |
#async_capable? ⇒ Boolean
34 |
# File 'nl/lib/nl/connection.rb', line 34 def async_capable? = @transport.async_capable? |
#close ⇒ Object
54 55 56 57 58 59 |
# File 'nl/lib/nl/connection.rb', line 54 def close @transport.close nil ensure @notifications.close end |
#drop_memberships(group_ids) ⇒ Object
45 46 47 48 |
# File 'nl/lib/nl/connection.rb', line 45 def drop_memberships(group_ids) group_ids.each { @socket.drop_membership(it) } nil end |
#exchange ⇒ Object
32 |
# File 'nl/lib/nl/connection.rb', line 32 def exchange(...) = @transport.exchange(...) |
#exchange_async ⇒ Object
33 |
# File 'nl/lib/nl/connection.rb', line 33 def exchange_async(...) = @transport.exchange_async(...) |
#receive_notification(endpoint, timeout: nil) ⇒ Object
50 51 52 |
# File 'nl/lib/nl/connection.rb', line 50 def receive_notification(endpoint, timeout: nil) @transport.receive_notification(endpoint, timeout:) end |
#register_notifications(endpoint, classes) ⇒ Object
36 37 38 |
# File 'nl/lib/nl/connection.rb', line 36 def register_notifications(endpoint, classes) @notifications.register(endpoint, classes) end |