module SocketActivation.GetSockets where

import Essentials

import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.Either (Either)
import System.IO (IO)

import qualified Network.Socket as Net

import SocketActivation.Concepts (Socket, Fd (..), Error)
import SocketActivation.GetFileDescriptors (getFileDescriptorList)
import SocketActivation.IO (IO' (IO', run))

getSocketList :: IO (Either Error [Socket])
getSocketList :: IO (Either Error [Socket])
getSocketList = forall a. IO' a -> IO (Either Error a)
run forall a b. (a -> b) -> a -> b
$
    forall a. IO (Either Error a) -> IO' a
IO' IO (Either Error [Fd])
getFileDescriptorList forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Fd -> IO Socket
fdSocket)

fdSocket :: Fd -> IO Socket
fdSocket :: Fd -> IO Socket
fdSocket (Fd CInt
i) = CInt -> IO Socket
Net.mkSocket CInt
i