Skip to content

Commit f8f05b6

Browse files
authored
Merge pull request #26 from sgaisser/gaisser_example
Potential double read of packet
2 parents 93cac52 + 5b68872 commit f8f05b6

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

examples/cfdp-simple/file-copy-example.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,19 +305,18 @@ def source_entity_handler(transfer_params: TransferParams, source_handler: Sourc
305305
trans_mode=transfer_params.transmission_mode,
306306
closure_requested=not transfer_params.no_closure,
307307
)
308-
packet_received = False
309308
print(f"SRC HANDLER: Inserting Put Request: {put_request}")
310309
with open(SOURCE_FILE) as file:
311310
file_content = file.read()
312311
print(f"File content of source file {SOURCE_FILE}: {file_content}")
313312
assert source_handler.put_request(put_request)
314-
packet = None
313+
315314
while True:
315+
packet = None
316316
try:
317317
# We are getting the packets from a Queue here, they could for example also be polled
318318
# from a network.
319319
packet = DEST_TO_SOURCE_QUEUE.get(False)
320-
packet_received = True
321320
except Empty:
322321
pass
323322
fsm_result = source_handler.state_machine(packet)
@@ -332,7 +331,7 @@ def source_entity_handler(transfer_params: TransferParams, source_handler: Sourc
332331
SOURCE_TO_DEST_QUEUE.put(next_pdu_wrapper.pdu)
333332
packet_sent = True
334333
# If there is no work to do, put the thread to sleep.
335-
if not packet_received and not packet_sent:
334+
if packet is None and not packet_sent:
336335
time.sleep(0.5)
337336
# Transaction done
338337
if fsm_result.states.state == CfdpState.IDLE:
@@ -342,12 +341,10 @@ def source_entity_handler(transfer_params: TransferParams, source_handler: Sourc
342341

343342
def dest_entity_handler(transfer_params: TransferParams, dest_handler: DestHandler) -> None:
344343
first_packet = True
345-
packet_received = False
346-
packet = None
347344
while True:
345+
packet = None
348346
try:
349347
packet = SOURCE_TO_DEST_QUEUE.get(False)
350-
packet_received = True
351348
if first_packet:
352349
first_packet = False
353350
except Empty:
@@ -363,7 +360,7 @@ def dest_entity_handler(transfer_params: TransferParams, dest_handler: DestHandl
363360
DEST_TO_SOURCE_QUEUE.put(next_pdu_wrapper.pdu)
364361
packet_sent = True
365362
# If there is no work to do, put the thread to sleep.
366-
if not packet_received and not packet_sent:
363+
if packet is None and not packet_sent:
367364
time.sleep(0.5)
368365
# Transaction done
369366
if not first_packet and fsm_result.states.state == CfdpState.IDLE:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ ignore = [
8585
"S101", # Use of assert, should be changed in the future
8686
"ANN204", # Do not use return typing on __init__, __new__ and __call__ methods
8787
"E111", # Recommended to be disabled when using the ruff formatter
88-
"E114" # Recommended to be disabled when using the ruff formatter
88+
"E114", # Recommended to be disabled when using the ruff formatter
89+
"SIM105" # Suppress exceptions which is more readable but much slower
8990
]
9091

9192
[tool.ruff.lint.extend-per-file-ignores]

0 commit comments

Comments
 (0)