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:
Joey Hess 2012-10-10 16:48:06 -04:00
parent b044dc2952
commit f7214e4de3

View file

@ -17,6 +17,7 @@ import Assistant.DaemonStatus
import Assistant.WebApp import Assistant.WebApp
import Assistant.WebApp.Types import Assistant.WebApp.Types
import Assistant.Alert import Assistant.Alert
import Utility.ThreadScheduler
import Network.Multicast import Network.Multicast
import Network.Socket import Network.Socket
@ -27,12 +28,17 @@ thisThread :: ThreadName
thisThread = "PairListener" thisThread = "PairListener"
pairListenerThread :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> UrlRenderer -> NamedThread pairListenerThread :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> UrlRenderer -> NamedThread
pairListenerThread st dstatus scanremotes urlrenderer = thread $ withSocketsDo $ do pairListenerThread st dstatus scanremotes urlrenderer = thread $ withSocketsDo $
sock <- multicastReceiver (multicastAddress $ IPv4Addr undefined) pairingPort runEvery (Seconds 1) $ void $ tryIO $ do
go sock [] [] sock <- getsock
go sock [] []
where where
thread = NamedThread thisThread 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 go sock reqs cache = getmsg sock [] >>= \msg -> case readish msg of
Nothing -> go sock reqs cache Nothing -> go sock reqs cache
Just m -> do Just m -> do