Class: Nl::Family
- Inherits:
-
Object
- Object
- Nl::Family
- Defined in:
- nl/lib/nl/family.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Session
Constant Summary collapse
- DEFAULT_NOTIFICATION_CAPACITY =
: Integer
Connection::DEFAULT_NOTIFICATION_CAPACITY
Instance Method Summary collapse
-
#async_capable? ⇒ Boolean
Returns if this family supports asynchronous operations.
-
#each_notification(&block) ⇒ Object
Receives unsolicited messages.
-
#initialize(connection, endpoint:) ⇒ Family
constructor
A new instance of Family.
-
#receive_notification(timeout: nil) ⇒ Object
Receives the next unsolicited message.
-
#subscribe(*groups) ⇒ Family
Adds multicast memberships to the netlink socket.
-
#unsubscribe(*groups) ⇒ Family
Removes multicast memberships from the netlink socket.
Constructor Details
#initialize(connection, endpoint:) ⇒ Family
Returns a new instance of Family.
51 52 53 54 55 56 57 58 |
# File 'nl/lib/nl/family.rb', line 51 def initialize(connection, endpoint:) @endpoint = endpoint @connection = connection @connection.register_notifications(@endpoint, notification_classes) @notification_stream = NotificationStream.new do |timeout| @connection.receive_notification(@endpoint, timeout:) end end |
Instance Method Details
#async_capable? ⇒ Boolean
Returns if this family supports asynchronous operations.
67 68 69 |
# File 'nl/lib/nl/family.rb', line 67 def async_capable? @connection.async_capable? end |
#each_notification(&block) ⇒ Object
Receives unsolicited messages.
103 104 105 106 107 |
# File 'nl/lib/nl/family.rb', line 103 def each_notification(&block) return @notification_stream.each unless block @notification_stream.each(&block) end |
#receive_notification(timeout: nil) ⇒ Object
Receives the next unsolicited message.
96 97 98 |
# File 'nl/lib/nl/family.rb', line 96 def receive_notification(timeout: nil) @notification_stream.next(timeout:) end |
#subscribe(*groups) ⇒ Family
Adds multicast memberships to the netlink socket.
Membership is additive and remains active until explicitly removed or the owner closes.
78 79 80 81 |
# File 'nl/lib/nl/family.rb', line 78 def subscribe(*groups) @connection.add_memberships(multicast_group_ids(groups)) self end |
#unsubscribe(*groups) ⇒ Family
Removes multicast memberships from the netlink socket.
88 89 90 91 |
# File 'nl/lib/nl/family.rb', line 88 def unsubscribe(*groups) @connection.drop_memberships(multicast_group_ids(groups)) self end |