Skip to content

Commit

Permalink
Merge pull request #20 from lebck/feat/configurable-scan-timeout
Browse files Browse the repository at this point in the history
Make scan timeout configurable
  • Loading branch information
penguinpowernz authored Oct 30, 2022
2 parents 87bea7e + 53b1947 commit fbdd402
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type WPAConn interface {

// Client represents a wireless client
type Client struct {
conn WPAConn
conn WPAConn
ScanTimeout time.Duration
}

// NewClient will create a new client by connecting to the
Expand Down Expand Up @@ -68,6 +69,12 @@ func (cl *Client) Status() (State, error) {

// Scan will scan for networks and return the APs it finds
func (cl *Client) Scan() (nets APs, err error) {
timeout := cl.ScanTimeout

if timeout == 0 {
timeout = 2 * time.Second
}

err = cl.conn.SendCommandBool(CmdScan)
if err != nil {
return
Expand All @@ -84,7 +91,7 @@ func (cl *Client) Scan() (nets APs, err error) {
return
case <-results.Next():
return
case <-time.NewTimer(time.Second * 2).C:
case <-time.NewTimer(cl.ScanTimeout).C:
return
}
}
Expand Down

0 comments on commit fbdd402

Please sign in to comment.