Safe Haskell | None |
---|---|
Language | Haskell98 |
System.Posix.Socket
Contents
Description
POSIX sockets.
- data Socket f
- withSocketFd :: MonadBase IO μ => Socket f -> (Fd -> IO α) -> μ α
- unsafeSocketFd :: MonadBase IO μ => Socket f -> μ Fd
- unsafeSocketFromFd :: MonadBase IO μ => Fd -> μ (Socket f)
- class SockAddr (SockFamilyAddr f) => SockFamily f where
- type SockFamilyAddr f
- class SockAddr a where
- newtype SockType = SockType CInt
- pattern SOCK_STREAM :: SockType
- pattern SOCK_DGRAM :: SockType
- pattern SOCK_RAW :: SockType
- pattern SOCK_RDM :: SockType
- pattern SOCK_SEQPACKET :: SockType
- newtype SockProto = SockProto CInt
- defaultSockProto :: SockProto
- class Storable (SockOptRaw o) => SockOpt o where
- type SockOptValue o
- type SockOptRaw o
- type SockOptReadable o :: Bool
- type SockOptWritable o :: Bool
- data SO_ERROR
- pattern SO_ERROR :: Proxy SO_ERROR
- data SO_KEEPALIVE
- pattern SO_KEEPALIVE :: Proxy SO_KEEPALIVE
- data SO_REUSEADDR
- pattern SO_REUSEADDR :: Proxy SO_REUSEADDR
- data SockOps
- newtype MsgFlags = MsgFlags CInt
- pattern MSG_PEEK :: MsgFlags
- pattern MSG_TRUNC :: MsgFlags
- pattern MSG_OOB :: MsgFlags
- pattern MSG_DONTROUTE :: MsgFlags
- socket :: (SockFamily f, MonadBase IO μ) => Proxy f -> SockType -> SockProto -> μ (Socket f)
- getSockOpt :: (SockOpt o, SockOptReadable o ~ True, MonadBase IO μ) => Socket f -> Proxy o -> μ (SockOptValue o)
- setSockOpt :: (SockOpt o, SockOptWritable o ~ True, MonadBase IO μ) => Socket f -> Proxy o -> SockOptValue o -> μ ()
- bind :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> SockFamilyAddr f -> μ ()
- connect :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> SockFamilyAddr f -> μ ()
- tryConnect :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> SockFamilyAddr f -> μ Bool
- listen :: MonadBase IO μ => Socket f -> Int -> μ ()
- accept :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (Socket f, SockFamilyAddr f)
- tryAccept :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (Maybe (Socket f, SockFamilyAddr f))
- getLocalAddr :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (SockFamilyAddr f)
- getRemoteAddr :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (SockFamilyAddr f)
- hasOobData :: MonadBase IO μ => Socket f -> μ Bool
- recvBufs :: (SockFamily f, MonadBase IO μ) => Socket f -> [(Ptr Word8, Int)] -> MsgFlags -> μ (Int, MsgFlags)
- recvBuf :: (SockFamily f, MonadBase IO μ) => Socket f -> Ptr α -> Int -> MsgFlags -> μ (Int, MsgFlags)
- recv' :: (SockFamily f, MonadBase IO μ) => Socket f -> Int -> MsgFlags -> μ (ByteString, MsgFlags)
- recv :: (SockFamily f, MonadBase IO μ) => Socket f -> Int -> μ ByteString
- recvBufsFrom :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> [(Ptr Word8, Int)] -> MsgFlags -> μ (SockFamilyAddr f, Int, MsgFlags)
- recvBufFrom :: (SockFamily f, MonadBase IO μ) => Socket f -> Ptr α -> Int -> MsgFlags -> μ (SockFamilyAddr f, Int, MsgFlags)
- recvFrom' :: (SockFamily f, MonadBase IO μ) => Socket f -> Int -> MsgFlags -> μ (SockFamilyAddr f, ByteString, MsgFlags)
- recvFrom :: (SockFamily f, MonadBase IO μ) => Socket f -> Int -> μ (SockFamilyAddr f, ByteString)
- sendBufs :: (SockFamily f, MonadBase IO μ) => Socket f -> [(Ptr Word8, Int)] -> MsgFlags -> μ Int
- sendMany' :: (SockFamily f, MonadBase IO μ) => Socket f -> [ByteString] -> MsgFlags -> μ Int
- sendMany :: (SockFamily f, MonadBase IO μ) => Socket f -> [ByteString] -> μ Int
- sendBuf :: (SockFamily f, MonadBase IO μ) => Socket f -> Ptr α -> Int -> MsgFlags -> μ Int
- send' :: (SockFamily f, MonadBase IO μ) => Socket f -> ByteString -> MsgFlags -> μ Int
- send :: (SockFamily f, MonadBase IO μ) => Socket f -> ByteString -> μ Int
- sendBufsTo :: (SockFamily f, MonadBase IO μ) => Socket f -> [(Ptr Word8, Int)] -> MsgFlags -> SockFamilyAddr f -> μ Int
- sendManyTo' :: (SockFamily f, MonadBase IO μ) => Socket f -> [ByteString] -> MsgFlags -> SockFamilyAddr f -> μ Int
- sendManyTo :: (SockFamily f, MonadBase IO μ) => Socket f -> [ByteString] -> SockFamilyAddr f -> μ Int
- sendBufTo :: (SockFamily f, MonadBase IO μ) => Socket f -> Ptr α -> Int -> MsgFlags -> SockFamilyAddr f -> μ Int
- sendTo' :: (SockFamily f, MonadBase IO μ) => Socket f -> ByteString -> MsgFlags -> SockFamilyAddr f -> μ Int
- sendTo :: (SockFamily f, MonadBase IO μ) => Socket f -> ByteString -> SockFamilyAddr f -> μ Int
- pattern SHUT_RD :: SockOps
- pattern SHUT_WR :: SockOps
- pattern SHUT_RDWR :: SockOps
- shutdown :: MonadBase IO μ => Socket f -> SockOps -> μ ()
- close :: MonadBase IO μ => Socket f -> μ ()
Socket types
withSocketFd :: MonadBase IO μ => Socket f -> (Fd -> IO α) -> μ α Source #
Lock the socket and pass the underlying file descriptor to the given action.
class SockAddr (SockFamilyAddr f) => SockFamily f where Source #
Socket family.
Minimal complete definition
Associated Types
type SockFamilyAddr f Source #
Instances
class SockAddr a where Source #
Socket address.
Minimal complete definition
Methods
sockAddrMaxSize :: Proxy a -> Int Source #
Maximum size of a socket address.
sockAddrSize :: a -> Int Source #
Size of a particular socket address.
Read socket address from a memory buffer.
Write socket address to a memory buffer.
Socket type.
pattern SOCK_STREAM :: SockType Source #
See socket(2).
pattern SOCK_DGRAM :: SockType Source #
See socket(2).
pattern SOCK_SEQPACKET :: SockType Source #
See socket(2).
Socket protocol.
defaultSockProto :: SockProto Source #
Default socket protocol (corresponds to 0
).
class Storable (SockOptRaw o) => SockOpt o where Source #
Socket option.
Minimal complete definition
Associated Types
type SockOptValue o Source #
Option value type
type SockOptRaw o Source #
FFI-level option value type
type SockOptReadable o :: Bool Source #
Whether option is readable
type SockOptWritable o :: Bool Source #
Whether option is writable
Methods
sockOptRaw :: Proxy o -> SockOptValue o -> SockOptRaw o Source #
Convert to FFI-level value
sockOptValue :: Proxy o -> SockOptRaw o -> SockOptValue o Source #
Convert from FFI-level value
sockOptLevel :: Proxy o -> CInt Source #
Option protocol level
sockOptCode :: Proxy o -> CInt Source #
Option code
Instances
SockOpt SO_ERROR Source # | |
type SockOptValue SO_ERROR Source # | |
type SockOptRaw SO_ERROR Source # | |
type SockOptReadable SO_ERROR Source # | |
type SockOptWritable SO_ERROR Source # | |
data SO_KEEPALIVE Source #
Instances
SockOpt SO_KEEPALIVE Source # | |
type SockOptValue SO_KEEPALIVE Source # | |
type SockOptRaw SO_KEEPALIVE Source # | |
type SockOptReadable SO_KEEPALIVE Source # | |
type SockOptWritable SO_KEEPALIVE Source # | |
pattern SO_KEEPALIVE :: Proxy SO_KEEPALIVE Source #
data SO_REUSEADDR Source #
Instances
SockOpt SO_REUSEADDR Source # | |
type SockOptValue SO_REUSEADDR Source # | |
type SockOptRaw SO_REUSEADDR Source # | |
type SockOptReadable SO_REUSEADDR Source # | |
type SockOptWritable SO_REUSEADDR Source # | |
pattern SO_REUSEADDR :: Proxy SO_REUSEADDR Source #
Socket operations.
Constructors
NoSockOps | |
RecvSockOps | |
SendSockOps | |
AllSockOps |
Message flags.
pattern MSG_DONTROUTE :: MsgFlags Source #
See recvmsg(2) and sendmsg(2).
Socket operations
Creating and connecting
socket :: (SockFamily f, MonadBase IO μ) => Proxy f -> SockType -> SockProto -> μ (Socket f) Source #
Create a socket. The underlying file descriptor is non-blocking. All blocking operations are done via the GHC event manager. See socket(2).
getSockOpt :: (SockOpt o, SockOptReadable o ~ True, MonadBase IO μ) => Socket f -> Proxy o -> μ (SockOptValue o) Source #
Get socket option value. See getsockopt(2).
setSockOpt :: (SockOpt o, SockOptWritable o ~ True, MonadBase IO μ) => Socket f -> Proxy o -> SockOptValue o -> μ () Source #
Set socket option value. See setsockopt(2).
bind :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> SockFamilyAddr f -> μ () Source #
Bind socket to the specified address. See bind(2).
connect :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> SockFamilyAddr f -> μ () Source #
Connect socket to the specified address. This operation blocks. See connect(2).
tryConnect :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> SockFamilyAddr f -> μ Bool Source #
listen :: MonadBase IO μ => Socket f -> Int -> μ () Source #
Listen for connections on the given socket. See listen(2).
accept :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (Socket f, SockFamilyAddr f) Source #
Accept a connection on the given socket. This operation blocks. See accept(2).
tryAccept :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (Maybe (Socket f, SockFamilyAddr f)) Source #
Try to accept a connection on the given socket without blocking. On success the accepted socket and the peer address are returned. See accept(2).
getLocalAddr :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (SockFamilyAddr f) Source #
Get the local address. See getsockname(2).
getRemoteAddr :: forall f μ. (SockFamily f, MonadBase IO μ) => Socket f -> μ (SockFamilyAddr f) Source #
Get the remote address. See getpeername(2).
Receiving messages
hasOobData :: MonadBase IO μ => Socket f -> μ Bool Source #
Check if socket has out-of-band data. See sockatmark(3).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [(Ptr Word8, Int)] | Memory buffers |
-> MsgFlags | Message flags |
-> μ (Int, MsgFlags) | Received message length and flags |
Receive a message from a connected socket, possibly utilizing multiple memory buffers. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Ptr α | Buffer pointer |
-> Int | Buffer length |
-> MsgFlags | Message flags |
-> μ (Int, MsgFlags) | Received message length and flags |
Receive a message from a connected socket. This operation blocks. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Int | Maximum message length |
-> MsgFlags | Message flags |
-> μ (ByteString, MsgFlags) | Received message contents and flags |
Receive a message from a connected socket. This operation blocks. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Int | Maximum message length |
-> μ ByteString | Received message contents |
Receive a message from a connected socket. This operation blocks. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [(Ptr Word8, Int)] | Memory buffers |
-> MsgFlags | Message flags |
-> μ (SockFamilyAddr f, Int, MsgFlags) | Received message source address, length, and flags |
Receive a message from an unconnected socket, possibly utilizing multiple memory buffers. This operation blocks. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Ptr α | Buffer pointer |
-> Int | Buffer length |
-> MsgFlags | Message flags |
-> μ (SockFamilyAddr f, Int, MsgFlags) | Received message source address, length, and flags |
Receive a message from an unconnected socket. This operation blocks. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Int | Maximum message length |
-> MsgFlags | Message flags |
-> μ (SockFamilyAddr f, ByteString, MsgFlags) | Received message source address, contents, and flags |
Receive a message from an unconnected socket. This operation blocks. See recvmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Int | Maximum message length |
-> μ (SockFamilyAddr f, ByteString) | Received message source address and contents |
Receive a message from an unconnected socket. This operation blocks. See recvmsg(2).
Sending messages
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [(Ptr Word8, Int)] | Memory buffers |
-> MsgFlags | Message flags |
-> μ Int | The number of bytes sent |
Send a message split into several memory buffers on a connected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [ByteString] | Message contents |
-> MsgFlags | Message flags |
-> μ Int | The number of bytes sent |
Send a message split into several ByteString
s on a connected socket.
This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [ByteString] | Message contents |
-> μ Int | The number of bytes sent |
Send a message split into several ByteString
s on a connected socket.
This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Ptr α | Buffer pointer |
-> Int | Buffer length |
-> MsgFlags | Message flags |
-> μ Int | The number of bytes sent |
Send a message on a connected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> ByteString | Message contents |
-> MsgFlags | Message flags |
-> μ Int | The number of bytes sent |
Send a message on a connected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> ByteString | Message contents |
-> μ Int | The number of bytes sent |
Send a message on a connected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [(Ptr Word8, Int)] | Memory buffers |
-> MsgFlags | Message flags |
-> SockFamilyAddr f | Message destination address |
-> μ Int | The number of bytes sent |
Send a message split into several memory buffers on an unconnected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [ByteString] | Message contents |
-> MsgFlags | Message flags |
-> SockFamilyAddr f | Message destination address |
-> μ Int | The number of bytes sent |
Send a message split into several ByteString
s on an unconnected socket.
This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> [ByteString] | Message contents |
-> SockFamilyAddr f | Message destination address |
-> μ Int | The number of bytes sent |
Send a message split into several ByteString
s on an unconnected socket.
This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> Ptr α | Buffer pointer |
-> Int | Buffer length |
-> MsgFlags | Message flags |
-> SockFamilyAddr f | Message destination address |
-> μ Int | The number of bytes sent |
Send a message on an unconnected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> ByteString | Message contents |
-> MsgFlags | Message flags |
-> SockFamilyAddr f | Message destination address |
-> μ Int | The number of bytes sent |
Send a message on an unconnected socket. This operation blocks. See sendmsg(2).
Arguments
:: (SockFamily f, MonadBase IO μ) | |
=> Socket f | The socket |
-> ByteString | Message contents |
-> SockFamilyAddr f | Message destination address |
-> μ Int | The number of bytes sent |
Send a message on an unconnected socket. This operation blocks. See sendmsg(2).
Closing
pattern SHUT_RD :: SockOps Source #
An alias for RecvSockOps
.
pattern SHUT_WR :: SockOps Source #
An alias for SendSockOps
.
pattern SHUT_RDWR :: SockOps Source #
An alias for AllSockOps
.