bbperf 0.0.7__tar.gz → 0.0.9__tar.gz

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.
Files changed (32) hide show
  1. {bbperf-0.0.7 → bbperf-0.0.9}/PKG-INFO +1 -1
  2. {bbperf-0.0.7 → bbperf-0.0.9}/bbperf.service +0 -1
  3. {bbperf-0.0.7 → bbperf-0.0.9}/pyproject.toml +1 -1
  4. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/bbperf.py +1 -1
  5. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/client.py +70 -88
  6. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/const.py +1 -3
  7. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/control_receiver_thread.py +17 -17
  8. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/data_receiver_thread.py +16 -36
  9. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/data_sender_thread.py +32 -36
  10. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/graph.py +4 -4
  11. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/json_output_class.py +3 -2
  12. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/output.py +9 -7
  13. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/run_mode_manager_class.py +37 -39
  14. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/server.py +59 -67
  15. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/tcp_control_connection_class.py +14 -52
  16. bbperf-0.0.9/src/bbperf/tcp_helper.py +59 -0
  17. bbperf-0.0.9/src/bbperf/udp_helper.py +18 -0
  18. bbperf-0.0.9/src/bbperf/udp_initial_string_sender_thread.py +33 -0
  19. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/udp_rate_manager_class.py +2 -1
  20. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/util.py +3 -26
  21. bbperf-0.0.7/src/bbperf/data_udp_ping_sender_thread.py +0 -45
  22. {bbperf-0.0.7 → bbperf-0.0.9}/.gitignore +0 -0
  23. {bbperf-0.0.7 → bbperf-0.0.9}/DEPLOY.txt +0 -0
  24. {bbperf-0.0.7 → bbperf-0.0.9}/LICENSE +0 -0
  25. {bbperf-0.0.7 → bbperf-0.0.9}/README.md +0 -0
  26. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/.gitignore +0 -0
  27. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/__init__.py +0 -0
  28. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/data_sample_evaluator_class.py +0 -0
  29. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/exceptions.py +0 -0
  30. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/tcp-graph.gp +0 -0
  31. {bbperf-0.0.7 → bbperf-0.0.9}/src/bbperf/udp-graph.gp +0 -0
  32. {bbperf-0.0.7 → bbperf-0.0.9}/tests/run_test.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bbperf
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: An end-to-end performance and bufferbloat measurement tool
5
5
  Project-URL: Homepage, https://github.com/cloudflare/bbperf
6
6
  Project-URL: Issues, https://github.com/cloudflare/bbperf/issues
@@ -5,7 +5,6 @@ After=syslog.target network.target
5
5
  [Service]
6
6
  Type=simple
7
7
  User=mfreemon
8
- Environment=PYTHONUNBUFFERED=1
9
8
  ExecStart=/home/mfreemon/bbperf-dev-venv/bin/bbperf -s
10
9
  Restart=always
11
10
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bbperf"
7
- version = "0.0.7"
7
+ version = "0.0.9"
8
8
  authors = [
9
9
  { name="Mike Freemon", email="mfreemon@cloudflare.com" },
10
10
  ]
@@ -1,4 +1,4 @@
1
- #!/usr/bin/python3 -u
1
+ #!/usr/bin/python3
2
2
 
3
3
  # Copyright (c) 2024 Cloudflare, Inc.
4
4
  # Licensed under the Apache 2.0 license found in the LICENSE file or at https://www.apache.org/licenses/LICENSE-2.0
@@ -7,105 +7,125 @@ import multiprocessing
7
7
  import time
8
8
  import queue
9
9
  import socket
10
+ import uuid
11
+ import json
10
12
 
11
13
  from . import data_sender_thread
12
- from . import data_udp_ping_sender_thread
14
+ from . import udp_initial_string_sender_thread
13
15
  from . import data_receiver_thread
14
16
  from . import control_receiver_thread
15
17
  from . import util
16
18
  from . import const
17
19
  from . import output
18
20
  from . import graph
21
+ from . import tcp_helper
19
22
 
20
23
  from .tcp_control_connection_class import TcpControlConnectionClass
21
24
 
22
25
 
23
26
  def client_mainline(args):
24
27
  if args.verbosity:
25
- print("args: {}".format(args))
28
+ print("args: {}".format(args), flush=True)
26
29
 
27
30
  server_ip = args.client
28
31
  server_port = args.port
29
-
30
- data_conn_verification_str = "d" + const.SOFT_SECRET + " "
32
+ server_addr = (server_ip, server_port)
31
33
 
32
34
  # create control connection
33
35
 
34
36
  if args.verbosity:
35
- print("creating control connection")
37
+ print("creating control connection", flush=True)
36
38
 
37
39
  control_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
38
- control_sock.connect((server_ip, server_port))
40
+ control_sock.connect(server_addr)
39
41
 
40
42
  control_conn = TcpControlConnectionClass(control_sock)
41
43
  control_conn.set_args(args)
42
44
 
43
- control_conn.send_validation_string()
45
+ # generate a random UUID (36 character string)
46
+ run_id = str(uuid.uuid4())
47
+ control_initial_string = "control " + run_id
48
+ control_conn.send_string(control_initial_string)
44
49
 
45
50
  if args.verbosity:
46
-
47
- print("created control connection")
51
+ print("created control connection", flush=True)
48
52
 
49
53
  if args.verbosity:
50
- print("sending args to server {}".format(vars(args)))
54
+ print("sending args to server {}".format(vars(args)), flush=True)
51
55
 
52
- control_conn.send_args_to_server(args)
56
+ args_json = json.dumps(vars(args))
57
+ control_conn.send_string(args_json)
53
58
 
54
59
  if args.verbosity:
55
- print("sent args to server")
60
+ print("sent args to server", flush=True)
56
61
 
57
62
  # create data connection
58
63
 
59
64
  if args.verbosity:
60
- print("creating data connection")
65
+ print("creating data connection", flush=True)
66
+
67
+ data_initial_string = "data " + run_id
61
68
 
62
69
  if args.udp:
63
70
  data_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
64
71
  data_sock.settimeout(const.SOCKET_TIMEOUT_SEC)
72
+ data_sock.connect(server_addr)
73
+
74
+ # start and keep sending the data connection initial string asynchronously
75
+ shared_initial_string_done = multiprocessing.Value('i', 0)
76
+ data_udp_ping_sender_process = multiprocessing.Process(
77
+ name = "datainitialsender",
78
+ target = udp_initial_string_sender_thread.run,
79
+ args = (args, data_sock, data_initial_string, shared_initial_string_done),
80
+ daemon = True)
81
+ data_udp_ping_sender_process.start()
65
82
 
66
83
  else:
67
84
  data_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
68
85
  data_sock.connect((server_ip, server_port))
69
86
  data_sock.settimeout(const.SOCKET_TIMEOUT_SEC)
87
+ tcp_helper.send_string(args, data_sock, data_initial_string)
70
88
 
71
- # send verification string
72
- num_bytes_sent = data_sock.send(data_conn_verification_str.encode())
73
- if num_bytes_sent != len(data_conn_verification_str):
74
- raise Exception("ERROR: send failed")
89
+ if args.verbosity:
90
+ print("created data connection", flush=True)
75
91
 
76
- server_addr = (server_ip, server_port)
92
+ # wait for connection setup complete message
93
+ len_of_setup_complete_message = len(const.SETUP_COMPLETE_MSG)
94
+ payload_bytes = tcp_helper.recv_exact_num_bytes(control_sock, len_of_setup_complete_message)
95
+ payload_str = payload_bytes.decode()
96
+ if payload_str != const.SETUP_COMPLETE_MSG:
97
+ raise Exception("ERROR: client_mainline: setup complete message was not received")
98
+
99
+ if args.udp:
100
+ shared_initial_string_done.value = 1
77
101
 
78
102
  if args.verbosity:
79
- print("created data connection ({})".format("udp" if args.udp else "tcp"))
103
+ print("connection setup complete: message received", flush=True)
104
+ print("test running, {} {} to server {}".format(
105
+ "udp" if args.udp else "tcp",
106
+ "down" if args.reverse else "up",
107
+ server_addr),
108
+ flush=True)
80
109
 
81
110
  shared_run_mode = multiprocessing.Value('i', const.RUN_MODE_CALIBRATING)
82
111
  shared_udp_sending_rate_pps = multiprocessing.Value('d', const.UDP_DEFAULT_INITIAL_RATE)
83
-
84
- # run test
85
-
86
- if args.verbosity:
87
- print("test running")
112
+ control_receiver_results_queue = multiprocessing.Queue()
88
113
 
89
114
  if not args.reverse:
90
115
  # up direction
91
116
 
92
- control_receiver_stdout_queue = multiprocessing.Queue()
93
- control_receiver_results_queue = multiprocessing.Queue()
94
-
95
117
  control_receiver_process = multiprocessing.Process(
96
118
  name = "controlreceiver",
97
119
  target = control_receiver_thread.run_recv_term_queue,
98
- args = (args, control_receiver_stdout_queue, control_conn, control_receiver_results_queue, shared_run_mode, shared_udp_sending_rate_pps),
120
+ args = (args, control_conn, control_receiver_results_queue, shared_run_mode, shared_udp_sending_rate_pps),
99
121
  daemon = True)
100
122
 
101
123
  control_receiver_process.start()
102
124
 
103
- data_sender_stdout_queue = multiprocessing.Queue()
104
-
105
125
  data_sender_process = multiprocessing.Process(
106
126
  name = "datasender",
107
127
  target = data_sender_thread.run,
108
- args = (args, data_sender_stdout_queue, data_sock, server_addr, shared_run_mode, shared_udp_sending_rate_pps),
128
+ args = (args, data_sock, shared_run_mode, shared_udp_sending_rate_pps),
109
129
  daemon = True)
110
130
 
111
131
  # test starts here
@@ -115,109 +135,71 @@ def client_mainline(args):
115
135
  thread_list.append(control_receiver_process)
116
136
  thread_list.append(data_sender_process)
117
137
 
118
- queue_list = []
119
- queue_list.append([control_receiver_results_queue, output.print_output])
120
- queue_list.append([control_receiver_stdout_queue, print])
121
- queue_list.append([data_sender_stdout_queue, print])
122
-
123
138
  if args.reverse:
124
139
  # down direction
125
140
 
126
- # udp pinger
127
- if args.udp:
128
- data_udp_ping_sender_stdout_queue = multiprocessing.Queue()
129
-
130
- data_udp_ping_sender_process = multiprocessing.Process(
131
- name = "dataudppingsender",
132
- target = data_udp_ping_sender_thread.run,
133
- args = (args, data_udp_ping_sender_stdout_queue, data_sock, server_addr),
134
- daemon = True)
135
-
136
- data_udp_ping_sender_process.start()
137
-
138
- # yield to let the first ping fly
139
- time.sleep(0.005)
140
-
141
- data_receiver_stdout_queue = multiprocessing.Queue()
142
-
143
141
  data_receiver_process = multiprocessing.Process(
144
142
  name = "datareceiver",
145
143
  target = data_receiver_thread.run,
146
- args = (args, data_receiver_stdout_queue, control_conn, data_sock, server_addr),
144
+ args = (args, control_conn, data_sock),
147
145
  daemon = True)
148
146
 
149
147
  data_receiver_process.start()
150
148
 
151
- control_receiver_stdout_queue = multiprocessing.Queue()
152
- control_receiver_results_queue = multiprocessing.Queue()
153
-
154
149
  control_receiver_process = multiprocessing.Process(
155
150
  name = "controlreceiver",
156
151
  target = control_receiver_thread.run_recv_queue,
157
- args = (args, control_receiver_stdout_queue, control_conn, control_receiver_results_queue),
152
+ args = (args, control_conn, control_receiver_results_queue),
158
153
  daemon = True)
159
154
 
160
155
  control_receiver_process.start()
161
156
 
162
157
  # test starts here
163
158
 
164
- control_conn.send_start_message_to_server()
159
+ if args.verbosity:
160
+ print("sending start message", flush=True)
161
+
162
+ control_conn.send_string(const.START_MSG)
165
163
 
166
164
  thread_list = []
167
165
  thread_list.append(data_receiver_process)
168
166
  thread_list.append(control_receiver_process)
169
- if args.udp:
170
- thread_list.append(data_udp_ping_sender_process)
171
-
172
- queue_list = []
173
- if args.udp:
174
- queue_list.append([data_udp_ping_sender_stdout_queue, print])
175
- queue_list.append([data_receiver_stdout_queue, print])
176
- queue_list.append([control_receiver_stdout_queue, print])
177
- queue_list.append([control_receiver_results_queue, output.print_output])
178
-
179
167
 
180
168
  # output loop
181
169
 
182
170
  output.init(args)
183
171
 
184
172
  while True:
185
- queue_was_processed = False
186
-
187
- for queue_to_read, function_to_call in queue_list:
188
- try:
189
- s1 = queue_to_read.get_nowait()
190
- queue_was_processed = True
191
- function_to_call(s1)
192
- except queue.Empty:
193
- pass
194
-
195
- if queue_was_processed:
196
- # immediately loop again
173
+ try:
174
+ s1 = control_receiver_results_queue.get_nowait()
175
+ except queue.Empty:
176
+ s1 = None
177
+
178
+ if s1:
179
+ output.print_output(s1)
197
180
  continue
198
181
 
199
182
  if util.threads_are_running(thread_list):
200
183
  # nothing in queues, but test is still running
201
184
  time.sleep(0.01)
202
185
  continue
203
-
204
- # exit program
205
- break
186
+ else:
187
+ break
206
188
 
207
189
  output.term()
208
190
 
209
191
  util.done_with_socket(data_sock)
210
- control_conn.close()
192
+ util.done_with_socket(control_sock)
211
193
 
212
194
  graphdatafilename = output.get_graph_data_file_name()
213
195
  rawdatafilename = output.get_raw_data_file_name()
214
196
 
215
197
  if args.graph and not args.quiet:
216
198
  graph.create_graph(args, graphdatafilename)
217
- print("created graph: {}".format(graphdatafilename + ".png"))
199
+ print("created graph: {}".format(graphdatafilename + ".png"), flush=True)
218
200
 
219
201
  if args.keep and not args.quiet:
220
- print("keeping graph data file: {}".format(graphdatafilename))
221
- print("keeping raw data file: {}".format(rawdatafilename))
202
+ print("keeping graph data file: {}".format(graphdatafilename), flush=True)
203
+ print("keeping raw data file: {}".format(rawdatafilename), flush=True)
222
204
  else:
223
205
  output.delete_data_files()
@@ -20,8 +20,6 @@ BUFSZ = 4096
20
20
  PAYLOAD_1K = b'a'*1024
21
21
  PAYLOAD_4K = b'a'*4096
22
22
 
23
- SOFT_SECRET = "ZZ32gkogidrueowiruvnmxn432874ZZ"
24
-
25
23
  RUN_MODE_CALIBRATING = 1
26
24
  RUN_MODE_RUNNING = 2
27
25
  RUN_MODE_STOP = 3
@@ -32,9 +30,9 @@ STDOUT_INTERVAL_SEC = 1
32
30
  RATE_LIMITED_BATCH_SIZE_PKTS_UDP_PKTS = 20
33
31
  RATE_LIMITED_BATCH_SIZE_PKTS_TCP_PKTS = 5
34
32
 
33
+ SETUP_COMPLETE_MSG = "setup complete"
35
34
  START_MSG = " start "
36
35
  UDP_STOP_MSG = "stop"
37
- UDP_PING_MSG = "ping"
38
36
 
39
37
  SOCKET_TIMEOUT_SEC=20
40
38
 
@@ -12,9 +12,9 @@ from .run_mode_manager_class import RunModeManagerClass
12
12
  # direction up, runs on client
13
13
  # args are client args (not server args)
14
14
  # falling off the end of this method terminates the process
15
- def run_recv_term_queue(args, stdout_queue, control_conn, results_queue, shared_run_mode, shared_udp_sending_rate_pps):
15
+ def run_recv_term_queue(args, control_conn, results_queue, shared_run_mode, shared_udp_sending_rate_pps):
16
16
  if args.verbosity:
17
- stdout_queue.put("starting control receiver process: run_recv_term_queue")
17
+ print("starting control receiver process: run_recv_term_queue", flush=True)
18
18
 
19
19
  run_mode_manager = RunModeManagerClass(args, shared_run_mode)
20
20
  udp_rate_manager = UdpRateManagerClass(args, shared_udp_sending_rate_pps)
@@ -27,13 +27,13 @@ def run_recv_term_queue(args, stdout_queue, control_conn, results_queue, shared_
27
27
 
28
28
  except ConnectionResetError:
29
29
  if args.verbosity:
30
- stdout_queue.put("connection reset error")
30
+ print("connection reset error", flush=True)
31
31
  # exit process
32
32
  break
33
33
 
34
34
  except PeerDisconnectedException:
35
35
  if args.verbosity:
36
- stdout_queue.put("peer disconnected (control socket)")
36
+ print("peer disconnected (control socket)", flush=True)
37
37
  # exit process
38
38
  break
39
39
 
@@ -63,20 +63,20 @@ def run_recv_term_queue(args, stdout_queue, control_conn, results_queue, shared_
63
63
  results_queue.put(new_str)
64
64
 
65
65
  if args.verbosity > 1:
66
- stdout_queue.put("control receiver process: created: {}".format(new_str))
66
+ print("control receiver process: {}".format(new_str), flush=True)
67
67
 
68
68
  control_conn.close()
69
69
 
70
70
  if args.verbosity:
71
- stdout_queue.put("exiting control receiver process: run_recv_term_queue")
71
+ print("exiting control receiver process: run_recv_term_queue", flush=True)
72
72
 
73
73
 
74
74
  # direction down, runs on server
75
75
  # args are client args (not server args)
76
76
  # falling off the end of this method terminates the process
77
- def run_recv_term_send(args, stdout_queue, control_conn, shared_run_mode, shared_udp_sending_rate_pps):
77
+ def run_recv_term_send(args, control_conn, shared_run_mode, shared_udp_sending_rate_pps):
78
78
  if args.verbosity:
79
- stdout_queue.put("starting control receiver process: run_recv_term_send")
79
+ print("starting control receiver process: run_recv_term_send", flush=True)
80
80
 
81
81
  run_mode_manager = RunModeManagerClass(args, shared_run_mode)
82
82
  udp_rate_manager = UdpRateManagerClass(args, shared_udp_sending_rate_pps)
@@ -89,13 +89,13 @@ def run_recv_term_send(args, stdout_queue, control_conn, shared_run_mode, shared
89
89
 
90
90
  except ConnectionResetError:
91
91
  if args.verbosity:
92
- stdout_queue.put("connection reset error")
92
+ print("connection reset error", flush=True)
93
93
  # exit process
94
94
  break
95
95
 
96
96
  except PeerDisconnectedException:
97
97
  if args.verbosity:
98
- stdout_queue.put("peer disconnected (control socket)")
98
+ print("peer disconnected (control socket)", flush=True)
99
99
  # exit process
100
100
  break
101
101
 
@@ -125,21 +125,21 @@ def run_recv_term_send(args, stdout_queue, control_conn, shared_run_mode, shared
125
125
  control_conn.send(new_str.encode())
126
126
 
127
127
  if args.verbosity > 1:
128
- stdout_queue.put("control receiver process: created: {}".format(new_str))
128
+ print("control receiver process: {}".format(new_str), flush=True)
129
129
 
130
130
 
131
131
  control_conn.close()
132
132
 
133
133
  if args.verbosity:
134
- stdout_queue.put("exiting control receiver process: run_recv_term_send")
134
+ print("exiting control receiver process: run_recv_term_send", flush=True)
135
135
 
136
136
 
137
137
  # direction down, runs on client (passthru)
138
138
  # args are client args (not server args) -- this always runs on client
139
139
  # falling off the end of this method terminates the process
140
- def run_recv_queue(args, stdout_queue, control_conn, results_queue):
140
+ def run_recv_queue(args, control_conn, results_queue):
141
141
  if args.verbosity:
142
- stdout_queue.put("starting control receiver process: run_recv_queue")
142
+ print("starting control receiver process: run_recv_queue", flush=True)
143
143
 
144
144
  while True:
145
145
  try:
@@ -148,13 +148,13 @@ def run_recv_queue(args, stdout_queue, control_conn, results_queue):
148
148
 
149
149
  except ConnectionResetError:
150
150
  if args.verbosity:
151
- stdout_queue.put("connection reset error")
151
+ print("connection reset error", flush=True)
152
152
  # exit process
153
153
  break
154
154
 
155
155
  except PeerDisconnectedException:
156
156
  if args.verbosity:
157
- stdout_queue.put("peer disconnected (control socket)")
157
+ print("peer disconnected (control socket)", flush=True)
158
158
  # exit process
159
159
  break
160
160
 
@@ -166,4 +166,4 @@ def run_recv_queue(args, stdout_queue, control_conn, results_queue):
166
166
  control_conn.close()
167
167
 
168
168
  if args.verbosity:
169
- stdout_queue.put("exiting control receiver process: run_recv_queue")
169
+ print("exiting control receiver process: run_recv_queue", flush=True)
@@ -8,17 +8,15 @@ from . import const
8
8
  from . import util
9
9
 
10
10
  # args are client args
11
- def run(args, stdout_queue, control_conn, data_sock, peer_addr):
11
+ def run(args, control_conn, data_sock):
12
12
 
13
13
  if args.verbosity:
14
- stdout_queue.put("starting data receiver process")
14
+ print("starting data receiver process", flush=True)
15
15
 
16
16
  # do not block on the below recv calls as we want to exit the process when
17
17
  # the "end of run" timer expires even if the flow of packets has stopped
18
18
  data_sock.settimeout(0.05)
19
19
 
20
- peer_addr_for_udp = peer_addr
21
-
22
20
  total_recv_calls = 0
23
21
 
24
22
  interval_start_time = time.time()
@@ -33,39 +31,21 @@ def run(args, stdout_queue, control_conn, data_sock, peer_addr):
33
31
  # do until end of test duration
34
32
  # we will not get a connection close with udp
35
33
  while True:
34
+ num_bytes_read = 0
36
35
 
37
36
  try:
38
- num_bytes_read = 0
39
- if args.udp:
40
- # recv with timeout
41
- bytes_read, pkt_from_addr = data_sock.recvfrom(const.BUFSZ)
42
-
43
- # validate peer address
44
- # all subsequent packets should come from the same addr as the first one
45
- if pkt_from_addr != peer_addr_for_udp:
46
- if peer_addr_for_udp is None:
47
- # first packet is received
48
- peer_addr_for_udp = pkt_from_addr
49
- if not args.quiet:
50
- print("peer address: {}".format(peer_addr_for_udp))
51
- else:
52
- raise Exception("ERROR: datagram from wrong peer address")
53
-
54
- num_bytes_read = len(bytes_read)
55
-
56
- else:
57
- # tcp
58
- # recv with timeout
59
- bytes_read = data_sock.recv(const.BUFSZ)
37
+ # works for both tcp and udp
38
+ # recv with timeout
39
+ bytes_read = data_sock.recv(const.BUFSZ)
60
40
 
61
- num_bytes_read = len(bytes_read)
41
+ num_bytes_read = len(bytes_read)
62
42
 
63
- if num_bytes_read == 0:
64
- # peer has disconnected
65
- if args.verbosity:
66
- stdout_queue.put("peer disconnected (data socket)")
67
- # exit process
68
- break
43
+ if num_bytes_read == 0:
44
+ # (tcp only) peer has disconnected
45
+ if args.verbosity:
46
+ print("peer disconnected (data socket)", flush=True)
47
+ # exit process
48
+ break
69
49
 
70
50
  socket_timeout_timer_active = False
71
51
 
@@ -79,7 +59,7 @@ def run(args, stdout_queue, control_conn, data_sock, peer_addr):
79
59
 
80
60
  if args.udp and num_bytes_read == len(const.UDP_STOP_MSG) and (bytes_read.decode() == const.UDP_STOP_MSG):
81
61
  if args.verbosity:
82
- stdout_queue.put("data receiver thread: received udp stop message, exiting")
62
+ print("data receiver thread: received udp stop message, exiting", flush=True)
83
63
  break
84
64
 
85
65
  if num_bytes_read == 0:
@@ -129,7 +109,7 @@ def run(args, stdout_queue, control_conn, data_sock, peer_addr):
129
109
  control_conn.send(ba)
130
110
 
131
111
  except Exception:
132
- stdout_queue.put("ERROR: send on control socket failed 2")
112
+ print("ERROR: send on control socket failed", flush=True)
133
113
  # exit process
134
114
  break
135
115
 
@@ -145,4 +125,4 @@ def run(args, stdout_queue, control_conn, data_sock, peer_addr):
145
125
  control_conn.close()
146
126
 
147
127
  if args.verbosity:
148
- stdout_queue.put("exiting data receiver process")
128
+ print("exiting data receiver process", flush=True)