Utility functions for TCP sockets
Backlog (maximum number of queued connections)
Set ReuseAddr option?
|-> (SomeException -> IO ())|
|-> (Socket -> IO ())|
|-> IO ThreadId|
Start a server at the specified address.
This sets up a server socket for the specified host and port. Exceptions thrown during setup are not caught.
Once the socket is created we spawn a new thread which repeatedly accepts
incoming connections and executes the given request handler. If any
exception occurs the thread terminates and calls the terminationHandler.
This exception may occur because of a call to
accept, because the thread
was explicitly killed, or because of a synchronous exception thrown by the
request handler. Typically, you should avoid the last case by catching any
relevant exceptions in the request handler.
The request handler should spawn threads to handle each individual request or the server will block. Once a thread has been spawned it will be the responsibility of the new thread to close the socket when an exception occurs.
Read an exact number of bytes from a socket
Throws an I/O exception if the socket closes before the specified number of bytes could be read