aboutsummaryrefslogtreecommitdiffstats
path: root/src/Network/WireGuard/TunListener.hs
diff options
context:
space:
mode:
authorBin Jin <bjin@ctrl-d.org>2017-03-14 00:44:34 +0800
committerBin Jin <bjin@ctrl-d.org>2017-03-14 00:44:34 +0800
commit8bc3504ebf0161f5553f924c3cac6445d46e5728 (patch)
tree8148814db4eda90dfd8ee5cdaee3af75a65b2170 /src/Network/WireGuard/TunListener.hs
parentUse dhPubEq for publickey equality check (diff)
downloadwireguard-hs-8bc3504ebf0161f5553f924c3cac6445d46e5728.tar.xz
wireguard-hs-8bc3504ebf0161f5553f924c3cac6445d46e5728.zip
Tun: use non-blocking fd
Diffstat (limited to 'src/Network/WireGuard/TunListener.hs')
-rw-r--r--src/Network/WireGuard/TunListener.hs18
1 files changed, 3 insertions, 15 deletions
diff --git a/src/Network/WireGuard/TunListener.hs b/src/Network/WireGuard/TunListener.hs
index d57cf98..46c290f 100644
--- a/src/Network/WireGuard/TunListener.hs
+++ b/src/Network/WireGuard/TunListener.hs
@@ -14,18 +14,12 @@ import Foreign.Marshal.Alloc (allocaBytes)
import Foreign.Ptr (Ptr)
import System.Posix.Types (Fd)
-import Network.WireGuard.Foreign.Tun (fdReadBuf, fdWriteBuf)
-
+import Network.WireGuard.Foreign.Tun
import Network.WireGuard.Internal.Constant
import Network.WireGuard.Internal.PacketQueue
import Network.WireGuard.Internal.Types
import Network.WireGuard.Internal.Util
-#ifdef OS_LINUX
-import Control.Concurrent (threadWaitRead,
- threadWaitWrite)
-#endif
-
runTunListener :: [Fd] -> PacketQueue TunPacket -> PacketQueue TunPacket -> IO ()
runTunListener fds readTunChan writeTunChan = loop fds []
where
@@ -45,16 +39,10 @@ handleWrite writeTunChan fd =
readFd :: BA.ByteArray ba => Ptr Word8 -> Fd -> IO ba
readFd buf fd = do
-#ifdef OS_LINUX
- threadWaitRead fd
-#endif
- nbytes <- fdReadBuf fd buf (fromIntegral tunReadBufferLength)
+ nbytes <- tunReadBuf fd buf (fromIntegral tunReadBufferLength)
snd <$> BA.allocRet (fromIntegral nbytes)
(\ptr -> copyMemory ptr buf nbytes >> zeroMemory buf nbytes)
writeFd :: BA.ByteArrayAccess ba => Fd -> ba -> IO ()
writeFd fd ba = BA.withByteArray ba $ \ptr -> do
-#ifdef OS_LINUX
- threadWaitWrite fd
-#endif
- void $ fdWriteBuf fd ptr (fromIntegral (BA.length ba))
+ void $ tunWriteBuf fd ptr (fromIntegral (BA.length ba))