netw-0.1.1.0: Binding to C socket API operating on bytearrays.
Safe HaskellSafe-Inferred
LanguageGHC2021

Netw.Socket

Description

This module contains all the functions required to create and use sockets.

Synopsis

Documentation

newtype Socket Source #

A file descriptor that is a socket. All socket used by this library is in nonblocking mode (O_NONBLOCK)

Constructors

MkSocket 

Fields

socket :: ProtocolFamily -> SocketType -> Protocol -> IO Socket Source #

Create a new socket (see `man 3 socket`)

closeSocket :: Socket -> IO () Source #

Close a socket (see `man 3 close`)

bind :: SockAddr a => Socket -> a -> IO () Source #

Bind a socket to an address (see `man 3 bind`)

listen :: Socket -> Int -> IO () Source #

Mark a socket as accepting connection (see `man 3 listen`)

getsockname :: Socket -> IO Addr Source #

Retrieve the name of the socket (see `man 3 getsockname`)

accept :: Socket -> IO (Socket, Addr) Source #

Extract the first connection on the pending connection queue (see `man 3 accept`). This function blocks the calling thread until a connection is made.

accept_ :: Socket -> IO Socket Source #

A version of accept which does not return the peer address

connect :: SockAddr a => Socket -> a -> IO () Source #

Try to connect to an address (see `man 3 connect`)

sendall :: Socket -> ByteArray -> MsgFlags -> IO () Source #

Send the whole content of a bytearray through a socket. Block until the entire bytearray has been sent.

send :: Socket -> ByteArray -> Int -> Int -> MsgFlags -> IO Int Source #

`send socket buffer offset size flags` Send a range of bytes in buffer located at offset and is size bytes long. Return the number of bytes accually sent which may be less than the number of bytes specified. Block the current thread until some bytes are sent. (see `man 3 send`)

send' :: Socket -> Ptr Word8 -> Int -> MsgFlags -> IO Int Source #

A version of send that accept a pointer instead of a bytearray.

sendallto :: SockAddr a => Socket -> ByteArray -> MsgFlags -> a -> IO () Source #

Send the whole content of a bytearray

sendto :: SockAddr a => Socket -> ByteArray -> Int -> Int -> MsgFlags -> a -> IO Int Source #

A version of send that accept the destination address (see `man 3 sendto`) Return the number of bytes accually sent which may be less than the number of bytes specified. Block the thread until some bytes are sent.

sendto' :: SockAddr a => Socket -> Ptr Word8 -> Int -> MsgFlags -> a -> IO Int Source #

A version of sendto that accept a pointer instead of a bytearray

sendmsg :: SockAddr a => Socket -> a -> [(ByteArray, Int, Int)] -> [AncillaryData] -> MsgFlags -> IO Int Source #

`sendmsg socket address iovecs cmsgs flags` The iovecs argument is a list of 3-tuples of the data buffer, the offset in bytes, and the number of bytes to send. Use SockAddrNull if no address is to be specified. This function blocks the calling thread and return the number of bytes sent, which may be less than the intended message size.

(See `man 3 sendmsg`)

sendmsg' :: SockAddr a => Socket -> a -> [(Ptr Word8, Int)] -> [AncillaryData] -> MsgFlags -> IO Int Source #

A version of sendmsg that uses pointers instead of bytearrays

recvsome :: Socket -> Int -> MsgFlags -> IO ByteArray Source #

`recvsome socket n flags` Receive a maximum of n bytes from socket. Return the message as a bytearray. If the bytearray is empty (size == 0) then there is no more data to be read and the socket should be closed.

recv :: Socket -> MutableByteArray RealWorld -> Int -> Int -> MsgFlags -> IO Int Source #

`recv socket buffer offset size flags` Receive a maximum of size bytes from socket, storing those bytes in buffer at offset Return the number of bytes received. (See `man 3 recv`) Block the calling thread until some bytes are received.

recv' :: Socket -> Ptr Word8 -> Int -> MsgFlags -> IO Int Source #

A version of recv that takes a pointer instead of a mutablebytearray

recvfrom :: Socket -> MutableByteArray RealWorld -> Int -> Int -> MsgFlags -> IO (Int, Addr) Source #

`recvfrom socket buffer offset size flags` Receive a message less than size bytes long and the source address. The bytes received are stored in buffer at offset Return the number of bytes received.

(See `man 3 recvfrom`)

recvfrom' :: Socket -> Ptr Word8 -> Int -> MsgFlags -> IO (Int, Addr) Source #

A version of recvfrom that takes a pointer

recvsomefrom :: Socket -> Int -> MsgFlags -> IO (ByteArray, Addr) Source #

A version of recvfrom that automatically allocates a bytearray

recvmsg :: Socket -> [(MutableByteArray RealWorld, Int, Int)] -> Int -> MsgFlags -> IO (Int, MsgFlags, [AncillaryData], Addr) Source #

Receive messages alongside ancillary data. The elements of iovecs are tuples containing the storage bytearray, offset into bytearray, and the number of bytes to write to said bytearray.

(See `man 3 recvmsg`)

recvmsg_ :: Socket -> [(MutableByteArray RealWorld, Int, Int)] -> Int -> MsgFlags -> IO (Int, MsgFlags, [AncillaryData]) Source #

A version of recvmsg that does not return the address

shutdown :: Socket -> ShutHow -> IO () Source #

Shutdown all or part of of a duplex connection

newtype ProtocolFamily Source #

Constructors

ProtocolFamily CInt 

Instances

Instances details
Eq ProtocolFamily Source # 
Instance details

Defined in Netw.Internal.Enum

newtype Protocol Source #

Constructors

Protocol CInt 

Instances

Instances details
Eq Protocol Source # 
Instance details

Defined in Netw.Internal.Enum

newtype MsgFlags Source #

Constructors

MsgFlags CInt 

newtype ShutHow Source #

Constructors

ShutHow CInt 

pattern SHUT_RD :: ShutHow Source #

pattern SHUT_WR :: ShutHow Source #