Skip to content

Commit e202ab5

Browse files
authored
feat(conn): expose socket timeout methods (#86)
Allow cancelling specific blocking netlink I/O operations. This is available in other netlink derivatives libraries such as https://github.com/jsimonetti/rtnetlink, and it can be used to implement request specific cancellation support without closing the file descriptor. Signed-off-by: Fred Lotter <fred.lotter@canonical.com>
1 parent 3dc4086 commit e202ab5

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

client.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package wifi
22

3+
import (
4+
"time"
5+
)
6+
37
// A Client is a type which can access WiFi device actions and statistics
48
// using operating system-specific operations.
59
type Client struct {
@@ -55,3 +59,18 @@ func (c *Client) BSS(ifi *Interface) (*BSS, error) {
5559
func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
5660
return c.c.StationInfo(ifi)
5761
}
62+
63+
// SetDeadline sets the read and write deadlines associated with the connection.
64+
func (c *Client) SetDeadline(t time.Time) error {
65+
return c.c.SetDeadline(t)
66+
}
67+
68+
// SetReadDeadline sets the read deadline associated with the connection.
69+
func (c *Client) SetReadDeadline(t time.Time) error {
70+
return c.c.SetReadDeadline(t)
71+
}
72+
73+
// SetWriteDeadline sets the write deadline associated with the connection.
74+
func (c *Client) SetWriteDeadline(t time.Time) error {
75+
return c.c.SetWriteDeadline(t)
76+
}

client_linux.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ func (c *client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
195195
return stations, nil
196196
}
197197

198+
// SetDeadline sets the read and write deadlines associated with the connection.
199+
func (c *client) SetDeadline(t time.Time) error {
200+
return c.c.SetDeadline(t)
201+
}
202+
203+
// SetReadDeadline sets the read deadline associated with the connection.
204+
func (c *client) SetReadDeadline(t time.Time) error {
205+
return c.c.SetReadDeadline(t)
206+
}
207+
208+
// SetWriteDeadline sets the write deadline associated with the connection.
209+
func (c *client) SetWriteDeadline(t time.Time) error {
210+
return c.c.SetWriteDeadline(t)
211+
}
212+
198213
// get performs a request/response interaction with nl80211.
199214
func (c *client) get(
200215
cmd uint8,

client_others.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package wifi
66
import (
77
"fmt"
88
"runtime"
9+
"time"
910
)
1011

1112
// errUnimplemented is returned by all functions on platforms that
@@ -24,3 +25,6 @@ func (*client) StationInfo(_ *Interface) ([]*StationInfo, error) { return nil, e
2425
func (*client) Connect(_ *Interface, _ string) error { return errUnimplemented }
2526
func (*client) Disconnect(_ *Interface) error { return errUnimplemented }
2627
func (*client) ConnectWPAPSK(_ *Interface, _, _ string) error { return errUnimplemented }
28+
func (*client) SetDeadline(t time.Time) error { return errUnimplemented }
29+
func (*client) SetReadDeadline(t time.Time) error { return errUnimplemented }
30+
func (*client) SetWriteDeadline(t time.Time) error { return errUnimplemented }

0 commit comments

Comments
 (0)