HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulestreamly-0.10.1Haskell2010

Streamly.Internal.Network.Socket

  • 1 type
  • 28 values
  • Packagestreamly-0.10.1
  • Exports29
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSocket.hs

Use a socket

2 declarations
valueforSocketM :: (MonadMask m, MonadIO m) => (Socket -> m ()) -> Socket -> m ()
#

forSocketM action socket runs the monadic computation action passing the socket handle to it. The handle will be closed on exit from forSocketM, whether by normal termination or by raising an exception. If closing the handle raises an exception, then this exception will be raised by forSocketM rather than any exception raised by action.

Accept connections

2 declarations
valueaccept :: MonadIO m => Int -> SockSpec -> SockAddr -> Stream m Socket
#

Start a TCP stream server that listens for connections on the supplied server address specification (address family, local interface IP address and port). The server generates a stream of connected sockets. The first argument is the maximum number of pending connections in the backlog.

Pre-release

Unfold a three tuple (listenQLen, spec, addr) into a stream of connected protocol sockets corresponding to incoming connections. listenQLen is the maximum number of pending connections in the backlog. spec is the socket protocol and options specification and addr is the protocol address where the server listens for incoming connections.

Connect

2 declarations
valueconnect :: SockSpec -> SockAddr -> IO Socket
#

Connect to a remote host using the given socket specification and remote address. Returns a connected socket or throws an exception.

Pre-release

Connect to a remote host using the given socket specification, a local address to bind to and a remote address to connect to. Returns a connected socket or throws an exception.

Pre-release

Read from connection

1 declaration
valuegetChunk :: Int -> Socket -> IO (Array Word8)
#

Read a byte array from a file handle up to a maximum of the requested size. If no data is available on the handle it blocks until some data becomes available. If data is available then it immediately returns that data without blocking.

Streams

valueread :: MonadIO m => Socket -> Stream m Word8
#

Generate a byte stream from a socket.

Example1 expression
read = Socket.readWith defaultChunkSize

Pre-release

valuereadChunks :: MonadIO m => Socket -> Stream m (Array Word8)
#

Read a stream of byte arrays from a socket. The maximum size of a single array is limited to defaultChunkSize.

Example1 expression
readChunks = Socket.readChunksWith defaultChunkSize

Pre-release

Unfolds

valuereader :: MonadIO m => Unfold m Socket Word8
#

Unfolds a Socket into a byte stream. IO requests to the socket are performed in sizes of Streamly.Internal.Data.Array.Type.defaultChunkSize.

Unfolds a socket into a stream of Word8 arrays. Requests to the socket are performed using a buffer of size Streamly.Internal.Data.Array.Type.defaultChunkSize. The size of arrays in the resulting stream are therefore less than or equal to Streamly.Internal.Data.Array.Type.defaultChunkSize.

Unfold the tuple (bufsize, socket) into a stream of Word8 arrays. Read requests to the socket are performed using a buffer of size bufsize. The size of an array in the resulting stream is always less than or equal to bufsize.

Write to connection

1 declaration

Folds

valuewrite :: MonadIO m => Socket -> Fold m Word8 ()
#

Write a byte stream to a socket. Accumulates the input in chunks of up to defaultChunkSize bytes before writing.

Example1 expression
write = Socket.writeWith defaultChunkSize
valuewriteWith :: MonadIO m => Int -> Socket -> Fold m Word8 ()
#

Write a byte stream to a socket. Accumulates the input in chunks of specified number of bytes before writing.

valuewriteChunksWith
  1. :: (MonadIO m, Unbox a)
  2. => Int
  3. -> Socket
  4. -> Fold m (Array a) ()
#

writeChunksWith bufsize socket writes a stream of arrays to socket after coalescing the adjacent arrays in chunks of bufsize. Multiple arrays are coalesed as long as the total size remains below the specified size. It never splits an array, if a single array is bigger than the specified size it emitted as it is.

Stream writes

valueputBytesWith :: MonadIO m => Int -> Socket -> Stream m Word8 -> m ()
#

Like write but provides control over the write buffer. Output will be written to the IO device as soon as we collect the specified number of input elements.

valueputBytes :: MonadIO m => Socket -> Stream m Word8 -> m ()
#

Write a byte stream to a file handle. Combines the bytes in chunks of size up to defaultChunkSize before writing. Note that the write behavior depends on the IOMode and the current seek position of the handle.

Deprecated

4 declarations