IdrisDoc: Network.Socket.Raw

Network.Socket.Raw

Low-Level C Sockets bindings for Idris. Used by higher-level, cleverer things.
Type-unsafe parts. Use Network.Socket for a safe variant.

Original (C) SimonJF, MIT Licensed, 2014
Modified (C) The Idris Community, 2015, 2016

sockaddr_free : SockaddrPtr -> IO ()
sock_free : BufPtr -> IO ()

Frees a given pointer

sock_alloc : ByteLength -> IO BufPtr

Allocates an amount of memory given by the ByteLength parameter.

Used to allocate a mutable pointer to be given to the Recv functions.

sendToBuf : (sock : Socket) -> (addr : SocketAddress) -> (port : Port) -> (ptr : BufPtr) -> (len : ByteLength) -> IO (Either SocketError ResultCode)

Send a message stored in some buffer.

Returns on failure a SocketError
Returns on success the ResultCode

sock

The socket on which to send the message.

addr

Address of the recipient.

port

The port on which to send the message.

ptr

A Pointer to the buffer containing the message.

len

The size of the message.

sendBuf : (sock : Socket) -> (ptr : BufPtr) -> (len : ByteLength) -> IO (Either SocketError ResultCode)

Sends the data in a given memory location

Returns on failure a SocketError
Returns on success the ResultCode

sock

The socket on which to send the message.

ptr

The location containing the data to send.

len

How much of the data to send.

recvFromBuf : (sock : Socket) -> (ptr : BufPtr) -> (len : ByteLength) -> IO (Either SocketError (UDPAddrInfo, ResultCode))

Receive a message placed on a 'known' buffer.

Returns on failure a SocketError.
Returns on success a pair of

  • UDPAddrInfo :: The address of the sender.
  • Int :: Result value from underlying function.
sock

The channel on which to receive.

ptr

Pointer to the buffer to place the message.

len

Size of the expected message.

recvBuf : (sock : Socket) -> (ptr : BufPtr) -> (len : ByteLength) -> IO (Either SocketError ResultCode)

Receive data from a given memory location.

Returns on failure a SocketError
Returns on success the ResultCode

sock

The socket on which to receive the message.

ptr

The location containing the data to receive.

len

How much of the data to receive.

getSockAddr : SockaddrPtr -> IO SocketAddress

Retrieves a socket address from a sockaddr pointer

freeRecvfromStruct : RecvfromStructPtr -> IO ()

Utility to extract data.

freeRecvStruct : RecvStructPtr -> IO ()
foreignGetRecvfromPort : RecvfromStructPtr -> IO Port

Utility function to return sender's IPV4 port.

foreignGetRecvfromPayload : RecvfromStructPtr -> IO String

Utility function to get the payload of the sent message as a String.

foreignGetRecvfromAddr : RecvfromStructPtr -> IO SocketAddress

Utility function to return senders socket address.

data SockaddrPtr : Type
SAPtr : Ptr -> SockaddrPtr
data RecvfromStructPtr : Type
RFPtr : Ptr -> RecvfromStructPtr
data RecvStructPtr : Type
RSPtr : Ptr -> RecvStructPtr
data BufPtr : Type
BPtr : Ptr -> BufPtr