Class: Nl::Family

Inherits:
Object
  • Object
show all
Defined in:
nl/lib/nl/family.rb

Direct Known Subclasses

Genl::Family, Raw::Family

Defined Under Namespace

Modules: Session

Constant Summary collapse

DEFAULT_NOTIFICATION_CAPACITY =

: Integer

Connection::DEFAULT_NOTIFICATION_CAPACITY

Instance Method Summary collapse

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.

Returns:

  • (Boolean)


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.

Parameters:

  • groups (Array<Symbol>)

Returns:



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.

Parameters:

  • groups (Array<Symbol>)

Returns:



88
89
90
91
# File 'nl/lib/nl/family.rb', line 88

def unsubscribe(*groups)
  @connection.drop_memberships(multicast_group_ids(groups))
  self
end