Expected behavior
When a custom FileRegion implementation's transferTo(WritableByteChannel, long) emits more bytes than count() - transferred() advertises -- for example, an on-the-fly encryption or framing layer whose count() reports the source size while transferTo() writes larger output (ciphertext, framing prefix/trailer, etc.) -- the io_uring transport should deliver every emitted byte to the peer.
Actual behavior
The generic-FileRegion fallback introduced in #16571 sizes the temporary chunk buffer to min(region.count() - region.transferred(), FILE_REGION_MAX_CHUNK_SIZE). That sizing treats count() as an upper bound on transferTo() output. For an over-emitting FileRegion, the chunk buffer is too small: ByteBufWritableByteChannel.write(ByteBuffer) clamps to the writable byte count, returns the clamped count to the region as if those bytes were accepted, and the excess is silently dropped on the floor.
If the implementation then advances transferred() to count() once its source is drained (the usual pattern when wrapping a fixed-size source), the io_uring completion handler treats transferred() >= count() as "done" and removes the entry from the outbound buffer while a portion of the per-call output is still sitting inside the region. The peer sees a partial frame and the connection stalls.
Steps to reproduce
The regression test added in the proposed fix is a self-contained reproducer (SocketFileRegionTest#testFileRegionEmittingMoreThanCount with EmitMoreThanCountFileRegion fixture). The fixture reports count() = 5 while transferTo() writes 20 bytes in one call. Against unpatched io_uring code the transport's 5-byte chunk buffer accepts only 5 of the emitted bytes; the fixture's fail-fast short-write check throws IOException, which surfaces on the write future and fails the test. With the fix applied the receiver observes all 20 bytes.
Minimal yet complete reproducer code (or URL to code)
See SocketFileRegionTest#testFileRegionEmittingMoreThanCount in the proposed fix.
Netty version
4.2.14.Final-SNAPSHOT (and any prior 4.2.x with #16571 applied).
JVM version (e.g. java -version)
Any JVM that supports Netty 4.2.
OS version (e.g. uname -a)
Linux (io_uring transport).