{-# LANGUAGE GeneralizedNewtypeDeriving #-} module SocketLike ( SocketLike , getSocketName , getPeerName , getPeerCred , socketPort , sIsConnected , sIsBound , sIsListening , sIsReadable , sIsWritable , RestrictedSocket , restrictSocket , PortNumber , SockAddr(..) , CUInt ) where import Network.Socket ( PortNumber , SockAddr ) import Foreign.C.Types ( CUInt ) import qualified Network.Socket as NS class SocketLike sock where getSocketName :: sock -> IO SockAddr getPeerName :: sock -> IO SockAddr getPeerCred :: sock -> IO (CUInt, CUInt, CUInt) socketPort :: sock -> IO PortNumber sIsConnected :: sock -> IO Bool sIsBound :: sock -> IO Bool sIsListening :: sock -> IO Bool sIsReadable :: sock -> IO Bool sIsWritable :: sock -> IO Bool instance SocketLike NS.Socket where getSocketName = NS.getSocketName getPeerName = NS.getPeerName getPeerCred = NS.getPeerCred socketPort = NS.socketPort sIsConnected = NS.sIsConnected sIsBound = NS.sIsBound sIsListening = NS.sIsListening sIsReadable = NS.sIsReadable sIsWritable = NS.sIsWritable newtype RestrictedSocket = Restricted NS.Socket deriving SocketLike restrictSocket :: NS.Socket -> RestrictedSocket restrictSocket socket = Restricted socket