Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions serialx/platforms/serial_rfc2217/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,12 @@ def _get_modem_pins(self) -> ModemPins:
return self._engine.get_modem_pins()

def _flush(self) -> None:
"""Flush write buffers (no-op, TCP handles buffering)."""
"""Wait for the server to acknowledge all preceding writes."""
if not self._engine.negotiated:
return

# RFC2217 has no flush. Instead, we "flush" the pipe with a req/rsp sequence.
self._send_and_wait(SetBaudrateCmd(baudrate=self._baudrate))


class _RFC2217ProxyProtocol(asyncio.Protocol):
Expand Down Expand Up @@ -1007,7 +1012,13 @@ def abort(self) -> None:
self._tcp_connection_lost(None)

async def flush(self) -> None:
"""Flush write buffers (no-op, TCP transport handles buffering)."""
"""Wait for the server to acknowledge all preceding writes."""
assert self._serial is not None
if not self._serial._engine.negotiated:
return

# RFC2217 has no flush. Instead, we "flush" the pipe with a req/rsp sequence.
await self._send_and_wait(SetBaudrateCmd(baudrate=self._serial._baudrate))

def get_write_buffer_size(self) -> int:
"""Get the number of bytes currently in the write buffer."""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_sync_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,11 @@ def test_fast_open_close(serial_pair: SerialPair) -> None:
with Serial.from_url(serial_pair.left, baudrate=115200) as left:
with Serial.from_url(serial_pair.right, baudrate=115200) as right:
right.write(message)
right.flush()

# Some backends (notably complex chained RFC2217) lose data on close, making
# this test flaky without a tiny delay
time.sleep(0.01)

assert left.readexactly(len(message)) == message

Expand Down
Loading