appmesh 1.6.0__py3-none-any.whl → 1.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appmesh/tcp_transport.py +23 -16
- {appmesh-1.6.0.dist-info → appmesh-1.6.1.dist-info}/METADATA +1 -1
- {appmesh-1.6.0.dist-info → appmesh-1.6.1.dist-info}/RECORD +5 -5
- {appmesh-1.6.0.dist-info → appmesh-1.6.1.dist-info}/WHEEL +0 -0
- {appmesh-1.6.0.dist-info → appmesh-1.6.1.dist-info}/top_level.txt +0 -0
appmesh/tcp_transport.py
CHANGED
@@ -108,7 +108,7 @@ class TCPTransport:
|
|
108
108
|
self._socket = ssl_socket
|
109
109
|
except (socket.error, ssl.SSLError) as e:
|
110
110
|
sock.close()
|
111
|
-
raise RuntimeError(f"Failed to connect to {self.tcp_address}: {e}")
|
111
|
+
raise RuntimeError(f"Failed to connect to {self.tcp_address}: {e}") from e
|
112
112
|
|
113
113
|
def close(self) -> None:
|
114
114
|
"""Close socket connection"""
|
@@ -137,7 +137,7 @@ class TCPTransport:
|
|
137
137
|
self._socket.sendall(data)
|
138
138
|
except (socket.error, ssl.SSLError) as e:
|
139
139
|
self.close()
|
140
|
-
raise RuntimeError(f"Error sending message: {e}")
|
140
|
+
raise RuntimeError(f"Error sending message: {e}") from e
|
141
141
|
|
142
142
|
def receive_message(self) -> Optional[bytearray]:
|
143
143
|
"""Receive a message with a prefixed header indicating its length and validate it"""
|
@@ -156,39 +156,46 @@ class TCPTransport:
|
|
156
156
|
return None
|
157
157
|
except (socket.error, ssl.SSLError) as e:
|
158
158
|
self.close()
|
159
|
-
raise RuntimeError(f"Error receiving message: {e}")
|
159
|
+
raise RuntimeError(f"Error receiving message: {e}") from e
|
160
160
|
|
161
|
-
def _recvall(self, length: int) ->
|
162
|
-
"""
|
161
|
+
def _recvall(self, length: int) -> bytes:
|
162
|
+
"""Receive exactly `length` bytes from the socket.
|
163
163
|
https://stackoverflow.com/questions/64466530/using-a-custom-socket-recvall-function-works-only-if-thread-is-put-to-sleep
|
164
|
+
|
164
165
|
Args:
|
165
|
-
length (int):
|
166
|
+
length (int): Number of bytes to receive.
|
166
167
|
|
167
168
|
Returns:
|
168
|
-
|
169
|
+
bytes: Received data.
|
169
170
|
|
170
171
|
Raises:
|
171
|
-
EOFError: If connection closes
|
172
|
-
ValueError: If length is
|
172
|
+
EOFError: If connection closes before receiving all data.
|
173
|
+
ValueError: If length is not positive.
|
174
|
+
socket.timeout: If socket operation times out.
|
173
175
|
"""
|
174
176
|
if length <= 0:
|
175
177
|
raise ValueError(f"Invalid length: {length}")
|
176
178
|
|
177
|
-
# Pre-allocate buffer
|
179
|
+
# Pre-allocate buffer
|
178
180
|
buffer = bytearray(length)
|
179
|
-
|
181
|
+
mv = memoryview(buffer)
|
180
182
|
bytes_received = 0
|
181
183
|
|
182
184
|
while bytes_received < length:
|
183
|
-
# Use recv_into to read directly into our buffer
|
184
185
|
try:
|
185
|
-
|
186
|
+
# Receive directly into buffer
|
187
|
+
remaining = length - bytes_received
|
188
|
+
chunk_size = self._socket.recv_into(mv, remaining)
|
186
189
|
|
187
190
|
if chunk_size == 0:
|
188
191
|
raise EOFError("Connection closed by peer")
|
189
192
|
|
193
|
+
mv = mv[chunk_size:] # advance memoryview
|
190
194
|
bytes_received += chunk_size
|
191
|
-
except socket.timeout:
|
192
|
-
raise socket.timeout(f"Socket operation timed out after receiving {bytes_received}/{length} bytes")
|
193
195
|
|
194
|
-
|
196
|
+
except InterruptedError:
|
197
|
+
continue
|
198
|
+
except socket.timeout as e:
|
199
|
+
raise socket.timeout(f"Socket operation timed out after receiving {bytes_received}/{length} bytes") from e
|
200
|
+
|
201
|
+
return bytes(buffer) # safer than bytearray
|
@@ -8,8 +8,8 @@ appmesh/client_tcp.py,sha256=hE0T_2Z0OQZdF5zi--iuvu2_-ka0DfSSQ4BP3oHlg44,11243
|
|
8
8
|
appmesh/server_http.py,sha256=zr9sfS8g_mtP2kuAfmz-qU7rLSFTVt3srbFXaCbl8Y0,4253
|
9
9
|
appmesh/server_tcp.py,sha256=biBFF5IGWFOw2ru831cfmzn1DVXcBm9e-W6CP2VkfzE,1444
|
10
10
|
appmesh/tcp_messages.py,sha256=4XRv5lSm_8ElMg_37SuyIRrfxI7XFNNP_7SdO7us3PA,1023
|
11
|
-
appmesh/tcp_transport.py,sha256=
|
12
|
-
appmesh-1.6.
|
13
|
-
appmesh-1.6.
|
14
|
-
appmesh-1.6.
|
15
|
-
appmesh-1.6.
|
11
|
+
appmesh/tcp_transport.py,sha256=f28zfZNH46tUHfT8F1PrCM1wUXiSBIW7R3ipMsXJqIU,8946
|
12
|
+
appmesh-1.6.1.dist-info/METADATA,sha256=DvJTf5922gT6fc-iOWizqodwljYIkIlCCI1SeTd0juM,11847
|
13
|
+
appmesh-1.6.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
14
|
+
appmesh-1.6.1.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
15
|
+
appmesh-1.6.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|