{-# LINE 1 "src/Linux/Socket/Types.hsc" #-}
{-# language DerivingStrategies #-}
{-# language GeneralizedNewtypeDeriving #-}



-- | All of the data constructors provided by this module are unsafe.
--   Only use them if you really know what you are doing.
module Linux.Socket.Types
  ( SocketFlags(..)
  , dontWait
  , truncate
  , closeOnExec
  , nonblocking
  ) where

import Prelude hiding (truncate)

import Data.Bits (Bits((.|.)))
import Foreign.C.Types (CInt)
import Posix.Socket (MessageFlags(..))

newtype SocketFlags = SocketFlags CInt
  deriving stock (Eq)
  deriving newtype (Bits)

instance Semigroup SocketFlags where (<>) = (.|.)
instance Monoid SocketFlags where mempty = SocketFlags 0

-- | The @MSG_DONTWAIT@ receive flag or send flag.
dontWait :: MessageFlags m
dontWait = MessageFlags 64
{-# LINE 32 "src/Linux/Socket/Types.hsc" #-}

-- | The @MSG_TRUNC@ receive flag.
truncate :: MessageFlags m
truncate = MessageFlags 64
{-# LINE 36 "src/Linux/Socket/Types.hsc" #-}

-- | The @SOCK_CLOEXEC@ receive flag or send flag.
closeOnExec :: SocketFlags
closeOnExec = SocketFlags 524288
{-# LINE 40 "src/Linux/Socket/Types.hsc" #-}

-- | The @SOCK_NONBLOCK@ receive flag or send flag.
nonblocking :: SocketFlags
nonblocking = SocketFlags 2048
{-# LINE 44 "src/Linux/Socket/Types.hsc" #-}