diff options
author | jim@bo <jim@bo> | 2018-06-24 17:18:38 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-24 17:18:38 -0400 |
commit | a5fad52f1e1ca6d8ebfcbb448f19014225368777 (patch) | |
tree | 4b8e7b18cab555319f8b1f311f98476b6789e175 /examples/dhtd.hs | |
parent | d374ac3a60b7b013899568441ab66e8ffc945c6e (diff) |
new interval comand, modifies all intervals at once
session 0 interval
-- shows the values of intervals on session 0
session 0 interval 0.5
-- half all the intervals on session 0
Diffstat (limited to 'examples/dhtd.hs')
-rw-r--r-- | examples/dhtd.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index db56ec24..bf7d7162 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -764,6 +764,30 @@ clientSession s@Session{..} sock cnum h = do | |||
764 | _ -> | 764 | _ -> |
765 | hPutClient h $ "Invalid " ++ key ++ " value: " ++ val | 765 | hPutClient h $ "Invalid " ++ key ++ " value: " ++ val |
766 | 766 | ||
767 | -- session <N> interval factor | ||
768 | ("session",s) | (idStr,"interval",unstripped) <- twoWords s | ||
769 | , val <- strp unstripped | ||
770 | -> cmd0 $ do | ||
771 | lrSession <- strToSession idStr | ||
772 | let displayIntervals session = atomically $ do | ||
773 | intervals <- forM [Tox.ncRequestInterval,Tox.ncAliveInterval, Tox.ncIdleEvent, Tox.ncTimeOut] $ \i -> readTVar (i session) | ||
774 | let keys = ["ncRequestInterval","ncAliveInterval","ncIdleEvent","ncTimeOut"] | ||
775 | return (intercalate "\n" $ | ||
776 | map (\(key,val) -> "Session " ++ idStr ++ ": " ++ key ++ " = " ++ val) | ||
777 | (zip keys (map show intervals))) | ||
778 | case lrSession of | ||
779 | Left s -> hPutClient h s | ||
780 | Right session -> do | ||
781 | case readMaybe val of | ||
782 | Just (factor::Double) -> do | ||
783 | atomically $ do | ||
784 | modifyTVar (Tox.ncRequestInterval session) (round . (*factor) . fromIntegral) | ||
785 | modifyTVar (Tox.ncAliveInterval session) (round . (*factor) . fromIntegral) | ||
786 | modifyTVar (Tox.ncIdleEvent session) (round . (*factor) . fromIntegral) | ||
787 | modifyTVar (Tox.ncTimeOut session) (round . (*factor) . fromIntegral) | ||
788 | displayIntervals session >>= hPutClient h | ||
789 | _ -> displayIntervals session >>= hPutClient h . (("No parse (" ++ show val ++ ").\n") ++) | ||
790 | |||
767 | -- report error when setting invalid keys | 791 | -- report error when setting invalid keys |
768 | ("session",s) | (idStr,"set",unstripped) <- twoWords s | 792 | ("session",s) | (idStr,"set",unstripped) <- twoWords s |
769 | , (key,val,unstripped2) <- twoWords unstripped | 793 | , (key,val,unstripped2) <- twoWords unstripped |