Skip to main content

A general purpose bidirectional packet stream connection.

Latest release 20240412:

  • PacketConnection: now subclasses MultiOpenMixin, big refactor.
  • PacketConnection.init: use @promote to turn the recv parameter into a CornuCopyBuffer.
  • Fix a deadlock.

Class Packet(cs.binary.SimpleBinary)

A protocol packet.

Method Packet.__str__(self): pylint: disable=signature-differs

Method Packet.parse(bfr): Parse a Packet from a buffer.

Method Packet.transcribe(self): Transcribe this packet.

Class PacketConnection(cs.resources.MultiOpenMixin)

A bidirectional binary connection for exchanging requests and responses.

Method PacketConnection.__init__(self, recv: cs.buffer.CornuCopyBuffer, send, request_handler=None, name=None, packet_grace=None, tick=None, recv_len_func=None, send_len_func=None): Initialise the PacketConnection.

Parameters:

  • recv: inbound binary stream. This value is automatically promoted to a cs.buffer.CornuCopyBuffer by the CornuCopyBuffer.promote method.
  • recv_len_func: optional function to compute the data length of a received packet; the default watches the offset on the receive stream
  • send: outbound binary stream. If this is an int it is taken to be an OS file descriptor, otherwise it should be a binary file like object with .write(bytes) and .flush() methods. This objects is not closed by the PacketConnection; the caller has responsibility for that.
  • send_len_func: optional function to compute the data length of a sent packet; the default watches the offset on the send stream
  • packet_grace: default pause in the packet sending worker to allow another packet to be queued before flushing the output stream. Default: DEFAULT_PACKET_GRACEs. A value of 0 will flush immediately if the queue is empty.
  • request_handler: an optional callable accepting (rq_type, flags, payload). The request_handler may return one of 5 values on success:
    • None: response will be 0 flags and an empty payload.
    • int: flags only. Response will be the flags and an empty payload.
    • bytes: payload only. Response will be 0 flags and the payload.
    • str: payload only. Response will be 0 flags and the str encoded as bytes using UTF-8.
    • (int, bytes): Specify flags and payload for response. An unsuccessful request should raise an exception, which will cause a failure response packet.
  • tick: optional tick parameter, default None. If None, do nothing. If a Boolean, call tick_fd_2 if true, otherwise do nothing. Otherwise tick should be a callable accepting a byteslike value.

Method PacketConnection.do(self, *a, **kw): Wrapper function to check that this instance is not closed.

Method PacketConnection.join(self): Wait for the receive side of the connection to terminate.

Method PacketConnection.request(self, *a, **kw): Wrapper function to check that this instance is not closed.

Class Request_State(builtins.tuple)

RequestState(decode_response, result)

Property Request_State.decode_response: Alias for field number 0

Property Request_State.result: Alias for field number 1

Function tick_fd_2(bs)

A low level tick function to write a short binary tick to the standard error file descriptor.

This may be called by the send and receive workers to give an indication of activity type.

Release Log

Release 20240412:

  • PacketConnection: now subclasses MultiOpenMixin, big refactor.
  • PacketConnection.init: use @promote to turn the recv parameter into a CornuCopyBuffer.
  • Fix a deadlock.

Release 20211208:

  • Packet.eq: only test .rq_type if .is_request.
  • Update tests for changes.

Release 20210306:

  • Port to new cs.binary.Binary* classes.
  • Some refactors and small fixes.

Release 20191004:

  • PacketConnection: new optional parameter packet_grace to tune the send delay for additional packets before a flush, default DEFAULT_PACKET_GRACE (0.01s), 0 for no delay.
  • Add a crude packet level activity ticker.

Release 20190221: DISTINFO requirement updates.

Release 20181228: Initial PyPI release.

Release files for cs.packetstream 20240412

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs.packetstream 20240412
File Size Uploaded
cs.packetstream-20240412.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cs.packetstream 20240412
File Interpreter ABI Platform
cs.packetstream-20240412-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / cs.packetstream-20240412.tar.gz

Download URL cs.packetstream-20240412.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f6fbfb389b01c5cd9505aedd4a1d352c5f8d8bab09132ad4cb4948104e1f0a81
BLAKE2b-256 checksum
How to use checksums
c607ce8dbb323b170305677439e59879ea83b18cce090ff62d4ea579f37b0bd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.6

Release files / cs.packetstream-20240412-py3-none-any.whl

Download URL cs.packetstream-20240412-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38687c04386adff75aa3a49a15be0ada255737715a059586e71fdee2e5b6e1db
BLAKE2b-256 checksum
How to use checksums
b0b5214f4fad43f751ff87cc76f04fc452bb7ed465aaeb193263971a1b2f8f8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.6

Release history Release notifications | RSS feed

This release

20240412 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page