| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hmssql.Tds.PacketWriter
Description
Writing a message straight into packet buffers, a packet at a time. This
module alone owns a packet's storage and its framing. A producer writes
ordinary Builders, except the bulk row writer and the scalar parameter
path, which poke a value held in memory (unsafeWriteSized).
A packet's storage stays private until its last write. The writer then lets
go of it, and only then is it the ByteString a sink receives, so no
ByteString ever refers to memory that is still being written. What
belongs in front of a packet, such as an SMP header, is the sink's to send
beside it.
Synopsis
- type PacketSink = ByteString -> IO ()
- inSource :: PacketWriter -> forall a. IO a -> IO a
- withSourceScope :: (forall a. IO a -> IO a) -> PacketWriter -> PacketWriter
- data PacketWriter
- runPacketWriter :: TdsContext -> PacketType -> PacketSink -> (PacketWriter -> IO a) -> IO a
- runPacketWriterWith :: TdsContext -> PacketType -> PacketStatus -> PacketSink -> (PacketWriter -> IO a) -> IO a
- writeBytes :: PacketWriter -> ByteString -> IO ()
- writeBuilder :: PacketWriter -> Builder -> IO ()
- unsafeWriteSized :: PacketWriter -> Int -> (Ptr Word8 -> IO ()) -> IO ()
Documentation
type PacketSink = ByteString -> IO () Source #
Where a message's complete TDS packets go, in order. Each is immutable and belongs to the sink: the writer keeps no reference to it.
inSource :: PacketWriter -> forall a. IO a -> IO a Source #
The scope a parameter's source runs in (withSourceScope).
withSourceScope :: (forall a. IO a -> IO a) -> PacketWriter -> PacketWriter Source #
Run the writer's sources in this scope, which is how the connection refuses a request made from inside a parameter's source.
data PacketWriter Source #
The writer of one message: the packet being filled, and where the complete packets go.
runPacketWriter :: TdsContext -> PacketType -> PacketSink -> (PacketWriter -> IO a) -> IO a Source #
Run a producer with a writer for a message of this packet type. Each packet goes to the sink as it fills, and the last when the producer returns.
runPacketWriterWith :: TdsContext -> PacketType -> PacketStatus -> PacketSink -> (PacketWriter -> IO a) -> IO a Source #
runPacketWriter with extra status bits, which go on every packet, except
that RESETCONNECTION goes on the first alone. Every packet but the last is
full.
writeBytes :: PacketWriter -> ByteString -> IO () Source #
Copy bytes into the message, across packets as needed. Nothing of the source is kept once it has been copied, and a full packet goes to the sink when the next byte arrives.
writeBuilder :: PacketWriter -> Builder -> IO () Source #
Run a Builder into the packets. A primitive that needs more
contiguous room than the packet has left is written to a small buffer of
its own, whose bytes fill the current packet and continue in the next, and
a chunk the builder inserts goes through writeBytes.
unsafeWriteSized :: PacketWriter -> Int -> (Ptr Word8 -> IO ()) -> IO () Source #
Write exactly n bytes by poking them: straight into the current packet when they
fit, and otherwise staged in a buffer of their own and copied as writeBytes copies.
The action must write all n bytes from the pointer it is given, read nothing there,
and keep no reference to it. This is for the two producers that compute a
write's size and its pokes from one description of a value: the bulk row
writer, and the scalar parameter path in Hmssql.Tds.Parameter.