| |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
Contents | |||||||||||||||||||||||||||||||||||||||||||||
Description | |||||||||||||||||||||||||||||||||||||||||||||
The Network.Socket module is for when you want full control over sockets. Essentially the entire C socket API is exposed through this module; in general the operations follow the behaviour of the C functions of the same name (consult your favourite Unix networking book). A higher level interface to networking operations is provided through the module Network. | |||||||||||||||||||||||||||||||||||||||||||||
Synopsis | |||||||||||||||||||||||||||||||||||||||||||||
Types | |||||||||||||||||||||||||||||||||||||||||||||
data Socket | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
data Family | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
data SocketType | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
data SockAddr | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
data SocketStatus | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
type HostAddress = Word32 | |||||||||||||||||||||||||||||||||||||||||||||
data ShutdownCmd | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
type ProtocolNumber = CInt | |||||||||||||||||||||||||||||||||||||||||||||
data PortNumber | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
Socket Operations | |||||||||||||||||||||||||||||||||||||||||||||
socket :: Family -> SocketType -> ProtocolNumber -> IO Socket | |||||||||||||||||||||||||||||||||||||||||||||
connect :: Socket -> SockAddr -> IO () | |||||||||||||||||||||||||||||||||||||||||||||
bindSocket :: Socket -> SockAddr -> IO () | |||||||||||||||||||||||||||||||||||||||||||||
listen :: Socket -> Int -> IO () | |||||||||||||||||||||||||||||||||||||||||||||
accept :: Socket -> IO (Socket, SockAddr) | |||||||||||||||||||||||||||||||||||||||||||||
getPeerName :: Socket -> IO SockAddr | |||||||||||||||||||||||||||||||||||||||||||||
getSocketName :: Socket -> IO SockAddr | |||||||||||||||||||||||||||||||||||||||||||||
socketPort :: Socket -> IO PortNumber | |||||||||||||||||||||||||||||||||||||||||||||
socketToHandle :: Socket -> IOMode -> IO Handle | |||||||||||||||||||||||||||||||||||||||||||||
sendTo :: Socket -> String -> SockAddr -> IO Int | |||||||||||||||||||||||||||||||||||||||||||||
recvFrom :: Socket -> Int -> IO (String, Int, SockAddr) | |||||||||||||||||||||||||||||||||||||||||||||
send :: Socket -> String -> IO Int | |||||||||||||||||||||||||||||||||||||||||||||
recv :: Socket -> Int -> IO String | |||||||||||||||||||||||||||||||||||||||||||||
inet_addr :: String -> IO HostAddress | |||||||||||||||||||||||||||||||||||||||||||||
inet_ntoa :: HostAddress -> IO String | |||||||||||||||||||||||||||||||||||||||||||||
shutdown :: Socket -> ShutdownCmd -> IO () | |||||||||||||||||||||||||||||||||||||||||||||
sClose :: Socket -> IO () | |||||||||||||||||||||||||||||||||||||||||||||
Predicates on sockets | |||||||||||||||||||||||||||||||||||||||||||||
sIsConnected :: Socket -> IO Bool | |||||||||||||||||||||||||||||||||||||||||||||
sIsBound :: Socket -> IO Bool | |||||||||||||||||||||||||||||||||||||||||||||
sIsListening :: Socket -> IO Bool | |||||||||||||||||||||||||||||||||||||||||||||
sIsReadable :: Socket -> IO Bool | |||||||||||||||||||||||||||||||||||||||||||||
sIsWritable :: Socket -> IO Bool | |||||||||||||||||||||||||||||||||||||||||||||
Socket options | |||||||||||||||||||||||||||||||||||||||||||||
data SocketOption | |||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||
getSocketOption :: Socket -> SocketOption -> IO Int | |||||||||||||||||||||||||||||||||||||||||||||
setSocketOption :: Socket -> SocketOption -> Int -> IO () | |||||||||||||||||||||||||||||||||||||||||||||
Ancilliary data | |||||||||||||||||||||||||||||||||||||||||||||
Special Constants | |||||||||||||||||||||||||||||||||||||||||||||
aNY_PORT :: PortNumber | |||||||||||||||||||||||||||||||||||||||||||||
iNADDR_ANY :: HostAddress | |||||||||||||||||||||||||||||||||||||||||||||
sOMAXCONN :: Int | |||||||||||||||||||||||||||||||||||||||||||||
sOL_SOCKET :: Int | |||||||||||||||||||||||||||||||||||||||||||||
maxListenQueue :: Int | |||||||||||||||||||||||||||||||||||||||||||||
Initialisation | |||||||||||||||||||||||||||||||||||||||||||||
withSocketsDo :: IO a -> IO a | |||||||||||||||||||||||||||||||||||||||||||||
On Windows operating systems, the networking subsystem has to be initialised using withSocketsDo before any networking operations can be used. eg. main = withSocketsDo $ do {...} Although this is only strictly necessary on Windows platforms, it is harmless on other platforms, so for portability it is good practice to use it all the time. | |||||||||||||||||||||||||||||||||||||||||||||
Very low level operations | |||||||||||||||||||||||||||||||||||||||||||||
fdSocket :: Socket -> CInt | |||||||||||||||||||||||||||||||||||||||||||||
mkSocket :: CInt -> Family -> SocketType -> ProtocolNumber -> SocketStatus -> IO Socket | |||||||||||||||||||||||||||||||||||||||||||||
Internal | |||||||||||||||||||||||||||||||||||||||||||||
The following are exported ONLY for use in the BSD module and should not be used anywhere else. | |||||||||||||||||||||||||||||||||||||||||||||
packFamily :: Family -> CInt | |||||||||||||||||||||||||||||||||||||||||||||
unpackFamily :: CInt -> Family | |||||||||||||||||||||||||||||||||||||||||||||
packSocketType :: SocketType -> CInt | |||||||||||||||||||||||||||||||||||||||||||||
Produced by Haddock version 0.3 |