nl 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fbd6064a908ddacbadbb65eaa2f7c7ab862baf91478804f1915ba988271b759
4
- data.tar.gz: f49043a50d47c82da9f1f818f02948a12f386df091b7041e4ae1b7d755780b23
3
+ metadata.gz: 79ef39fff2bdef294954fb2504056339d504229a5ea65c967319f16bdbe23baf
4
+ data.tar.gz: b5f40b4f424d888406b6d2d6998e2182a5303fc2d4c4ad5d5be6c9d95005731d
5
5
  SHA512:
6
- metadata.gz: 0f162b7c19214639fdd277bea5fdedb1ef4661a8747de0458b08dd85fefa94ec36dfbbd71b039ef5143069ca903e54d133029528dd4a75cee865d6b409db7251
7
- data.tar.gz: c538d2a693926047576fc49bd82fd0bf435cbe19e3c61c21536826a0d873f260b87f2b6544dec4dac73e5385c11baa1da741c901bd81f2711eadb827cf34f356
6
+ metadata.gz: 61b396c794cbb4b65538ecaf605aa954b01ec4bbf53d80169b5cc0804c6176405b5c75dc6776f5a5af63091ef94a1f02fd48604c4a801836cadde0567b8a8855
7
+ data.tar.gz: 37cbe64bd74bd5d47fca5c5306ee8f490dfe84445595e8db7ed02716de2abbe2eff3594b806ef9ece125ab03d11fd9f4aa826347447aafce62f5e5c00941bcd7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v0.4.2 (2026-09-09)
6
+
5
7
  ## v0.4.1 (2026-09-08)
6
8
 
7
9
  ## v0.4.0 (2026-09-08)
data/lib/nl/endian.rb CHANGED
@@ -1,6 +1,5 @@
1
- # Byte-order helpers
2
-
3
1
  module Nl
2
+ # Byte-order helpers
4
3
  module Endian
5
4
  # sizeof(int)
6
5
  SIZEOF_INT = [1].pack('i!').bytesize
data/lib/nl/family.rb CHANGED
@@ -34,18 +34,20 @@ module Nl
34
34
  # end
35
35
 
36
36
  class Family
37
- DEFAULT_NOTIFICATION_CAPACITY = Connection::DEFAULT_NOTIFICATION_CAPACITY
37
+ DEFAULT_NOTIFICATION_CAPACITY = Connection::DEFAULT_NOTIFICATION_CAPACITY #: Integer
38
38
 
39
+ # Socket-owning family.
40
+ #
41
+ # {Family} instances that owns sockets are extended with this module.
39
42
  module Session
40
- def close #: nil
43
+ # Closes the Netlink socket owned by this {Family}.
44
+ # @rbs () -> void
45
+ def close
41
46
  @connection.close
42
47
  end
43
48
  end
44
49
 
45
- #--
46
- # @rbs connection: _Connection
47
- # @rbs endpoint: Raw::Endpoint
48
- # @rbs return: instance
50
+ # @rbs (_Connection connection, endpoint: Raw::Endpoint) -> instance
49
51
  def initialize(connection, endpoint:)
50
52
  @endpoint = endpoint
51
53
  @connection = connection
@@ -59,38 +61,54 @@ module Nl
59
61
  @connection.exchange(@endpoint, kind, request_class, reply_class, args, &block)
60
62
  end
61
63
 
62
- def async_capable? #: bool
64
+ # Returns if this family supports asynchronous operations.
65
+ #
66
+ # @rbs () -> bool
67
+ def async_capable?
63
68
  @connection.async_capable?
64
69
  end
65
70
 
66
- # Adds multicast memberships to the existing family socket. Membership is
67
- # additive and remains active until explicitly removed or the owner closes.
71
+ # Adds multicast memberships to the netlink socket.
72
+ #
73
+ # Membership is additive and remains active until explicitly removed or the owner closes.
74
+ #
75
+ # @param [Array<Symbol>] groups
76
+ # @return [Family] self
77
+ # @rbs (Symbol *groups) -> self
68
78
  def subscribe(*groups)
69
79
  @connection.add_memberships(multicast_group_ids(groups))
70
80
  self
71
81
  end
72
82
 
83
+ # Removes multicast memberships from the netlink socket.
84
+ #
85
+ # @param [Array<Symbol>] groups
86
+ # @return [Family] self
87
+ # @rbs (Symbol *groups) -> self
73
88
  def unsubscribe(*groups)
74
89
  @connection.drop_memberships(multicast_group_ids(groups))
75
90
  self
76
91
  end
77
92
 
93
+ # Receives the next unsolicited message.
94
+ #
95
+ # @rbs (?timeout: Integer?) -> Message
78
96
  def receive_notification(timeout: nil)
79
97
  @notification_stream.next(timeout:)
80
98
  end
81
99
 
100
+ # Receives unsolicited messages.
101
+ #
102
+ # @rbs () { (Message) -> void } -> void
82
103
  def each_notification(&block)
83
104
  return @notification_stream.each unless block
84
105
 
85
106
  @notification_stream.each(&block)
86
107
  end
87
108
 
88
- # Builds a generated asynchronous-operation facade with a narrowly scoped
89
- # callback, so the facade does not need access to Family's private API.
90
- #--
91
- # @rbs operations_class: Class
92
- # @rbs stream_capacity: Integer?
93
- # @rbs return: untyped
109
+ # Builds a asynchronous-operation facade.
110
+ #
111
+ # @rbs (Class operations_class, ?stream_capacity: Integer?) -> untyped
94
112
  private def build_async_facade(operations_class, stream_capacity: nil)
95
113
  unless async_capable?
96
114
  raise Async::UnavailableError, 'async operations require an executor'
@@ -1,4 +1,5 @@
1
1
  # Generic Netlink client handling
2
+ #-
2
3
 
3
4
  require_relative '../connection'
4
5
  require_relative 'wire'
data/lib/nl/genl/wire.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Generic Netlink wire definitions
2
+ #-
2
3
 
3
4
  require_relative '../raw/wire'
4
5
  require_relative '../endian'
data/lib/nl/genl.rb CHANGED
@@ -1,5 +1,3 @@
1
- # Generic Netlink family support
2
-
3
1
  require_relative 'genl/wire'
4
2
  require_relative 'family'
5
3
  require_relative 'raw'
data/lib/nl/raw/client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Raw Netlink client handling
2
+ #-
2
3
 
3
4
  require_relative '../connection'
4
5
  require_relative 'protocol'
@@ -73,7 +74,6 @@ module Nl
73
74
  # Closes the underlying Netlink connection.
74
75
  #
75
76
  # @return [void]
76
- #--
77
77
  # @rbs () -> void
78
78
  def close
79
79
  @connection.close
data/lib/nl/raw/wire.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Netlink wire definitions
2
+ #-
2
3
 
3
4
  require_relative '../endian'
4
5
 
data/lib/nl/socket.rb CHANGED
@@ -1,15 +1,15 @@
1
- # Netlink sockets
2
-
3
1
  require 'socket'
4
2
 
5
3
  module Nl
6
4
  # Netlink socket
7
5
  class Socket < ::Socket
8
6
  module Constants
9
- # From include/linux/socket.h
7
+ # From linux/socket.h
8
+ #-
10
9
  PF_NETLINK = AF_NETLINK = 16
11
10
 
12
- # From include/uapi/linux/netlink.h
11
+ # From linux/netlink.h
12
+ #-
13
13
  SOL_NETLINK = 270
14
14
  NETLINK_ADD_MEMBERSHIP = 1
15
15
  NETLINK_DROP_MEMBERSHIP = 2
@@ -17,17 +17,28 @@ module Nl
17
17
  include Constants
18
18
 
19
19
  class << self
20
+ # Packs Netlink socket address
21
+ #
22
+ # @rbs (Integer pid, Integer groups) -> String
20
23
  def pack_sockaddr_nl(pid, groups) = [Socket::AF_NETLINK, 0, pid, groups].pack('S!S!LL')
21
24
  alias sockaddr_nl pack_sockaddr_nl
22
25
 
26
+ # Unpacks Netlink socket address
27
+ #
28
+ # @rbs (String) -> [Integer, Integer]
23
29
  def unpack_sockaddr_nl(sockaddr) = sockaddr.unpack('S!S!LL')[2..3]
24
30
  end
25
31
 
26
- # @param protonum [Integer] Netlink protocol number
32
+ # @param [Integer] protonum Netlink protocol number
33
+ # @rbs (Integer) -> void
27
34
  def initialize(protonum)
28
35
  super(PF_NETLINK, SOCK_RAW, protonum)
29
36
  end
30
37
 
38
+ # Opens a Netlink socket for the specified protocol number.
39
+ #
40
+ # @rbs (Integer protonum) -> instance
41
+ # | [R] (Integer protonum) { (instance) -> R } -> R
31
42
  def self.open(protonum)
32
43
  return new(protonum) unless block_given?
33
44
  begin
@@ -39,16 +50,21 @@ module Nl
39
50
  end
40
51
 
41
52
  # @return [Integer] Local Netlink port ID assigned to this socket
53
+ # @rbs () -> Integer
42
54
  def local_port_id
43
55
  Socket.unpack_sockaddr_nl(local_address.to_sockaddr).first
44
56
  end
45
57
 
46
58
  # Adds this socket to a Netlink multicast group.
59
+ #
60
+ # @rbs (Integer group_id) -> void
47
61
  def add_membership(group_id)
48
62
  setsockopt(SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, group_id)
49
63
  end
50
64
 
51
65
  # Removes this socket from a Netlink multicast group.
66
+ #
67
+ # @rbs (Integer group_id) -> void
52
68
  def drop_membership(group_id)
53
69
  setsockopt(SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, group_id)
54
70
  end
data/lib/nl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nl
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -1,6 +1,7 @@
1
1
  # Generated from lib/nl/endian.rb with RBS::Inline
2
2
 
3
3
  module Nl
4
+ # Byte-order helpers
4
5
  module Endian
5
6
  # sizeof(int)
6
7
  SIZEOF_INT: untyped
@@ -26,38 +26,56 @@ module Nl
26
26
  end
27
27
 
28
28
  class Family
29
- DEFAULT_NOTIFICATION_CAPACITY: untyped
29
+ DEFAULT_NOTIFICATION_CAPACITY: Integer
30
30
 
31
+ # Socket-owning family.
32
+ #
33
+ # {Family} instances that owns sockets are extended with this module.
31
34
  module Session
32
- def close: () -> nil
35
+ # Closes the Netlink socket owned by this {Family}.
36
+ # @rbs () -> void
37
+ def close: () -> void
33
38
  end
34
39
 
35
- # --
36
- # @rbs connection: _Connection
37
- # @rbs endpoint: Raw::Endpoint
38
- # @rbs return: instance
40
+ # @rbs (_Connection connection, endpoint: Raw::Endpoint) -> instance
39
41
  def initialize: (_Connection connection, endpoint: Raw::Endpoint) -> instance
40
42
 
41
43
  private def exchange_message: (untyped kind, untyped request_class, untyped reply_class, untyped args) ?{ (?) -> untyped } -> untyped
42
44
 
45
+ # Returns if this family supports asynchronous operations.
46
+ #
47
+ # @rbs () -> bool
43
48
  def async_capable?: () -> bool
44
49
 
45
- # Adds multicast memberships to the existing family socket. Membership is
46
- # additive and remains active until explicitly removed or the owner closes.
47
- def subscribe: (*untyped groups) -> untyped
48
-
49
- def unsubscribe: (*untyped groups) -> untyped
50
-
51
- def receive_notification: (?timeout: untyped) -> untyped
52
-
53
- def each_notification: () ?{ (?) -> untyped } -> untyped
54
-
55
- # Builds a generated asynchronous-operation facade with a narrowly scoped
56
- # callback, so the facade does not need access to Family's private API.
57
- # --
58
- # @rbs operations_class: Class
59
- # @rbs stream_capacity: Integer?
60
- # @rbs return: untyped
50
+ # Adds multicast memberships to the netlink socket.
51
+ #
52
+ # Membership is additive and remains active until explicitly removed or the owner closes.
53
+ #
54
+ # @param [Array<Symbol>] groups
55
+ # @return [Family] self
56
+ # @rbs (Symbol *groups) -> self
57
+ def subscribe:
58
+
59
+ # Removes multicast memberships from the netlink socket.
60
+ #
61
+ # @param [Array<Symbol>] groups
62
+ # @return [Family] self
63
+ # @rbs (Symbol *groups) -> self
64
+ def unsubscribe:
65
+
66
+ # Receives the next unsolicited message.
67
+ #
68
+ # @rbs (?timeout: Integer?) -> Message
69
+ def receive_notification: (?timeout: Integer?) -> Message
70
+
71
+ # Receives unsolicited messages.
72
+ #
73
+ # @rbs () { (Message) -> void } -> void
74
+ def each_notification: () { (Message) -> void } -> void
75
+
76
+ # Builds a asynchronous-operation facade.
77
+ #
78
+ # @rbs (Class operations_class, ?stream_capacity: Integer?) -> untyped
61
79
  private def build_async_facade: (Class operations_class, ?stream_capacity: Integer?) -> untyped
62
80
 
63
81
  private def exchange_message_async: (untyped kind, untyped request_class, untyped reply_class, untyped args, ?stream_capacity: untyped) -> untyped
@@ -42,7 +42,6 @@ module Nl
42
42
  # Closes the underlying Netlink connection.
43
43
  #
44
44
  # @return [void]
45
- # --
46
45
  # @rbs () -> void
47
46
  def close: () -> void
48
47
  end
@@ -4,10 +4,12 @@ module Nl
4
4
  # Netlink socket
5
5
  class Socket < ::Socket
6
6
  module Constants
7
- # From include/linux/socket.h
7
+ # From linux/socket.h
8
+ # -
8
9
  PF_NETLINK: untyped
9
10
 
10
- # From include/uapi/linux/netlink.h
11
+ # From linux/netlink.h
12
+ # -
11
13
  SOL_NETLINK: ::Integer
12
14
 
13
15
  NETLINK_ADD_MEMBERSHIP: ::Integer
@@ -17,24 +19,41 @@ module Nl
17
19
 
18
20
  include Constants
19
21
 
20
- def self.pack_sockaddr_nl: (untyped pid, untyped groups) -> untyped
22
+ # Packs Netlink socket address
23
+ #
24
+ # @rbs (Integer pid, Integer groups) -> String
25
+ def self.pack_sockaddr_nl: (Integer pid, Integer groups) -> String
21
26
 
22
27
  alias self.sockaddr_nl self.pack_sockaddr_nl
23
28
 
24
- def self.unpack_sockaddr_nl: (untyped sockaddr) -> untyped
29
+ # Unpacks Netlink socket address
30
+ #
31
+ # @rbs (String) -> [Integer, Integer]
32
+ def self.unpack_sockaddr_nl: (String) -> [ Integer, Integer ]
25
33
 
26
- # @param protonum [Integer] Netlink protocol number
27
- def initialize: (untyped protonum) -> untyped
34
+ # @param [Integer] protonum Netlink protocol number
35
+ # @rbs (Integer) -> void
36
+ def initialize: (Integer) -> void
28
37
 
29
- def self.open: (untyped protonum) -> untyped
38
+ # Opens a Netlink socket for the specified protocol number.
39
+ #
40
+ # @rbs (Integer protonum) -> instance
41
+ # | [R] (Integer protonum) { (instance) -> R } -> R
42
+ def self.open: (Integer protonum) -> instance
43
+ | [R] (Integer protonum) { (instance) -> R } -> R
30
44
 
31
45
  # @return [Integer] Local Netlink port ID assigned to this socket
32
- def local_port_id: () -> untyped
46
+ # @rbs () -> Integer
47
+ def local_port_id: () -> Integer
33
48
 
34
49
  # Adds this socket to a Netlink multicast group.
35
- def add_membership: (untyped group_id) -> untyped
50
+ #
51
+ # @rbs (Integer group_id) -> void
52
+ def add_membership: (Integer group_id) -> void
36
53
 
37
54
  # Removes this socket from a Netlink multicast group.
38
- def drop_membership: (untyped group_id) -> untyped
55
+ #
56
+ # @rbs (Integer group_id) -> void
57
+ def drop_membership: (Integer group_id) -> void
39
58
  end
40
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasumi Hanazuki
@@ -93,7 +93,7 @@ licenses:
93
93
  - MIT
94
94
  metadata:
95
95
  homepage_uri: https://github.com/hanazuki/nl
96
- source_code_uri: https://github.com/hanazuki/nl/tree/v0.4.1
96
+ source_code_uri: https://github.com/hanazuki/nl/tree/v0.4.2
97
97
  changelog_uri: https://github.com/hanazuki/nl/blob/master/CHANGELOG.md
98
98
  rdoc_options: []
99
99
  require_paths: