Connection
pyvider.rpcplugin.client.connection
¶
Client Connection Management.
This module defines the ClientConnection class, responsible for managing
the state and I/O operations of a single client connection within the
Pyvider RPC Plugin system. It includes metrics tracking and supports
dependency injection for I/O functions to facilitate testing.
Classes¶
ClientConnection
¶
Represents an active client connection with associated metrics and state.
This class wraps the asyncio StreamReader and StreamWriter with additional functionality for tracking metrics and managing connection state. It now supports dependency injection for its I/O functions, allowing tests or alternative implementations to override the default behavior.
Attributes:
| Name | Type | Description |
|---|---|---|
reader |
StreamReader
|
Stream for reading client data. |
writer |
StreamWriter
|
Stream for writing responses. |
remote_addr |
str
|
Remote address of the client. |
bytes_sent |
int
|
Total bytes sent over this connection. |
bytes_received |
int
|
Total bytes received over this connection. |
send_func |
SendFuncType | None
|
Callable used to send data; defaults to _default_send. |
receive_func |
ReceiveFuncType | None
|
Callable used to receive data; defaults to _default_receive. |
Attributes¶
Functions¶
__attrs_post_init__
¶
Post-initialization hook to set default I/O functions if not provided.
Source code in pyvider/rpcplugin/client/connection.py
__del__
¶
Ensure resources are cleaned up.
Raising exceptions in del is generally discouraged; a warning
is logged instead.
Source code in pyvider/rpcplugin/client/connection.py
close
async
¶
Close the connection and clean up resources.
This method is idempotent and can be safely called multiple times.
Source code in pyvider/rpcplugin/client/connection.py
receive_data
async
¶
Receive data from the connection using the injected receive_func.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | None
|
Maximum number of bytes to receive. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Received data as bytes. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the connection is closed. |
Source code in pyvider/rpcplugin/client/connection.py
send_data
async
¶
Send data over the connection using the injected send_func.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Bytes to send. |
required |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the connection is closed. |
Source code in pyvider/rpcplugin/client/connection.py
update_metrics
¶
Update connection metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bytes_sent
|
int
|
Number of bytes sent. |
0
|
bytes_received
|
int
|
Number of bytes received. |
0
|