network-bytestring-0.1.3.3: Fast, memory-efficient, low-level networking

PortabilityPOSIX, GHC
Stabilityexperimental
Maintainerbos@serpentine.com

Network.Socket.ByteString.Lazy

Contents

Description

This module provides access to the BSD socket interface. This module is generally more efficient than the String based network functions in Network.Socket. For detailed documentation, consult your favorite POSIX socket reference. All functions communicate failures by converting the error number to System.IO.IOError.

This module is made to be imported with Network.Socket like so:

 import Network.Socket hiding (send, sendTo, recv, recvFrom)
 import Network.Socket.ByteString.Lazy
 import Prelude hiding (getContents)

Synopsis

Send data to a socket

send

Arguments

:: Socket

Connected socket

-> ByteString

Data to send

-> IO Int

Number of bytes sent

Send data to the socket. The socket must be connected to a remote socket. Returns the number of bytes sent. Applications are responsible for ensuring that all data has been sent.

sendAll

Arguments

:: Socket

Connected socket

-> ByteString

Data to send

-> IO () 

Send data to the socket. The socket must be connected to a remote socket. Unlike send, this function continues to send data until either all data has been sent or an error occurs. On error, an exception is raised, and there is no way to determine how much data, if any, was successfully sent.

Receive data from a socket

getContents :: IO String

The getContents operation returns all user input as a single string, which is read lazily as it is needed (same as hGetContents stdin).

recv

Arguments

:: Socket

Connected socket

-> Int

Maximum number of bytes to receive

-> IO ByteString

Data received

Receive data from the socket. The socket must be in a connected state. This function may return fewer bytes than specified. If the message is longer than the specified length, it may be discarded depending on the type of socket. This function may block until a message arrives.

Considering hardware and network realities, the maximum number of bytes to receive should be a small power of 2, e.g., 4096.

For TCP sockets, a zero length return value means the peer has closed its half side of the connection.