diff options
Diffstat (limited to 'src/Network/WireGuard')
-rw-r--r-- | src/Network/WireGuard/Foreign/Tun.hs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/Network/WireGuard/Foreign/Tun.hs b/src/Network/WireGuard/Foreign/Tun.hs index 2d0f929..3fdbbd4 100644 --- a/src/Network/WireGuard/Foreign/Tun.hs +++ b/src/Network/WireGuard/Foreign/Tun.hs @@ -14,17 +14,15 @@ import System.Posix.Types (Fd (..)) import Foreign import Foreign.C -openTun :: String -> Int -> IO (Maybe [Fd]) +openTun :: String -> Int -> IO [Fd] openTun intfName threads = withCString intfName $ \intf_name_c -> allocaArray threads $ \fds_c -> do - res <- tun_alloc_c intf_name_c (fromIntegral threads) fds_c -- TODO: handle exception - if res > 0 - then do - fds <- peekArray (fromIntegral res) fds_c - forM_ fds $ \fd -> setNonBlockingFD fd True - return (Just (map Fd fds)) - else return Nothing + res <- throwErrnoIfMinus1Retry "openTun" $ + tun_alloc_c intf_name_c (fromIntegral threads) fds_c + fds <- peekArray (fromIntegral res) fds_c + forM_ fds $ \fd -> setNonBlockingFD fd True + return (map Fd fds) tunReadBuf :: Fd -> Ptr Word8 -> CSize -> IO CSize tunReadBuf _fd _buf 0 = return 0 |