MCPcopy Create free account
hub / github.com/apache/trafficserver / drain_socket

Function drain_socket

tests/gold_tests/post/http_utils.py:69–93  ·  view source on GitHub ↗

Read the rest of the transaction. :param sock: The socket to drain. :param num_bytes_to_drain: The number of bytes to drain. If -1, then drain bytes until the final zero-length chunk is read.

(sock: socket.socket, previously_read_data: bytes, num_bytes_to_drain: int)

Source from the content-addressed store, hash-verified

67
68
69def drain_socket(sock: socket.socket, previously_read_data: bytes, num_bytes_to_drain: int) -> None:
70 """Read the rest of the transaction.
71
72 :param sock: The socket to drain.
73 :param num_bytes_to_drain: The number of bytes to drain. If -1, then drain
74 bytes until the final zero-length chunk is read.
75 """
76
77 read_data = previously_read_data
78 num_bytes_drained = 0
79 while True:
80 if num_bytes_to_drain > 0:
81 if num_bytes_drained >= num_bytes_to_drain:
82 break
83 elif b'0\r\n\r\n' == read_data[-5:]:
84 print("Found end of chunked data.")
85 break
86
87 data = sock.recv(1024)
88 print(f'Received:\n{data}')
89 if not data:
90 print("Socket closed.")
91 break
92 num_bytes_drained += len(data)
93 read_data += data

Callers 3

drain_responseFunction · 0.90
mainFunction · 0.90
drain_responseFunction · 0.90

Calls 1

recvMethod · 0.45

Tested by

no test coverage detected