| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.IO.Streams.TCP
Description
This module provides convenience functions for interfacing raw tcp.
Please use bracket or its friends to enusre exception safety.
This module is intended to be imported qualified, e.g.:
import Data.Connection import qualified System.IO.Streams.TCP as TCP
- type TCPConnection = Connection (Socket, SockAddr)
- connect :: HostName -> PortNumber -> IO TCPConnection
- connectSocket :: HostName -> PortNumber -> IO (Socket, SockAddr)
- socketToConnection :: Int -> (Socket, SockAddr) -> IO TCPConnection
- defaultChunkSize :: Int
- bindAndListen :: Int -> PortNumber -> IO Socket
- bindAndListenWith :: (Socket -> IO ()) -> Int -> PortNumber -> IO Socket
- accept :: Socket -> IO TCPConnection
- acceptWith :: ((Socket, SockAddr) -> IO TCPConnection) -> Socket -> IO TCPConnection
Documentation
type TCPConnection = Connection (Socket, SockAddr) Source #
Type alias for tcp connection.
Normally you shouldn't use Socket in connExtraInfo directly, this field is
intend for used with setSocketOption if you need to.
client
Arguments
| :: HostName | hostname to connect to |
| -> PortNumber | port number to connect to |
| -> IO TCPConnection |
Connect to server using defaultChunkSize.
Arguments
| :: HostName | hostname to connect to |
| -> PortNumber | port number to connect to |
| -> IO (Socket, SockAddr) |
Initiating an raw TCP connection to the given ( combination.HostName, PortNumber)
It use getAddrInfo to resolve host/service name
with AI_ADDRCONFIG, AI_NUMERICSERV hint set, so it should be able to
resolve both numeric IPv4/IPv6 hostname and domain name.
TCP_NODELAY are enabled by default. you can use setSocketOption to adjust.
Arguments
| :: Int | receive buffer size |
| -> (Socket, SockAddr) | socket address pair |
| -> IO TCPConnection |
Make a Connection from a Socket with given buffer size.
defaultChunkSize :: Int Source #
The chunk size used for I/O, less the memory management overhead.
Currently set to 32k.
server
Arguments
| :: Int | connection limit |
| -> PortNumber | port number |
| -> IO Socket |
Bind and listen on port with a limit on connection count.
This function will set SO_REUSEADDR, TCP_NODELAY before binding.
Arguments
| :: (Socket -> IO ()) | set socket options before binding |
| -> Int | connection limit |
| -> PortNumber | port number |
| -> IO Socket |
Bind and listen on port with a limit on connection count.
Note: The following socket options are inherited by a connected TCP socket from the listening socket:
SO_DEBUG SO_DONTROUTE SO_KEEPALIVE SO_LINGER SO_OOBINLINE SO_RCVBUF SO_RCVLOWAT SO_SNDBUF SO_SNDLOWAT TCP_MAXSEG TCP_NODELAY
accept :: Socket -> IO TCPConnection Source #
Accept a connection with defaultChunkSize.
Arguments
| :: ((Socket, SockAddr) -> IO TCPConnection) | set socket options, adjust receive buffer, etc. |
| -> Socket | |
| -> IO TCPConnection |
Accept a connection with user customization.