network-transport-0.4.0.0: Network abstraction layer

Safe HaskellNone
LanguageHaskell98

Network.Transport.Internal

Contents

Description

Internal functions

Synopsis

Encoders/decoders

encodeInt32 :: Enum a => a -> ByteString Source

Serialize 32-bit to network byte order

decodeInt32 :: Num a => ByteString -> a Source

Deserialize 32-bit from network byte order Throws an IO exception if this is not a valid integer.

encodeInt16 :: Enum a => a -> ByteString Source

Serialize 16-bit to network byte order

decodeInt16 :: Num a => ByteString -> a Source

Deserialize 16-bit from network byte order Throws an IO exception if this is not a valid integer

prependLength :: [ByteString] -> [ByteString] Source

Prepend a list of bytestrings with their total length

Miscellaneous abstractions

mapIOException :: Exception e => (IOException -> e) -> IO a -> IO a Source

Translate exceptions that arise in IO computations

tryIO :: MonadIO m => IO a -> m (Either IOException a) Source

Like try, but lifted and specialized to IOExceptions

tryToEnum :: (Enum a, Bounded a) => Int -> Maybe a Source

Safe version of toEnum

timeoutMaybe :: Exception e => Maybe Int -> e -> IO a -> IO a Source

If the timeout value is not Nothing, wrap the given computation with a timeout and it if times out throw the specified exception. Identity otherwise.

asyncWhenCancelled :: forall a. (a -> IO ()) -> IO a -> IO a Source

asyncWhenCancelled g f runs f in a separate thread and waits for it to complete. If f throws an exception we catch it and rethrow it in the current thread. If the current thread is interrupted before f completes, we run the specified clean up handler (if f throws an exception we assume that no cleanup is necessary).

Replicated functionality from "base"

void :: Monad m => m a -> m () Source

Not all versions of "base" export void

forkIOWithUnmask :: ((forall a. IO a -> IO a) -> IO ()) -> IO ThreadId Source

This was introduced in "base" some time after 7.0.4

Debugging

tlog :: MonadIO m => String -> m () Source

Logging (for debugging)