hans-3.0.2: Network Stack

Safe HaskellNone
LanguageHaskell2010

Hans.Socket

Contents

Synopsis

Abstract Sockets

class Socket sock where Source #

Minimal complete definition

sClose

Methods

sClose :: Network addr => sock addr -> IO () Source #

Close an open socket.

Instances

Socket TcpListenSocket Source # 

Methods

sClose :: Network addr => TcpListenSocket addr -> IO () Source #

Socket TcpSocket Source # 

Methods

sClose :: Network addr => TcpSocket addr -> IO () Source #

Socket UdpSocket Source # 

Methods

sClose :: Network addr => UdpSocket addr -> IO () Source #

class (DataSocket (Client sock), Socket sock) => ListenSocket sock where Source #

Minimal complete definition

sListen, sAccept

Associated Types

type Client sock :: * -> * Source #

Methods

sListen :: (HasNetworkStack ns, Network addr) => ns -> SocketConfig -> addr -> SockPort -> Int -> IO (sock addr) Source #

Create a listening socket, with a backlog of n.

sAccept :: Network addr => sock addr -> IO (Client sock addr) Source #

Instances

ListenSocket TcpListenSocket Source # 

Associated Types

type Client (TcpListenSocket :: * -> *) :: * -> * Source #

Methods

sListen :: (HasNetworkStack ns, Network addr) => ns -> SocketConfig -> addr -> SockPort -> Int -> IO (TcpListenSocket addr) Source #

sAccept :: Network addr => TcpListenSocket addr -> IO (Client TcpListenSocket addr) Source #

class Socket sock => DataSocket sock where Source #

Minimal complete definition

sConnect, sCanWrite, sWrite, sCanRead, sRead, sTryRead

Methods

sConnect :: (HasNetworkStack ns, Network addr) => ns -> SocketConfig -> Maybe Device -> addr -> Maybe SockPort -> addr -> SockPort -> IO (sock addr) Source #

Connect this socket to one on a remote machine.

sCanWrite :: Network addr => sock addr -> IO Bool Source #

Returns True iff there is currently space in the buffer to accept a write. Note, this is probably a bad thing to count on in a concurrent system ...

sWrite :: Network addr => sock addr -> ByteString -> IO Int Source #

Send a chunk of data on a socket.

sCanRead :: Network addr => sock addr -> IO Bool Source #

Returns True iff there is data in the buffer that can be read. Note, this is probably a bad thing to count on in a concurrent system ...

sRead :: Network addr => sock addr -> Int -> IO ByteString Source #

Read a chunk of data from a socket. Reading an empty result indicates that the socket has closed.

sTryRead :: Network addr => sock addr -> Int -> IO (Maybe ByteString) Source #

Non-blocking read from a socket. Reading an empty result means that the socket has closed, while reading a Nothing result indicates that there was no data available.

Instances

DataSocket TcpSocket Source # 

Methods

sConnect :: (HasNetworkStack ns, Network addr) => ns -> SocketConfig -> Maybe Device -> addr -> Maybe SockPort -> addr -> SockPort -> IO (TcpSocket addr) Source #

sCanWrite :: Network addr => TcpSocket addr -> IO Bool Source #

sWrite :: Network addr => TcpSocket addr -> ByteString -> IO Int Source #

sCanRead :: Network addr => TcpSocket addr -> IO Bool Source #

sRead :: Network addr => TcpSocket addr -> Int -> IO ByteString Source #

sTryRead :: Network addr => TcpSocket addr -> Int -> IO (Maybe ByteString) Source #

DataSocket UdpSocket Source # 

Methods

sConnect :: (HasNetworkStack ns, Network addr) => ns -> SocketConfig -> Maybe Device -> addr -> Maybe SockPort -> addr -> SockPort -> IO (UdpSocket addr) Source #

sCanWrite :: Network addr => UdpSocket addr -> IO Bool Source #

sWrite :: Network addr => UdpSocket addr -> ByteString -> IO Int Source #

sCanRead :: Network addr => UdpSocket addr -> IO Bool Source #

sRead :: Network addr => UdpSocket addr -> Int -> IO ByteString Source #

sTryRead :: Network addr => UdpSocket addr -> Int -> IO (Maybe ByteString) Source #

data SocketConfig Source #

Constructors

SocketConfig 

Fields

UDP Sockets

data UdpSocket addr Source #

Instances

sendto :: Network addr => UdpSocket addr -> addr -> SockPort -> ByteString -> IO () Source #

Send to a specific end host.

recvfrom :: Network addr => UdpSocket addr -> IO (Device, addr, SockPort, ByteString) Source #

Receive, with information about who sent this datagram.

recvfrom' :: Network addr => UdpSocket addr -> IO (Device, addr, SockPort, addr, ByteString) Source #

TCP Sockets

data TcpSocket addr Source #

Instances

tcpRemoteAddr :: NetworkAddr addr => Getting r (TcpSocket addr) addr Source #

The remote address of this socket.

tcpRemotePort :: Getting r (TcpSocket addr) SockPort Source #

The remote port of this socket.

tcpLocalAddr :: NetworkAddr addr => Getting r (TcpSocket addr) addr Source #

The source address of this socket.

tcpLocalPort :: Getting r (TcpSocket addr) SockPort Source #

The local port for this socket.

Exceptions