Skip to content

Commit

Permalink
feat(conn): expose socket timeout methods (#86)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
flotter authored Sep 9, 2024
1 parent 3dc4086 commit e202ab5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package wifi

import (
"time"
)

// A Client is a type which can access WiFi device actions and statistics
// using operating system-specific operations.
type Client struct {
Expand Down Expand Up @@ -55,3 +59,18 @@ func (c *Client) BSS(ifi *Interface) (*BSS, error) {
func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
return c.c.StationInfo(ifi)
}

// SetDeadline sets the read and write deadlines associated with the connection.
func (c *Client) SetDeadline(t time.Time) error {
return c.c.SetDeadline(t)
}

// SetReadDeadline sets the read deadline associated with the connection.
func (c *Client) SetReadDeadline(t time.Time) error {
return c.c.SetReadDeadline(t)
}

// SetWriteDeadline sets the write deadline associated with the connection.
func (c *Client) SetWriteDeadline(t time.Time) error {
return c.c.SetWriteDeadline(t)
}
15 changes: 15 additions & 0 deletions client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ func (c *client) StationInfo(ifi *Interface) ([]*StationInfo, error) {
return stations, nil
}

// SetDeadline sets the read and write deadlines associated with the connection.
func (c *client) SetDeadline(t time.Time) error {
return c.c.SetDeadline(t)
}

// SetReadDeadline sets the read deadline associated with the connection.
func (c *client) SetReadDeadline(t time.Time) error {
return c.c.SetReadDeadline(t)
}

// SetWriteDeadline sets the write deadline associated with the connection.
func (c *client) SetWriteDeadline(t time.Time) error {
return c.c.SetWriteDeadline(t)
}

// get performs a request/response interaction with nl80211.
func (c *client) get(
cmd uint8,
Expand Down
4 changes: 4 additions & 0 deletions client_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package wifi
import (
"fmt"
"runtime"
"time"
)

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

0 comments on commit e202ab5

Please sign in to comment.