network-2.6.2.1: Low-level networking interface

Copyright(c) The University of Glasgow 2001
LicenseBSD-style (see the file libraries/network/LICENSE)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Network.Socket.Internal

Contents

Description

A module containing semi-public Socket internals. Modules which extend the Socket module will need to use this module while ideally most users will be able to make do with the public interface.

Synopsis

Socket addresses

type HostAddress = Word32 Source

Network byte order.

type HostAddress6 = (Word32, Word32, Word32, Word32) Source

Host byte order.

newtype PortNumber Source

Use the Num instance (i.e. use a literal) to create a PortNumber value with the correct network-byte-ordering. You should not use the PortNum constructor. It will be removed in the next release.

Constructors

PortNum Word16

Deprecated: Do not use the PortNum constructor. Use the Num instance. PortNum will be removed in the next release.

data SockAddr Source

The existence of a constructor does not necessarily imply that that socket address type is supported on your system: see isSupportedSockAddr.

peekSockAddr :: Ptr SockAddr -> IO SockAddr Source

Read a SockAddr from the given memory location.

pokeSockAddr :: Ptr a -> SockAddr -> IO () Source

Write the given SockAddr to the given memory location.

sizeOfSockAddr :: SockAddr -> Int Source

Computes the storage requirements (in bytes) of the given SockAddr. This function differs from sizeOf in that the value of the argument is used.

sizeOfSockAddrByFamily :: Family -> Int Source

Computes the storage requirements (in bytes) required for a SockAddr with the given Family.

withSockAddr :: SockAddr -> (Ptr SockAddr -> Int -> IO a) -> IO a Source

Use a SockAddr with a function requiring a pointer to a SockAddr and the length of that SockAddr.

withNewSockAddr :: Family -> (Ptr SockAddr -> Int -> IO a) -> IO a Source

Create a new SockAddr for use with a function requiring a pointer to a SockAddr and the length of that SockAddr.

Protocol families

Socket error functions

throwSocketError Source

Arguments

:: String

textual description of the error location

-> IO a 

Throw an IOError corresponding to the current socket error.

throwSocketErrorCode :: String -> CInt -> IO a Source

Like throwSocketError, but the error code is supplied as an argument.

On Windows, do not use errno. Use a system error code instead.

Guards for socket operations that may fail

throwSocketErrorIfMinus1_ Source

Arguments

:: (Eq a, Num a) 
=> String

textual description of the location

-> IO a

the IO operation to be executed

-> IO () 

Throw an IOError corresponding to the current socket error if the IO action returns a result of -1. Discards the result of the IO action after error handling.

throwSocketErrorIfMinus1Retry Source

Arguments

:: (Eq a, Num a) 
=> String

textual description of the location

-> IO a

the IO operation to be executed

-> IO a 

Throw an IOError corresponding to the current socket error if the IO action returns a result of -1, but retries in case of an interrupted operation.

throwSocketErrorIfMinus1Retry_ Source

Arguments

:: (Eq a, Num a) 
=> String

textual description of the location

-> IO a

the IO operation to be executed

-> IO () 

Throw an IOError corresponding to the current socket error if the IO action returns a result of -1, but retries in case of an interrupted operation. Discards the result of the IO action after error handling.

throwSocketErrorIfMinus1RetryMayBlock Source

Arguments

:: (Eq a, Num a) 
=> String

textual description of the location

-> IO b

action to execute before retrying if an immediate retry would block

-> IO a

the IO operation to be executed

-> IO a 

Throw an IOError corresponding to the current socket error if the IO action returns a result of -1, but retries in case of an interrupted operation. Checks for operations that would block and executes an alternative action before retrying in that case.

Guards that wait and retry if the operation would block

These guards are based on throwSocketErrorIfMinus1RetryMayBlock. They wait for socket readiness if the action fails with EWOULDBLOCK or similar.

throwSocketErrorWaitRead :: (Eq a, Num a) => Socket -> String -> IO a -> IO a Source

Like throwSocketErrorIfMinus1Retry, but if the action fails with EWOULDBLOCK or similar, wait for the socket to be read-ready, and try again.

throwSocketErrorWaitWrite :: (Eq a, Num a) => Socket -> String -> IO a -> IO a Source

Like throwSocketErrorIfMinus1Retry, but if the action fails with EWOULDBLOCK or similar, wait for the socket to be write-ready, and try again.

Initialization

withSocketsDo :: IO a -> IO a Source

With older versions of the network library on Windows operating systems, the networking subsystem must be initialised using withSocketsDo before any networking operations can be used. eg.

main = withSocketsDo $ do {...}

It is fine to nest calls to withSocketsDo, and to perform networking operations after withSocketsDo has returned.

In newer versions of the network library it is only necessary to call withSocketsDo if you are calling the MkSocket constructor directly. However, for compatibility with older versions on Windows, it is good practice to always call withSocketsDo (it's very cheap).

Low-level helpers

zeroMemory :: Ptr a -> CSize -> IO () Source

Zero a structure.