Skip to content

Commit

Permalink
Merge pull request #26 from sgaisser/gaisser_example
Browse files Browse the repository at this point in the history
Potential double read of packet
  • Loading branch information
robamu authored Nov 27, 2024
2 parents 93cac52 + 5b68872 commit f8f05b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 5 additions & 8 deletions examples/cfdp-simple/file-copy-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,18 @@ def source_entity_handler(transfer_params: TransferParams, source_handler: Sourc
trans_mode=transfer_params.transmission_mode,
closure_requested=not transfer_params.no_closure,
)
packet_received = False
print(f"SRC HANDLER: Inserting Put Request: {put_request}")
with open(SOURCE_FILE) as file:
file_content = file.read()
print(f"File content of source file {SOURCE_FILE}: {file_content}")
assert source_handler.put_request(put_request)
packet = None

while True:
packet = None
try:
# We are getting the packets from a Queue here, they could for example also be polled
# from a network.
packet = DEST_TO_SOURCE_QUEUE.get(False)
packet_received = True
except Empty:
pass
fsm_result = source_handler.state_machine(packet)
Expand All @@ -332,7 +331,7 @@ def source_entity_handler(transfer_params: TransferParams, source_handler: Sourc
SOURCE_TO_DEST_QUEUE.put(next_pdu_wrapper.pdu)
packet_sent = True
# If there is no work to do, put the thread to sleep.
if not packet_received and not packet_sent:
if packet is None and not packet_sent:
time.sleep(0.5)
# Transaction done
if fsm_result.states.state == CfdpState.IDLE:
Expand All @@ -342,12 +341,10 @@ def source_entity_handler(transfer_params: TransferParams, source_handler: Sourc

def dest_entity_handler(transfer_params: TransferParams, dest_handler: DestHandler) -> None:
first_packet = True
packet_received = False
packet = None
while True:
packet = None
try:
packet = SOURCE_TO_DEST_QUEUE.get(False)
packet_received = True
if first_packet:
first_packet = False
except Empty:
Expand All @@ -363,7 +360,7 @@ def dest_entity_handler(transfer_params: TransferParams, dest_handler: DestHandl
DEST_TO_SOURCE_QUEUE.put(next_pdu_wrapper.pdu)
packet_sent = True
# If there is no work to do, put the thread to sleep.
if not packet_received and not packet_sent:
if packet is None and not packet_sent:
time.sleep(0.5)
# Transaction done
if not first_packet and fsm_result.states.state == CfdpState.IDLE:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ ignore = [
"S101", # Use of assert, should be changed in the future
"ANN204", # Do not use return typing on __init__, __new__ and __call__ methods
"E111", # Recommended to be disabled when using the ruff formatter
"E114" # Recommended to be disabled when using the ruff formatter
"E114", # Recommended to be disabled when using the ruff formatter
"SIM105" # Suppress exceptions which is more readable but much slower
]

[tool.ruff.lint.extend-per-file-ignores]
Expand Down

0 comments on commit f8f05b6

Please sign in to comment.