Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scan timeout configurable #20

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -67,6 +68,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 @@ -83,7 +90,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