From d646a84764f46ee4f772d7c1f2edeecd9a18ec54 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 12 Nov 2017 18:09:56 -0500 Subject: Removed redundant SocketLike module. --- Presence/LocalPeerCred.hs | 2 +- Presence/SocketLike.hs | 76 ----------------------------------------------- 2 files changed, 1 insertion(+), 77 deletions(-) delete mode 100644 Presence/SocketLike.hs diff --git a/Presence/LocalPeerCred.hs b/Presence/LocalPeerCred.hs index 6f7735dd..3396358e 100644 --- a/Presence/LocalPeerCred.hs +++ b/Presence/LocalPeerCred.hs @@ -18,7 +18,7 @@ import Data.Bits import System.Posix.Types import System.Posix.Files import Logging -import SocketLike +import Network.SocketLike import ControlMaybe xs ?? n | n < 0 = Nothing diff --git a/Presence/SocketLike.hs b/Presence/SocketLike.hs deleted file mode 100644 index af0249ae..00000000 --- a/Presence/SocketLike.hs +++ /dev/null @@ -1,76 +0,0 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -module SocketLike - ( SocketLike - , getSocketName - , getPeerName - , getPeerCred - , socketPort - , sIsConnected - , sIsBound - , sIsListening - , sIsReadable - , sIsWritable - , sClose - , RestrictedSocket - , restrictSocket - , restrictHandleSocket - , PortNumber - , SockAddr(..) - , CUInt - ) where - -import Network.Socket - ( PortNumber - , SockAddr - ) -import Foreign.C.Types ( CUInt ) - -import qualified Network.Socket as NS -import System.IO (Handle,hClose) - -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 - sClose :: sock -> IO () - -instance SocketLike NS.Socket where - getSocketName = NS.getSocketName - getPeerName = NS.getPeerName - getPeerCred = NS.getPeerCred - socketPort = NS.socketPort - sIsConnected = NS.sIsConnected -- warning: this is always False if the socket - -- was converted to a Handle - sIsBound = NS.sIsBound - sIsListening = NS.sIsListening - sIsReadable = NS.sIsReadable - sIsWritable = NS.sIsWritable - - sClose = NS.sClose - --- newtype RestrictedSocket = Restricted NS.Socket deriving (SocketLike,Show) -data RestrictedSocket = Restricted (Maybe Handle) NS.Socket deriving Show - -instance SocketLike RestrictedSocket where - getSocketName (Restricted mb sock) = NS.getSocketName sock - getPeerName (Restricted mb sock) = NS.getPeerName sock - getPeerCred (Restricted mb sock) = NS.getPeerCred sock - socketPort (Restricted mb sock) = NS.socketPort sock - sIsConnected (Restricted mb sock) = NS.sIsConnected sock - sIsBound (Restricted mb sock) = NS.sIsBound sock - sIsListening (Restricted mb sock) = NS.sIsListening sock - sIsReadable (Restricted mb sock) = NS.sIsReadable sock - sIsWritable (Restricted mb sock) = NS.sIsWritable sock - sClose (Restricted mb sock) = maybe (NS.sClose sock) (\h -> hClose h >> NS.sClose sock) mb - -restrictSocket :: NS.Socket -> RestrictedSocket -restrictSocket socket = Restricted Nothing socket - -restrictHandleSocket :: Handle -> NS.Socket -> RestrictedSocket -restrictHandleSocket h socket = Restricted (Just h) socket -- cgit v1.2.3