From 8bc3504ebf0161f5553f924c3cac6445d46e5728 Mon Sep 17 00:00:00 2001 From: Bin Jin Date: Tue, 14 Mar 2017 00:44:34 +0800 Subject: Tun: use non-blocking fd --- src/Network/WireGuard/TunListener.hs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/Network/WireGuard/TunListener.hs') 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)) -- cgit v1.2.3-59-g8ed1b