summaryrefslogtreecommitdiff
path: root/Assistant/Threads/NetWatcher.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-08-23 16:13:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-08-23 16:13:43 -0400
commit4a4f8064aee71d71d7ad2035f5e0156c41d3340f (patch)
tree96b939a5f499e61fca736d80d23ad0cbe8acb34c /Assistant/Threads/NetWatcher.hs
parent37b960d3b05fdcda083d364c8e63e82f4615048c (diff)
make the NetWatcher always rescan networked remotes every 30 minutes
There are multiple reasons to do this: * The local network may be up solid, but a route to a networked remote is having trouble. Any transfers to it that fail should be retried. * Someone might have wicd running, but like to bring up new networks by hand too. This way, it'll eventually notice them.
Diffstat (limited to 'Assistant/Threads/NetWatcher.hs')
-rw-r--r--Assistant/Threads/NetWatcher.hs26
1 files changed, 12 insertions, 14 deletions
diff --git a/Assistant/Threads/NetWatcher.hs b/Assistant/Threads/NetWatcher.hs
index 500eff1ce..2f71b0825 100644
--- a/Assistant/Threads/NetWatcher.hs
+++ b/Assistant/Threads/NetWatcher.hs
@@ -21,6 +21,7 @@ import Remote.List
import qualified Types.Remote as Remote
import qualified Control.Exception as E
+import Control.Concurrent
#if WITH_DBUS
import Utility.DBus
@@ -35,12 +36,17 @@ thisThread :: ThreadName
thisThread = "NetWatcher"
netWatcherThread :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> IO ()
-netWatcherThread st handle scanremotes =
+netWatcherThread st dstatus scanremotes = do
#if WITH_DBUS
- dbusThread st handle scanremotes
-#else
- pollingThread st handle scanremotes
+ void $ forkIO $ dbusThread st dstatus scanremotes
#endif
+ {- This is a fallback for when dbus cannot be used to detect
+ - network connection changes, but it also ensures that
+ - any networked remotes that may have not been routable for a
+ - while (despite the local network staying up), are synced with
+ - periodically. -}
+ runEvery (Seconds 3600) $
+ handleConnection st dstatus scanremotes
#if WITH_DBUS
@@ -54,14 +60,10 @@ dbusThread st dstatus scanremotes = E.catch (go =<< connectSystem) onerr
, do
runThreadState st $
warning "No known network monitor available through dbus; falling back to polling"
- pollinstead
)
onerr :: E.SomeException -> IO ()
- onerr e = do
- runThreadState st $
- warning $ "Failed to use dbus; falling back to polling (" ++ show e ++ ")"
- pollinstead
- pollinstead = pollingThread st dstatus scanremotes
+ onerr e = runThreadState st $
+ warning $ "Failed to use dbus; falling back to polling (" ++ show e ++ ")"
handle = do
debug thisThread ["detected network connection"]
handleConnection st dstatus scanremotes
@@ -118,10 +120,6 @@ listenWicdConnections client callback =
#endif
-pollingThread :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> IO ()
-pollingThread st dstatus scanremotes = runEvery (Seconds 3600) $
- handleConnection st dstatus scanremotes
-
handleConnection :: ThreadState -> DaemonStatusHandle -> ScanRemoteMap -> IO ()
handleConnection st dstatus scanremotes = do
reconnectRemotes thisThread st dstatus scanremotes =<<