Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- newtype Socket d t p = Socket (MVar Fd)
- newtype SocketException = SocketException Errno
- newtype MsgFlags = MsgFlags CInt
- msgEOR :: MsgFlags
- msgOOB :: MsgFlags
- msgNOSIGNAL :: MsgFlags
- class GetSockOpt o where
- getSockOpt :: Socket f t p -> IO o
- class SetSockOpt o where
- setSockOpt :: Socket f t p -> o -> IO ()
- data SO_ACCEPTCONN = SO_ACCEPTCONN Bool
Documentation
A generic socket type. Also see socket
for details.
The socket is just an MVar
-wrapped file descriptor.
It is exposed in order to make this library easily extensible, but it is
usually not necessary nor advised to work directly on the file descriptor.
If you do, the following rules must be obeyed:
- Make sure not to deadlock. Use
withMVar
or similar. - The lock must not be held during a blocking call. This would make it impossible to send and receive simultaneously or to close the socket.
- The lock must be held when calling operations that use the file descriptor. Otherwise the socket might get closed or even reused by another thread/capability which might result in reading from or writing totally different connection. This is a security nightmare!
- The socket is non-blocking and all the code relies on that assumption.
You need to use GHC's eventing mechanism primitives to block until
something happens. The former rules forbid to use
threadWaitRead
as it does not seperate between registering the file descriptor (for which the lock must be held) and the actual waiting (for which you must not hold the lock). Also see this thread and read the library code to see how the problem is currently circumvented.
newtype SocketException Source
class GetSockOpt o where Source
getSockOpt :: Socket f t p -> IO o Source
class SetSockOpt o where Source
setSockOpt :: Socket f t p -> o -> IO () Source