network
Low-level networking interface
https://github.com/haskell/network
| LTS Haskell 24.65: | 3.2.9.0 |
| Stackage Nightly 2026-11-03: | 3.2.11.0 |
| Latest on Hackage: | 3.2.11.0 |
network-3.2.11.0@sha256:c57718249f1ec74de6be367a9527f938b12df412d7ac990095de5a6376faf0c7,5501Module documentation for 3.2.11.0
network
To build this package directly from git, you must run autoreconf -i.
And then use cabal configure; cabal build or stack build.
Support Policy
GHC
The network package support 3 major versions of GHC only.
This means that the current stable version and two previous stable versions are supported.
Windows
We use MSYS to build this package on Windows.
To use the network package on Cygwin, use stack.
Coding
.hs files
If you need C macros created by “configure” or CALLCONV/SAFE_ON_WIN, put
#include "HsNetDef.h"
“HsNet.h” does now work well since Mac’s cpp sucks.
.hsc files
If you need #peek, #poke and others, create a .hsc file with
#include "HsNet.h"
HsNet.h includes HsNefDef.h and necessary C structures.
Unfortunately, hsc2hs does not convert C macros.
So, if you use CALLCONV/SAFE_ON_WIN, the following is also necessary:
##include "HsNetDef.h"
Changes
CHANGELOG for network
Version 3.2.11.0
- Add unsafeClose #629
Version 3.2.10.0
- Multicast support #614
- Support for getHostName #621
- Adding acceptWith, recvWith, recvFromWith, recvBufWith and recvBufFromWith, which take an STM action beside the operation and let the caller give up on it without closing the socket or interrupting the thread, and withReadable, which they are built from.
- Adding isClosedSocketError and isTransientAcceptError, which name what an accept loop has to tell apart: a socket closed under it, one queued connection which failed, and the rest.
- On Windows, the Winsock error code is kept in ioe_errno rather than dropped. Winsock reports every error as OtherError, so the code was the only thing telling them apart and it was only in the description. isClosedSocketError and isTransientAcceptError read it, so an accept loop there now stops when its socket is closed and retries a connection the peer gave up on.
- gracefulClose waits for the peer’s FIN through recvBufWith, which is one code path on every platform, and drains what arrived before it up to 128 KiB rather than reading once: data left unread makes close send RST. It therefore keeps to its timeout on Windows, where System.Timeout cannot cut a receive short and a peer which stayed open and silent used to hold the caller for as long as it did.
- gracefulClose reads its timeout as the milliseconds it is documented to be without an event manager. System.Timeout takes microseconds, so it was a thousandth of what was asked for.
- On Windows, a datagram socket hears an ICMP unreachable which a send of its own caused only once it is connected, as on POSIX. Winsock reports it to every datagram socket, so one reply bouncing off a client which had gone ended a server’s receive loop; socket turns that off and connect turns it back on.
- The readiness based waitReadSocketSTM and waitWriteSocketSTM cannot work on Windows, where completion ports report that an operation has finished rather than that one could be started, and now say so instead of blocking forever.
Version 3.2.9.0
- Exporting recvBufNoWait.
Version 3.2.8.0
- sockopt: add IP_DONTFRAG/IP_MTU_DISCOVER option. #603
- Add new SocketOption KeepInit. #600
- Remove withSocketsDo from examples. #596
Version 3.2.7.0
- Using nested
bracketforgracefulClose. #591 - Fix memory leak in getaddrinfo and make it async exception safe. #591
- Make call to c_free async exception safe. #592
Version 3.2.6.0
- fixing the Show instance of IPv4-mapped IPv6 address on little endian machines
Version 3.2.5.0
gracefulClosebased on STM racing andtimeout. #587
Version 3.2.4.0
- New API: setSockOptValue. #588
Version 3.2.3.0
- Making getAddrInfo polymorphic #587
Version 3.2.2.0
- New API: waitReadSocketSTM, waitAndCancelReadSocketSTM, waitWriteSocketSTM, waitAndCancelWriteSocketSTM #586
- Checking the length of ASCII string allowing trailing 0. #585
Version 3.2.1.0
- Trying to release with the latest autoreconf. Packing “network” in the local directory instead of CI.
- Remove includes from .cabal-file #583
- making gracefulClose more graceful #580
- Update config.guess, config.sub to their latest versions #579
Version 3.2.0.0
- Breaking change: Using Strict and StrictData.
- Breaking change: Allow a control message to contain multiple file descriptors #567
- Breaking change: CmsgIdFd -> CmsgIdFds #575
- SocketTypes: use UnsupportedSocketType instead of -1. #560
- Expose NullSockAddr, add send-with-fds functions. #562
- Allow bytestring-0.12 and replace deprecated memcpy by copyBytes. #564
- Close file descriptor in accept when exception happens #569
- Bump CI to GHC 9.8 and latest versions of actions #573
Version 3.1.5.0
- #541
- Export
Network.Socket.Internal.NullSockAddr - Add
Network.Socket.ByteString.sendManyWithFds - Add
Network.Socket.ByteString.Lazy.sendWithFds
- Export
Version 3.1.4.0
- Install and use afunix_compat.h header. #556
- Supporting SO_SNDTIMEO and SO_RCVTIMEO. #555
- Emulating socketPair on Windows. #554
Version 3.1.3.0
- Supporting AF_UNIX on Windows #553
Version 3.1.2.9
- Resolving the runtime linker problem on Windows. #552
Version 3.1.2.8
- Ignoring error from shutdown in gracefulClose
- Fix bitsize of some msghdr and cmsghdr fields on Linux #535
- Add SO_ACCEPTCONN SocketOption #524
Version 3.1.2.7
- No change from 3.1.2.6 but to take a right procedure to upload “network” to Hackage for Windows.
Version 3.1.2.6
Version 3.1.2.5
- Regenerate
configurescript with autoconf-2.69 to temporarily fix broken cabal-3.4.0.0 on Windows. Note that the old one was generated with autoconf-2.71. #513
Version 3.1.2.3
- Supporting M1 Mac #510
- Workaround for autoconf on Windows #508
- Fixing building failure on SmartOS #507
- HsNet.h: remove unused fn hsnet_inet_ntoa definition #504
- Use a working define for OpenBSD detection #503
Version 3.1.2.2
Version 3.1.2.1
- Increasing base lower bound to 4.9. #473
- Suppressing errors from removeFile in UNIX bind. #478
- Restoring UNIX stub functions on Windows. #489
Version 3.1.2.0
- Added
-f develfor test cases that are known to fail. #471 - Improved precedence-compliant Read/Show instances. Verified via QuickCheck. #465 #466
- Removed the racing graceful close implementation to avoid issues with
CLOSE_WAIT. #460 - Gracefully handle binding of UNIX domain sockets. #460
- Replace Socket type and family with extensible
CIntpattern and synonyms. #459 - Fixed race conditions in tests. #458
- Removed many legacy uses of
undefined. #456 - Defined extensible
CustomSockOptviaViewPatterns. #455 - Defined
openSocketin terms ofAddrInfo. 5b0987197fe2ed7beddd7b2096522d624e71151e - Improved FreeBSD portability for Control Messages and tests #452
- Support
sendMsgandrecvMsg#433 #445 #451- Added
sendMsgandrecvMsgAPIs - Redefined
SocketOptionas pattern synonym
- Added
- Implement total Show functions for SockAddr #441
- Improve portability changing
u_int32_ttouint32_t. #442 - Removed obsolete CPP statements. d1f4ee60ce6a4a85abb79532f64d4a4e71e2b1ce
- Loads of improved test coverage. cbd67cc50a37770432eb978ac8b8eb6da3664817 fcc2d86d53a6bec793f6a979a9e8fdf7fe3f4c22 6db96969b3e8974abbfd50a7f073baa57376fd5e
Version 3.1.1.1
- Fix for GHCJS. #431
Version 3.1.1.0
- A new API:
gracefulClose. #417 touchSocket,unsafeFdSocket: Allow direct access to a socket’s file descriptor while providing tools to prevent it from being garbage collected. This also deprecatedfdSocketin favor ofunsafeFdSocketandwithFdSocket. #423socketToFd: Duplicates a socket as a file desriptor and closes the source socket. #424
Version 3.1.0.1
Version 3.1.0.0
- Making GC of socket safer. #399
- Deprecating fdSocket. Use withFdSocket instead to ensure that sockets are GCed in proper time. #399
Version 3.0.1.1
- Fix blocking
if_nametoindexerrors on Windows #391
Version 3.0.1.0
- Added
getSocketType :: Socket -> IO SocketType. #372 - Correcting manual and brushing up test cases #375
- Fixed longstanded bug in
getContentson mac #375 - Fixing regression: set correct sockaddr length for abstract addresses for Linux. #374
Version 3.0.0.1
- Fixed a bug in
connectwhere exceptions were not thrown #368
Version 3.0.0.0
- Breaking change: the Network and Network.BSD are removed. Network.BSD is provided a new package: network-bsd.
- Breaking change: the signatures are changed:
old fdSocket :: Socket -> CInt
new fdSocket :: Socket -> IO CInt
old mkSocket :: CInt -> Family -> SocketType -> ProtocolNumber -> SocketStatus -> IO Socket
new mkSocket :: CInt -> IO Socket
- Breaking change: the deprecated APIs are removed: send, sendTo, recv, recvFrom, recvLen, htonl, ntohl, inet_addr, int_ntoa, bindSocket, sClose, SocketStatus, isConnected, isBound, isListening, isReadable, isWritable, sIsConnected, sIsBound, sIsListening, sIsReadable, sIsWritable, aNY_PORT, iNADDR_ANY, iN6ADDR_ANY, sOMAXCONN, sOL_SOCKET, sCM_RIGHTS, packSocketType, getPeerCred.
- Breaking change: SockAddrCan is removed from SockAddr.
- Socket addresses are extendable with Network.Socket.Address.
- “socket” is now asynchronous-exception-safe. #336
- “recvFrom” returns (0, addr) instead of throwing an error on EOF. #360
- All APIs are available on any platforms.
- Build system is simplified.
- Bug fixes.
Version 2.8.0.1
- Eensuring that accept returns a correct sockaddr for unix domain. #400
- Avoid out of bounds writes in pokeSockAddr. #400
Version 2.8.0.0
- Breaking change: PortNumber originally contained Word16 in network byte order and used “deriving Ord”. This results in strange behavior on the Ord instance. Now PortNumber holds Word16 in host byte order. #347
- Breaking change: stopping the export of the PortNum constructor in PortNumber.
- Use bytestring == 0.10.* only.
- Use base >= 4.7 && < 5.
Version 2.7.0.2
- Removing withMVar to avoid the deadlock between “accept” and “close” #330
- “close” does not throw exceptions. A new API: “close’” throws exceptions when necessary. #337
- Fixing the hang of lazy sendAll. #340
- Installing NetDef.h (#334) #334
Version 2.7.0.1
- A new API: socketPortSafe. #319
- Fixing a drain bug of sendAll. #320
- Porting the new CALLCONV convention from master. #313
- Withdrawing the deprecations of packFamily and unpackFamily. #324
Version 2.7.0.0
- Obsoleting the Network module.
- Obsoleting the Network.BSD module.
- Obsoleting APIs: MkSocket, htonl, ntohl, getPeerCred, getPeerEid, send, sendTo, recv, recvFrom, recvLen, inet_addr, inet_ntoa, isConnected, isBound, isListening, isReadable, isWritable, aNY_PORT, iNADDR_ANY, iN6ADDR_ANY, sOMAXCONN, sOL_SOCKET, sCM_RIGHTS, packFamily, unpackFamily, packSocketType
- Breaking change: do not closeFd within sendFd. #271
- Exporting ifNameToIndex and ifIndexToName from Network.Socket.
- New APIs: setCloseOnExecIfNeeded, getCloseOnExec and getNonBlock
- New APIs: isUnixDomainSocketAvailable and getPeerCredential
- socketPair, sendFd and recvFd are exported even on Windows.
Version 2.6.3.5
- Reverting “Do not closeFd within sendFd” #271
Version 2.6.3.4
- Don’t touch IPv6Only when running on OpenBSD #227
- Do not closeFd within sendFd #271
- Updating examples and docs.
Version 2.6.3.3
- Adds a function to show the defaultHints without reading their undefined fields #291
- Improve exception error messages for getAddrInfo and getNameInfo #289
Version 2.6.3.2
-
Zero memory of
sockaddr_unif abstract socket #220 -
Improving error messages #232
-
Allow non-blocking file descriptors via
setNonBlockIfNeeded#242 -
Update config.{guess,sub} to latest version #244
-
Rename
my_inet_ntoato avoid symbol conflicts #228
Version 2.6.3.1
- Reverse breaking exception change in
Network.Socket.ByteString.recv#215
Version 2.6.3.0
-
New maintainers: Evan Borden (@eborden) and Kazu Yamamoto (@kazu-yamamoto). The maintainer for a long period, Johan Tibell (@tibbe) stepped down. Thank you, Johan, for your hard work for a long time.
-
New APIs: ntohl, htonl,hostAddressToTuple{,6} and tupleToHostAddress{,6}. #210
-
Added a Read instance for PortNumber. #145
-
We only set the IPV6_V6ONLY flag to 0 for stream and datagram socket types, as opposed to all of them. This makes it possible to use ICMPv6. #180 #181
-
Work around GHC bug #12020. Socket errors no longer cause segfaults or hangs on Windows. #192
-
Various documentation improvements and the deprecated pragmas. #186 #201 #205 #206 #211
Version 2.6.2.1
-
Regenerate configure and
HsNetworkConfig.h.in. -
Better detection of CAN sockets.
Version 2.6.2.0
-
Add support for
TCP_USER_TIMEOUT. -
Don’t conditionally export the
SockAddrconstructors. -
Add
isSupportSockAddrto allow checking for supported address types at runtime.