Skip to content

Conversation

@htibosch
Copy link
Contributor

@htibosch htibosch commented Jul 27, 2021

Description

The module FreeRTOS+TCP_WIN.c had 4 functions with a high score on complexity. I cut down their size by moving some code the helper functions:

lTCPWindowRxCheck() score 66

  • prvTCPWindowRx_ExpectedRX()
  • prvTCPWindowRx_UnexpectedRX()

lTCPWindowTxAdd() score 35

  • prvTCPWindowTxAdd_FrontSegment()

ulTCPWindowTxGet() score 43

  • pxTCPWindowTx_GetWaitQueue()
  • pxTCPWindowTx_GetTXQueue()

prvTCPWindowTxCheckAck() score 25

  • prvTCPWindowTxCheckAck_CalcSRTT()

Test Steps

I tested by transferring files in both directions while dropping random packets in both directions.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@htibosch htibosch requested a review from a team as a code owner July 27, 2021 14:45
@htibosch htibosch changed the title Reduced complexity FreeRTOS_TCP_WIN IPv6/Multi: Reduced complexity FreeRTOS_TCP_WIN.c Jul 27, 2021
Comment on lines 1440 to 1451
/* if( ( ipconfigTCP_MAY_LOG_PORT( pxWindow->usOurPortNumber ) ) && */
/* ( ( xTCPWindowLoggingLevel >= 3 ) || */
/* ( ( xTCPWindowLoggingLevel >= 2 ) && ( pxWindow->pxHeadSegment != NULL ) ) ) ) */
/* { */
/* FreeRTOS_debug_printf( ( "lTCPWindowTxAdd: New %4ld bytes for seqNr %lu len %4lu (nxt %lu) pos %lu\n", */
/* ulLength, */
/* pxSegment->ulSequenceNumber - pxWindow->tx.ulFirstSequenceNumber, */
/* pxSegment->lDataLength, */
/* pxWindow->ulNextTxSequenceNumber - pxWindow->tx.ulFirstSequenceNumber, */
/* pxSegment->lStreamPos ) ); */
/* FreeRTOS_flush_logging(); */
/* } */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsed comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disabled the comment with double slashes, uncrustify replaced them by proper C comments /* */.
This is a very old logging statement, which increases the complexity of the function from 6 to 14.
As I haven't enabled any TCP_WIN logging for many years, I will take it away.

/* This out-of-sequence packet has been received for a
* second time. It is already stored but do send a SACK
* again. */
/* A negative value will be returned to indicate than error. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* A negative value will be returned to indicate than error. */
/* A negative value will be returned to indicate an error. */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done so, thanks.

@AniruddhaKanhere AniruddhaKanhere merged commit 2293047 into FreeRTOS:labs/ipv6_multi Aug 7, 2021
@htibosch htibosch deleted the IPv6/multi__complexity_FreeRTOS_TCP_WIN branch September 17, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants