aboutsummaryrefslogtreecommitdiffstats
path: root/src/Network/WireGuard/Internal/Util.hs
diff options
context:
space:
mode:
authorBin Jin <bjin@ctrl-d.org>2017-03-14 21:18:00 +0800
committerBin Jin <bjin@ctrl-d.org>2017-03-14 21:18:00 +0800
commita60988db82aed029b71531e8a4bc5698fa247c02 (patch)
treebcf9432ac5b0ee14c8e89fb0a4c7e0eece013616 /src/Network/WireGuard/Internal/Util.hs
parentRemove unused language extension pragma (diff)
downloadwireguard-hs-a60988db82aed029b71531e8a4bc5698fa247c02.tar.xz
wireguard-hs-a60988db82aed029b71531e8a4bc5698fa247c02.zip
Tun: add timestamp for incoming packets
Diffstat (limited to '')
-rw-r--r--src/Network/WireGuard/Internal/Util.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Network/WireGuard/Internal/Util.hs b/src/Network/WireGuard/Internal/Util.hs
index f7ecde5..6aefee7 100644
--- a/src/Network/WireGuard/Internal/Util.hs
+++ b/src/Network/WireGuard/Internal/Util.hs
@@ -7,6 +7,7 @@ module Network.WireGuard.Internal.Util
, catchIOExceptionAnd
, catchSomeExceptionAnd
, withJust
+ , dropUntilM
, zeroMemory
, copyMemory
) where
@@ -52,6 +53,15 @@ withJust mma func = do
Nothing -> return ()
Just a -> func a
+dropUntilM :: Monad m => (a -> Bool) -> m a -> m a
+dropUntilM cond ma = loop
+ where
+ loop = do
+ a <- ma
+ if cond a
+ then return a
+ else loop
+
zeroMemory :: Ptr a -> CSize -> IO ()
zeroMemory dest nbytes = memset dest 0 (fromIntegral nbytes)