From ae371ea9a5e9615f234f631b01fe81971614a6dd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 18 May 2024 13:46:24 -1000 Subject: [PATCH] Add missing mapping for setsockopt to _WebsocketWrapper Fixes the asyncio example with a websocket wrapped socket https://github.com/eclipse/paho.mqtt.python/blob/d45de3737879cfe7a6acc361631fa5cb1ef584bb/examples/loop_asyncio.py#L92 --- src/paho/mqtt/client.py | 6 +++++- tests/test_websocket_integration.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index 4ccc8696..7b70a197 100644 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -92,7 +92,8 @@ def fileno(self) -> int: ... def setblocking(self, flag: bool) -> None: ... - + def setsockopt(self, level: int, optname: int, value: Any) -> None: + ... try: import ssl @@ -5002,3 +5003,6 @@ def pending(self) -> int: def setblocking(self, flag: bool) -> None: self._socket.setblocking(flag) + + def setsockopt(self, level: int, optname: int, value: Any) -> None: + self._socket.setsockopt(level, optname, value) \ No newline at end of file diff --git a/tests/test_websocket_integration.py b/tests/test_websocket_integration.py index b44f3475..5187d8e8 100644 --- a/tests/test_websocket_integration.py +++ b/tests/test_websocket_integration.py @@ -2,6 +2,7 @@ import hashlib import re import socketserver +import socket from collections import OrderedDict import paho.mqtt.client as client @@ -182,6 +183,8 @@ def test_successful_connection(self, proto_ver, proto_name, with fake_websocket_broker.serve(response): mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) + mqttc.socket().setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + mqttc.disconnect() @pytest.mark.parametrize("mqtt_path", [ @@ -255,3 +258,4 @@ def check_headers_used(decoded): mqttc.connect("localhost", fake_websocket_broker.port, keepalive=10) mqttc.disconnect() +