Skip to content

Commit

Permalink
Bind connack_timeout_ms for mqtt5 (#548)
Browse files Browse the repository at this point in the history
Co-authored-by: Bret Ambrose <bretambrose@gmail.com>
  • Loading branch information
sbSteveK and bretambrose committed May 22, 2024
1 parent b5c7972 commit 68afb70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
12 changes: 7 additions & 5 deletions awscrt/mqtt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,8 @@ class ConnackPacket:
Args:
session_present (bool): True if the client rejoined an existing session on the server, false otherwise.
reason_code (ConnectReasonCode): Indicates either success or the reason for failure for the connection attempt. session_expiry_interval_sec (int): A time interval, in seconds, that the server will persist this connection's MQTT session state for. If present, this value overrides any session expiry specified in the preceding CONNECT packet.
reason_code (ConnectReasonCode): Indicates either success or the reason for failure for the connection attempt.
session_expiry_interval_sec (int): A time interval, in seconds, that the server will persist this connection's MQTT session state for. If present, this value overrides any session expiry specified in the preceding CONNECT packet.
receive_maximum (int): The maximum amount of in-flight QoS 1 or 2 messages that the server is willing to handle at once. If omitted or None, the limit is based on the valid MQTT packet id space (65535).
maximum_qos (QoS): The maximum message delivery quality of service that the server will allow on this connection.
retain_available (bool): Indicates whether the server supports retained messages. If None, retained messages are supported.
Expand Down Expand Up @@ -1236,10 +1237,10 @@ class OperationStatisticsData:
"""Dataclass containing some simple statistics about the current state of the client's queue of operations
Args:
incomplete_operation_count (int): total number of operations submitted to the client that have not yet been completed. Unacked operations are a subset of this.
incomplete_operation_size (int): total packet size of operations submitted to the client that have not yet been completed. Unacked operations are a subset of this.
unacked_operation_count (int): total number of operations that have been sent to the server and are waiting for a corresponding ACK before they can be completed.
unacked_operation_size (int): total packet size of operations that have been sent to the server and are waiting for a corresponding ACK before they can be completed.
incomplete_operation_count (int): Total number of operations submitted to the client that have not yet been completed. Unacked operations are a subset of this.
incomplete_operation_size (int): Total packet size of operations submitted to the client that have not yet been completed. Unacked operations are a subset of this.
unacked_operation_count (int): Total number of operations that have been sent to the server and are waiting for a corresponding ACK before they can be completed.
unacked_operation_size (int): Total packet size of operations that have been sent to the server and are waiting for a corresponding ACK before they can be completed.
"""
incomplete_operation_count: int = 0
incomplete_operation_size: int = 0
Expand Down Expand Up @@ -1792,6 +1793,7 @@ def __init__(self, client_options: ClientOptions):
client_options.max_reconnect_delay_ms,
client_options.min_connected_time_to_reset_reconnect_delay_ms,
client_options.ping_timeout_ms,
client_options.connack_timeout_ms,
client_options.ack_timeout_sec,
client_options.topic_aliasing_options,
websocket_is_none,
Expand Down
19 changes: 17 additions & 2 deletions source/mqtt5_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static const char *AWS_PYOBJECT_KEY_MAX_RECONNECT_DELAY_MS = "max_reconnect_dela
static const char *AWS_PYOBJECT_KEY_MIN_CONNECTED_TIME_TO_RESET_RECONNECT_DELAY_MS =
"min_connected_time_to_reset_reconnect_delay_ms";
static const char *AWS_PYOBJECT_KEY_PING_TIMEOUT_MS = "ping_timeout_ms";
static const char *AWS_PYOBJECT_KEY_CONNACK_TIMEOUT_MS = "connack_timeout_ms";
static const char *AWS_PYOBJECT_KEY_ACK_TIMEOUT_SECONDS = "ack_timeout_seconds";

#define KEEP_ALIVE_INTERVAL_SECONDS 1200
Expand Down Expand Up @@ -815,7 +816,7 @@ PyObject *aws_py_mqtt5_client_new(PyObject *self, PyObject *args) {

/* Connect Options */
struct aws_byte_cursor client_id; /* optional */
PyObject *keep_alive_interval_sec_py; /* uint16_t */
PyObject *keep_alive_interval_sec_py; /* optional uint16_t */
struct aws_byte_cursor username; /* optional */
struct aws_byte_cursor password; /* optional */
PyObject *session_expiry_interval_sec_py; /* optional uint32_t */
Expand Down Expand Up @@ -848,6 +849,7 @@ PyObject *aws_py_mqtt5_client_new(PyObject *self, PyObject *args) {
PyObject *max_reconnect_delay_ms_py; /* optional uint64_t */
PyObject *min_connected_time_to_reset_reconnect_delay_ms_py; /* optional uint64_t */
PyObject *ping_timeout_ms_py; /* optional uint32_t */
PyObject *connack_timeout_ms_py; /* optional uint32_t */
PyObject *ack_timeout_seconds_py; /* optional uint32_t */
PyObject *topic_aliasing_options_py; /* optional TopicAliasingOptions */
/* Callbacks */
Expand All @@ -856,7 +858,7 @@ PyObject *aws_py_mqtt5_client_new(PyObject *self, PyObject *args) {

if (!PyArg_ParseTuple(
args,
"Os#IOOOOz#Oz#z#OOOOOOOOOz*Oz#OOOz#z*z#OOOOOOOOOOOOO",
"Os#IOOOOz#Oz#z#OOOOOOOOOz*Oz#OOOz#z*z#OOOOOOOOOOOOOO",
/* O */ &self_py,
/* s */ &host_name.ptr,
/* # */ &host_name.len,
Expand Down Expand Up @@ -906,6 +908,7 @@ PyObject *aws_py_mqtt5_client_new(PyObject *self, PyObject *args) {
/* O */ &max_reconnect_delay_ms_py,
/* O */ &min_connected_time_to_reset_reconnect_delay_ms_py,
/* O */ &ping_timeout_ms_py,
/* O */ &connack_timeout_ms_py,
/* O */ &ack_timeout_seconds_py,
/* O */ &topic_aliasing_options_py,

Expand Down Expand Up @@ -1079,6 +1082,18 @@ PyObject *aws_py_mqtt5_client_new(PyObject *self, PyObject *args) {
goto done;
}

uint32_t connack_timeout_ms_tmp = 0;
if (PyObject_GetAsOptionalUint32(
connack_timeout_ms_py,
AWS_PYOBJECT_KEY_CLIENT_OPTIONS,
AWS_PYOBJECT_KEY_CONNACK_TIMEOUT_MS,
&connack_timeout_ms_tmp)) {
client_options.connack_timeout_ms = connack_timeout_ms_tmp;
}
if (PyErr_Occurred()) {
goto done;
}

uint32_t ack_timeout_seconds_tmp = 0;
if (PyObject_GetAsOptionalUint32(
ack_timeout_seconds_py,
Expand Down

0 comments on commit 68afb70

Please sign in to comment.