Skip to content

Commit

Permalink
optimize impl, improve names
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Jul 18, 2024
1 parent 700e7bc commit 60d0582
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/cfdppy/handler/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TransactionStep(enum.Enum):
@dataclass
class _SourceFileParams(_FileParamsBase):
# This flag accounts for the empty file case where an EOF still needs to be sent.
no_eof: bool = False
empty_file: bool = False

@classmethod
def empty(cls) -> _SourceFileParams:
Expand All @@ -102,11 +102,12 @@ def empty(cls) -> _SourceFileParams:
segment_len=0,
crc32=bytes(),
file_size=0,
no_eof=False,
empty_file=False,
metadata_only=False,
)

def reset(self):
self.empty_file = False
super().reset()


Expand Down Expand Up @@ -571,15 +572,14 @@ def _prepare_file_params(self):
assert self._put_req is not None
if self._put_req.metadata_only:
self._params.fp.metadata_only = True
self._params.fp.no_eof = True
else:
assert self._put_req.source_file is not None
if not self._put_req.source_file.exists():
# TODO: Handle this exception in the handler, reset CFDP state machine
raise SourceFileDoesNotExist(self._put_req.source_file)
file_size = self.user.vfs.file_size(self._put_req.source_file)
if file_size == 0:
self._params.fp.metadata_only = True
self._params.fp.empty_file = True
else:
self._params.fp.file_size = file_size

Expand Down Expand Up @@ -686,16 +686,16 @@ def _sending_file_data_fsm(self) -> bool:
self._prepare_progressing_file_data_pdu()
# Not finished yet. We exit here to allow the user to do flow control.
return True
# Special case: Metadata Only, no EOF required.
if self._params.fp.no_eof:
if self._params.fp.empty_file:
# Special case: Empty file, EOF still required.
self._params.cond_code_eof = ConditionCode.NO_ERROR
self.states.step = TransactionStep.SENDING_EOF
elif self._params.fp.metadata_only:
# Special case: Metadata Only, no EOF required.
if self._params.closure_requested:
self.states.step = TransactionStep.WAITING_FOR_FINISHED
else:
self.states.step = TransactionStep.NOTICE_OF_COMPLETION
else:
# Special case: Empty file, EOF still required.
self._params.cond_code_eof = ConditionCode.NO_ERROR
self.states.step = TransactionStep.SENDING_EOF
return False

def __handle_retransmission(self) -> bool:
Expand Down

0 comments on commit 60d0582

Please sign in to comment.