| Server IP : 172.67.201.108 / Your IP : 216.73.217.39 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib64/python3.9/site-packages/awscrt/__pycache__/ |
Upload File : |
a
ů�i�o � @ s� d Z ddlZddlmZ ddlZddlmZmZ ddlm Z m
Z
mZ ddlm
Z
ddlmZ ddlZddlmZmZmZmZmZ G d d
� d
e�ZdZe
G dd
� d
��Ze
G dd� d��Ze
G dd� d��Ze
G dd� d��Ze
G dd� d��Ze
G dd� d��Ze
G dd� d��ZG dd� de�Z G dd� de�Z!dddddddddddd�e"ee# eee ee ee
ee e$ee# eegdf eeegdf eeegdf eeegdf eeegdf d �d!d"�Z%d#d$�e"e"ed%�d&d'�Z&dS )(a�
WebSocket - `RFC 6455 <https://www.rfc-editor.org/rfc/rfc6455>`_
Use the :func:`connect()` to establish a :class:`WebSocket` client connection.
Note from the developer: This is a very low-level API, which forces the
user to deal with things like data fragmentation.
A higher-level API could easily be built on top of this.
.. _authoring-callbacks:
Authoring Callbacks
-------------------
All network operations in `awscrt.websocket` are asynchronous.
Callbacks are always invoked on the WebSocket's networking thread.
You MUST NOT perform blocking network operations from any callback, or you will cause a deadlock.
For example: do not send a frame, and then wait for that frame to complete,
within a callback. The WebSocket cannot do work until your callback returns,
so the thread will be stuck. You can send the frame from within the callback,
just don't wait for it to complete within the callback.
If you want to do blocking waits, do it from a thread you control, like the main thread.
It's fine for the main thread to send a frame, and wait until it completes.
All functions and methods in `awscrt.websocket` are thread-safe.
They can be called from any mix of threads.
.. _flow-control-reading:
Flow Control (reading)
----------------------
By default, the WebSocket will read from the network as fast as it can hand you the data.
You must prevent the WebSocket from reading data faster than you can process it,
or memory usage could balloon until your application explodes.
There are two ways to manage this.
First, and simplest, is to process incoming data synchronously within the
`on_incoming_frame` callbacks. Since callbacks are invoked on the WebSocket's
networking thread, the WebSocket cannot read more data until the callback returns.
Therefore, processing the data in a synchronous manner
(i.e. writing to disk, printing to screen, etc) will naturally
affect `TCP flow control <https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Flow_control>`_,
and prevent data from arriving too fast. However, you MUST NOT perform a blocking
network operation from within the callback or you risk deadlock (see :ref:`authoring-callbacks`).
The second, more complex, way requires you to manage the size of the read window.
Do this if you are processing the data asynchronously
(i.e. sending the data along on another network connection).
Create the WebSocket with `manage_read_window` set true,
and set `initial_read_window` to the number of bytes you are ready to receive right away.
Whenever the read window reaches 0, you will stop receiving anything.
The read window shrinks as you receive the payload from "data" frames (TEXT, BINARY, CONTINUATION).
Call :meth:`WebSocket.increment_read_window()` to increase the window again keep frames flowing in.
You only need to worry about the payload from "data" frames.
The WebSocket automatically increments its window to account for any
other incoming bytes, including other parts of a frame (opcode, payload-length, etc)
and the payload of other frame types (PING, PONG, CLOSE).
You'll probably want to do it like this:
Pick the max amount of memory to buffer, and set this as the `initial_read_window`.
When data arrives, the window has shrunk by that amount.
Send this data along on the other network connection.
When that data is done sending, call `increment_read_window()`
by the amount you just finished sending.
If you don't want to receive any data at first, set the `initial_read_window` to 0,
and `increment_read_window()` when you're ready.
Maintaining a larger window is better for overall throughput.
.. _flow-control-writing:
Flow Control (writing)
----------------------
You must also ensure that you do not continually send frames faster than the other
side can read them, or memory usage could balloon until your application explodes.
The simplest approach is to only send 1 frame at a time.
Use the :meth:`WebSocket.send_frame()` `on_complete` callback to know when the send is complete.
Then you can try and send another.
A more complex, but higher throughput, way is to let multiple frames be in flight
but have a cap. If the number of frames in flight, or bytes in flight, reaches
your cap then wait until some frames complete before trying to send more.
.. _api:
API
---
� N)�NativeResource)�HttpProxyOptions�HttpRequest)�ClientBootstrap�TlsConnectionOptions�
SocketOptions)� dataclass)�IntEnum)�Callable�Optional�Sequence�Tuple�Unionc @ s0 e Zd ZdZdZdZdZdZdZdZ dd � Z
d
S )�Opcodea> An opcode defines a frame's type.
RFC 6455 classifies TEXT and BINARY as `data frames <https://www.rfc-editor.org/rfc/rfc6455#section-5.6>`_.
A CONTINUATION frame "continues" the most recent data frame.
All other opcodes are for `control frames <https://www.rfc-editor.org/rfc/rfc6455#section-5.5>`_.
)r � � � � �
c C s | j tjtjtjfv S )aR True if this is a "data frame" opcode.
TEXT, BINARY, and CONTINUATION are "data frames". The rest are "control" frames.
If the WebSocket was created with `manage_read_window`,
then the read window shrinks as "data frames" are received.
See :ref:`flow-control-reading` for a thorough explanation.
)�valuer �TEXT�BINARY�CONTINUATION��self� r �6/usr/lib64/python3.9/site-packages/awscrt/websocket.py�
is_data_frame� s zOpcode.is_data_frameN)�__name__�
__module__�__qualname__�__doc__r r r ZCLOSEZPINGZPONGr r r r r r g s r l ���� c @ sj e Zd ZU dZdZee ed<