mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 10:53:43 +00:00
delay addition of extra error types until verifiably needed
This commit is contained in:
+12
-26
@@ -12,30 +12,15 @@ import (
|
|||||||
//go:linkname UseStack net.useNetdev
|
//go:linkname UseStack net.useNetdev
|
||||||
func UseStack(stack Stack)
|
func UseStack(stack Stack)
|
||||||
|
|
||||||
// GethostByName() errors
|
// Socket errors.
|
||||||
var (
|
var (
|
||||||
ErrHostUnknown = errors.New("host unknown")
|
|
||||||
ErrMalAddr = errors.New("malformed address")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Socket errors
|
|
||||||
var (
|
|
||||||
ErrFamilyNotSupported = errors.New("address family not supported")
|
|
||||||
ErrProtocolNotSupported = errors.New("socket protocol/type not supported")
|
ErrProtocolNotSupported = errors.New("socket protocol/type not supported")
|
||||||
ErrStartingDHCPClient = errors.New("error starting DHPC client")
|
|
||||||
ErrNoMoreSockets = errors.New("no more sockets")
|
|
||||||
ErrClosingSocket = errors.New("error closing socket")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Wifi errors.
|
||||||
var (
|
var (
|
||||||
ErrConnected = errors.New("already connected")
|
ErrAuthFailure = errors.New("wifi authentication failure")
|
||||||
ErrConnectFailed = errors.New("connect failed")
|
ErrAuthUnsupported = errors.New("wifi authorization type not supported")
|
||||||
ErrConnectTimeout = errors.New("connect timed out")
|
|
||||||
ErrMissingSSID = errors.New("missing WiFi SSID")
|
|
||||||
ErrAuthFailure = errors.New("wifi authentication failure")
|
|
||||||
ErrAuthTypeNoGood = errors.New("wifi authorization type not supported")
|
|
||||||
ErrConnectModeNoGood = errors.New("connect mode not supported")
|
|
||||||
ErrNotSupported = errors.New("not supported")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -152,7 +137,7 @@ type WifiParams struct {
|
|||||||
CountryCode string
|
CountryCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event int
|
type Event uint8
|
||||||
|
|
||||||
// Network events
|
// Network events
|
||||||
const (
|
const (
|
||||||
@@ -162,7 +147,7 @@ const (
|
|||||||
EventNetDown
|
EventNetDown
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConnectMode int
|
type ConnectMode uint8
|
||||||
|
|
||||||
// Connect modes
|
// Connect modes
|
||||||
const (
|
const (
|
||||||
@@ -170,7 +155,7 @@ const (
|
|||||||
ConnectModeAP // Connect as Wifi Access Point
|
ConnectModeAP // Connect as Wifi Access Point
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthType int
|
type AuthType uint8
|
||||||
|
|
||||||
// Wifi authorization types. Used when setting up an access point, or
|
// Wifi authorization types. Used when setting up an access point, or
|
||||||
// connecting to an access point
|
// connecting to an access point
|
||||||
@@ -186,7 +171,7 @@ type WifiAutoconnectParams struct {
|
|||||||
|
|
||||||
// Retries is how many attempts to connect before returning with a
|
// Retries is how many attempts to connect before returning with a
|
||||||
// "Connect failed" error. Zero means infinite retries.
|
// "Connect failed" error. Zero means infinite retries.
|
||||||
Retries int // Probably should be implemented as a function
|
// Retries int // Probably should be implemented as a function
|
||||||
|
|
||||||
// Timeout duration for each connection attempt. The default zero
|
// Timeout duration for each connection attempt. The default zero
|
||||||
// value means 10sec.
|
// value means 10sec.
|
||||||
@@ -200,22 +185,23 @@ type WifiAutoconnectParams struct {
|
|||||||
|
|
||||||
func StartWifiAutoconnect(dev InterfaceWifi, cfg WifiAutoconnectParams) error {
|
func StartWifiAutoconnect(dev InterfaceWifi, cfg WifiAutoconnectParams) error {
|
||||||
if dev == nil {
|
if dev == nil {
|
||||||
return ErrConnectModeNoGood
|
return errors.New("nil device")
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// Wifi autoconnect algorithm in one place,
|
// Wifi autoconnect algorithm in one place,
|
||||||
// no need to implement for every single netdever.
|
// no need to implement for every single netdever.
|
||||||
RECONNECT:
|
RECONNECT:
|
||||||
for i := 0; i < cfg.Retries; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
err := dev.NetConnect(cfg.WifiParams)
|
err := dev.NetConnect(cfg.WifiParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
time.Sleep(cfg.ConnectTimeout)
|
time.Sleep(cfg.ConnectTimeout)
|
||||||
goto RECONNECT
|
goto RECONNECT
|
||||||
}
|
}
|
||||||
|
// Once connected reset the retry counter.
|
||||||
|
i = 0
|
||||||
for cfg.WatchdogTimeout != 0 {
|
for cfg.WatchdogTimeout != 0 {
|
||||||
time.Sleep(cfg.WatchdogTimeout)
|
time.Sleep(cfg.WatchdogTimeout)
|
||||||
if dev.NetFlags()&net.FlagRunning == 0 {
|
if dev.NetFlags()&net.FlagRunning == 0 {
|
||||||
i = 0
|
|
||||||
goto RECONNECT
|
goto RECONNECT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user