avoid pairlistener crash
I noticed this while offline (so that lack of solar power is good for something). Apparently it tries to bind multicast to lo, and that fails. If this happens, catch it, and retry until a real network interface becomes available. It may be that this should tie into the NetWatcher, and rebind whenever an interface comes up. Needs testing..
This commit is contained in:
parent
b044dc2952
commit
f7214e4de3
1 changed files with 9 additions and 3 deletions
|
@ -17,6 +17,7 @@ import Assistant.DaemonStatus
|
|||
import Assistant.WebApp
|
||||
import Assistant.WebApp.Types
|
||||
import Assistant.Alert
|
||||
import Utility.ThreadScheduler
|
||||
|
||||
import Network.Multicast
|
||||
import Network.Socket
|
||||
|
@ -27,12 +28,17 @@ thisThread :: ThreadName
|
|||
thisThread = "PairListener"
|
||||
|
||||
pairListenerThread :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> UrlRenderer -> NamedThread
|
||||
pairListenerThread st dstatus scanremotes urlrenderer = thread $ withSocketsDo $ do
|
||||
sock <- multicastReceiver (multicastAddress $ IPv4Addr undefined) pairingPort
|
||||
go sock [] []
|
||||
pairListenerThread st dstatus scanremotes urlrenderer = thread $ withSocketsDo $
|
||||
runEvery (Seconds 1) $ void $ tryIO $ do
|
||||
sock <- getsock
|
||||
go sock [] []
|
||||
where
|
||||
thread = NamedThread thisThread
|
||||
|
||||
{- Note this can crash if there's no network interface,
|
||||
- or only one like lo that doesn't support multicast. -}
|
||||
getsock = multicastReceiver (multicastAddress $ IPv4Addr undefined) pairingPort
|
||||
|
||||
go sock reqs cache = getmsg sock [] >>= \msg -> case readish msg of
|
||||
Nothing -> go sock reqs cache
|
||||
Just m -> do
|
||||
|
|
Loading…
Add table
Reference in a new issue