`Framed.ReadPdu` copied the whole buffer into a new array on every
`FindSize` call. An active-stage PDU announces its length in its first
bytes (four for TPKT, at most three for fast-path), so `Framed` now
probes only the first four buffered bytes into a reusable array;
`ReadByHint` keeps the full copy because connection-time PDUs are few
and small.
New members, alongside the existing ones:
- `ReadPdu(CancellationToken)`, and `CancellationToken` overloads of
`ReadExact` and both `ReadByHint`.
- `TryReadBufferedPdu(out (Action, byte[]))`: takes the next PDU when it
is already buffered, without reading the stream, so a consumer can flush
rendering only when nothing more is pending.
- `ReadPduSync()`: a blocking read for a dedicated read thread.
A cancelled read stops waiting but leaves the stream read in flight; the
next read, asynchronous or synchronous, finishes it first, so bytes are
neither lost nor read twice. Every read reports a stream that ends
before the PDU is complete as `IronRdpLibException(EndOfFile)`, where
`ReadExact` and `ReadByHint` threw a plain `Exception`.
`Connection.Connect`,
`RDCleanPathConnection.ConnectRDCleanPath`/`ConnectVmConnectRDCleanPath`
and `Connection.SingleSequenceStep` take an optional `CancellationToken`
and pass it to the hint reads, the TCP connect and the TLS handshake.
Consumers:
- The Avalonia example cancels the connection sequence and the read loop
through one token on window close or session end, and uses
`TryReadBufferedPdu` to present the bitmap only once no further PDU is
buffered, so a burst of updates draws once.
- `ConnectExample` uses the cancellable read with a timeout instead of
`Task.WhenAny`, which left a read pending.
- Devolutions/IronSessions `RdpSession` uses `TryReadBufferedPdu` to
flush rendering only when the socket is quiet,
`ReadPdu(CancellationToken)` for disconnect and timeout, the cancellable
`ReadByHint` during the connection sequence, and `ReadPduSync` for a
dedicated read thread on Mono (Android/iOS), where awaiting every read
hopped pool threads. `ReadPduSync` has no consumer in this repository on
purpose: the examples are async end to end.
`ffi/INTENT.md` records the probe width, the `ReadByHint` split, the EOF
policy and the read regime.
Smoke tests cover header-only sizing for TPKT and both fast-path length
encodings, several PDUs in one read, a partial PDU left buffered, the
sync read across split reads, EOF inside a PDU body on every read path,
and a cancelled read whose in-flight stream read the next read finishes.
`DecodedImage`, `DecodedPointer` and `ActiveStageOutput` own the
framebuffer, the pointer bitmap and response payloads, which are large
native allocations the garbage collector does not see. That is the first
condition in `ffi/INTENT.md` for being `IDisposable`. They handed out
views that borrow from them, which the new .NET generator refuses for
disposable types, and every caller copied the bytes into a managed array
right away anyway.
- `ActiveStageOutput.ResponseFrame`/`WindowingOrders` and
`DecodedPointer.Data` return an owned `VecU8`, which has the same
`Size`/`Fill` members as the old view.
- `DecodedImage.Data` is replaced by `DataSize` and `FillData(byte[])`.
They copy the framebuffer once into the caller's buffer, and a larger
buffer is fine.
The three types are now `IDisposable`, and `ffi/README.md` lists them.
The Avalonia example disposes the image it replaces on reactivation, and
both examples dispose each output and response frame they read.
BREAKING CHANGE: `DecodedImage.Data` is removed, use `DataSize` and
`FillData`. `ResponseFrame`, `WindowingOrders` and `DecodedPointer.Data`
now return `VecU8` instead of `BytesSlice`.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Marc-André Moreau <mamoreau@devolutions.net>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The .NET bindings were generated by Diplomat 0.7 from a personal fork,
years behind upstream. Move to the protected `Devolutions/diplomat` tag
that IronVNC and picky-rs already use, with the same xtask pinning and
install flow.
Rust side:
- pin `diplomat` and `diplomat-runtime` to tag `0.16.1-devo.2` and drop
the `[patch.crates-io]` entry for the old fork; its zero-length slice
fix is upstream now, since slice parameters go through `DiplomatSlice`,
which maps a null pointer to an empty slice
- `opaque_mut` on the 20 types that are mutated through `&mut`, named
lifetimes on borrowed returns, `DiplomatWriteable` renamed to
`DiplomatWrite`, and no explicit `Clone`/`Copy` on bridge enums
- move `dotnet-interop-conf.toml` to the `lib_name` + `[dotnet]` layout
Tooling: xtask installs `diplomat-tool` from the tag with Rust 1.96.0,
because the tag does not build with the workspace toolchain. It records
the source and version so a tool from another tag is never reused,
checks that the tool and the ffi crate use the same tag, and calls the
tool by absolute path. The `ffi` CI job caches those records with the
binary, so a cache hit does not reinstall the tool.
The library and examples use properties instead of the removed
`GetX()`/`SetX()` methods.
`ffi/README.md` gains a migration section with these steps.
BREAKING CHANGE: for consumers of `Devolutions.IronRdp`:
- `GetX()`/`SetX()` methods that duplicated a property are removed
- the `&mut` getters on `ClientConnectorState` and
`CredsspSequenceInitResult` are methods only
- `IronRdpErrorKind.IO` and `WrongOS` are now `Io` and `WrongOs`
- `Position`, `MultitransportRequest` and `NetworkCharacteristics` are
structs with public fields instead of classes with properties
- the `Devolutions.IronRdp.Raw` namespace is internal, and the public
`AsFFI()` methods and raw-pointer constructors are removed
- `DiplomatWriteable`, `DiplomatOpaqueException` and the
`IronRdpError.ToDisplay(DiplomatWriteable)` overload are removed
- `IronRdpException` is no longer `partial`
- only the ten types listed in `ffi/README.md` are `IDisposable`; every
other type, such as `Config`, `InclusiveRectangle` and
`ClientConnector`, is released by its finalizer and no longer has
`Dispose()`
- overlapping calls on one native object now throw, such as calling
`ActiveStage` from the PDU loop and an input handler at once, or using a
`CredsspSequence` while its `CredsspProcessGenerator` is alive
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
We used to inject the resolved target server address, but that is not
what is expected. Server typically ignores this field so this was not a
problem up until now.