socket
A portable and extensible sockets library.
https://github.com/lpeterse/haskell-socket
| Version on this page: | 0.5.3.0@rev:1 |
| LTS Haskell 24.18: | 0.8.3.0@rev:2 |
| Stackage Nightly 2025-11-01: | 0.8.3.0@rev:2 |
| Latest on Hackage: | 0.8.3.0@rev:2 |
socket-0.5.3.0@sha256:2dd7a1d3117389e1efa5fa6149925c6bd912116a68c2b2ee1370911b106440fc,5987Module documentation for 0.5.3.0
socket
Motivation
This library aims to expose a minimal and platform-independant interface for POSIX compliant networking code.
Implementation Philosophy
-
Every operation and every flag exposed should be supported with same semantics on every platform. If this cannot be guaranteed it should be supplied by another (extension) package. Examples for things that have been ripped out of this library are:
- Support for Unix sockets which don’t have an equivalent on Windows.
- Support for SCTP.
- Support for vectored IO (at least unless it can be guaranteed to be supported on all platforms).
-
Absolutely no conditional exports.
-
No
#ifdefmadness in the Haskell sources. The Haskell binding code uses the FFI to reference the platform’s native networking functions. If they are not Posix compliant (i.e. on Windows) an level of indirection is introduced to create an Posix compliant equivalent in C using whatever the plaform specific building blocks are.
Platform Support
Linux
Working.
BSD
Unknown. Should work. Please report if not.
MacOS
Working.
Windows
Fully supported on Windows7 (maybe Vista) or higher :-)
GHCs runtime system on Windows does not offer an event notification mechanism for sockets. The original network library suffers from this, too. For example, connection attempts are uninterruptible etc. The approach taken to circumvent this in this library is to poll the non-blocking sockets with increasing delay. This guarantees interruptability and fairness between different threads. It allows for decent throughput while also keeping CPU consumption on a moderate level if a socket has not seen events for a longer period of time (maximum of 1 second delay after 20 polling iterations). The only drawback is potentially reduced response time of your application. The good part: Heavy load (e.g. connection requests or incoming traffic) will reduce this problem. Eventually your accepting thread won’t wait at all if there are several connection requests queued.
This workaround may be removed if someone is willing to sacrifice to improve the IO manager on Windows.
Dependencies
- base
- bytestring
Tests
Run the default test suites:
cabal test
Changes
0.5.3.0 Lars Petersen [email protected] 2015-08-09
- Added a test for
eOperationNotSupported(try to listen on a UDP socket). - Niklas Hambüchen added
eOperationNotSupported.
0.5.2.0 Lars Petersen [email protected] 2015-07-08
- Don’t set
msgNoSignalautomatically withsendandsendTo. This implicit behaviour is a bad design decision. The implications of this change are rather limited. The behaviour/correctness of an application is only affected if it hooked SIGPIPE. GHC’s RTS by default ignores SIGPIPE since #1619. You’re still advised to adapt your applications to usemsgNoSignalexplicitly when writing on stream oriented sockets. Otherwise the RTS gets unnecessarily interrupted. This is harmless, but annoying and not desired when developing high-performance applications. - Define
msgNoSignalas 0 if not available and documented this behaviour. - Added new exception value
ePipe.
0.5.1.0 Lars Petersen [email protected] 2015-06-22
- Exposed
unsafeGetSocketOptionandunsafeSetSocketOption. - Exposed
socketWaitReadandsocketWaitWritethroughSystem.Socket.Unsafe.
0.5.0.0 Lars Petersen [email protected] 2015-06-19
- Introduced newtypes
Port,FlowInfoandScopeIdin Inet6 family. - Renamed nearly everything in response to very constructive criticism by Bryan O’Sullivan. This is a breaking change (sorry about that). I felt this was the last chance to get this straight before the library gets widely adopted. Additional kudos to @ignorantone and @whatsthepoint.
- Issue #7: Typo in documentation of inaddrNONE and inaddrBROADCAST. Kudos to Michael Fox.
0.4.0.1 Lars Petersen [email protected] 2015-06-17
- tar-ball did not contain relevant source files.
0.4.0.0 Lars Petersen [email protected] 2015-06-16
- Changed semantics of
connectoperation. It now blocks until a connection has either has been established or failed. - Added
SO_ERRORsocket option. - Added
eALREADYexception constant. - Added
eISCONNexception constant. - Added
eNOTCONNexception constant. - Added convenience operation
withConnectedSocket. - Added
eNETUNREACHexception constant. - Added new operation
recvAlland changedsendAllto lazyByteString. - Added new socket option IPV6_V6ONLY.
- Removed untested socket option SO_ACCEPTCONN.
- Correctly defining AI_ flags on Windows (MinGW doesn’t although they are all well support on Vista or higher).
- Got all tests passing on Windows 7.
0.3.0.1 Lars Petersen [email protected] 2015-06-07
- Fixed documentation of eaiNONAME.
- Fixed typo in .cabal file in reference to cbits file.
0.3.0.0 Lars Petersen [email protected] 2015-06-07
AddrInfoFlagsandNameInfoFlagsare now instances ofBits.- Dropped all sendmsg/recvmsg related operations (harden the core first!)
- Dropped support for UNIX socket (will be separate package
socket-unix) - Renamed type function
AddresstoSockAddr. - Added GetAddrInfo and GetNameInfo classes.
- Dropped support for SCTP (will be separate package
socket-sctp) - Added support for RAW sockets.
- Started to support Windows (still unfinished).
- New operation
recvRecord. - ReceiveMsg now returns a strict
ByteString. - New operations
sendV,sendToV. - Restricted getAddrInfo and getNameInfo and added
getAddrInfo6andgetNameInfo6 - Added address family types INET, INET6 and UNIX (API breaking change)
- Hide
SockAddrIn6address constructor - Hide
SockAddrInaddress constructor - Added
recvMsgoperation - Fixed unsafeSend, unsafeSendTo and unsafeSendMsg (they were waiting for a read event instead of waiting for writing)
- Use
aiStrErrorvalues in Show instance - Added
aiStrErrorfunction - Added constants for AddrInfoException
- Changed definitin of AddrInfoException
- Added
sendAllMsgoperation - Added
sendMsgoperation (+ some types and internals)
0.2.0.0 Lars Petersen [email protected] 2015-05-29
- Added a sendAll operation
- Exposed the Socket constructor
- Added
getNameInfooperation - Added msgWAITALL and fixed serious bug regarding all other MsgFlags
- Nicer Show instances for SockAddrIn and SockAddrIn6
- Hiding internal modules
- Added
getAddrInfooperation
0.1.0.1 Lars Petersen [email protected] 2015-05-28
- Added CHANGELOG.md
- Removed
threadWaitReadMVarandthreadWaitWriteMVar - Import
Data.MonoidinSystem.Socket.Unsafeto support older Preludes
0.1.0.0 Lars Petersen [email protected] 2015-05-28
- Initial release