Skip to content

Commit

Permalink
Remove INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS (project-chip#13188)
Browse files Browse the repository at this point in the history
#### Problem

The option `INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS` is not
enabled by any configuration in tree, and clutters up TCP code.

Fixes project-chip#12939 INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS unused

#### Change overview

- Remove `INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS` and associated code

#### Testing

CI/build. No functional change since the option is unused.
  • Loading branch information
kpschoedel authored Dec 22, 2021
1 parent 58cf730 commit 92b9ef8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 167 deletions.
19 changes: 0 additions & 19 deletions src/inet/InetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,6 @@
#define INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT 1
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT

/**
* @def INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
*
* @brief
* When this flag is set, the InetLayer enables
* callbacks to the upper layer notifying it when
* the send channel of the TCP connection changes
* between being idle or not idle.
*
* @note
* When enabled, the TCP send queue is actively
* polled to determine if sent data has been
* acknowledged.
*
*/
#ifndef INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
#define INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS 0
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

/**
* @def INET_CONFIG_TCP_SEND_QUEUE_POLL_INTERVAL_MSEC
*
Expand Down
33 changes: 1 addition & 32 deletions src/inet/TCPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,40 +467,9 @@ void TCPEndPoint::ScheduleNextTCPUserTimeoutPoll(uint32_t aTimeOut)
GetSystemLayer().StartTimer(System::Clock::Milliseconds32(aTimeOut), TCPUserTimeoutHandler, this);
}

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
void TCPEndPoint::SetTCPSendIdleAndNotifyChange(bool aIsTCPSendIdle)
{
if (mIsTCPSendIdle != aIsTCPSendIdle)
{
ChipLogDetail(Inet, "TCP con send channel idle state changed : %s", aIsTCPSendIdle ? "false->true" : "true->false");

// Set the current Idle state
mIsTCPSendIdle = aIsTCPSendIdle;

if (OnTCPSendIdleChanged)
{
OnTCPSendIdleChanged(this, mIsTCPSendIdle);
}
}
}
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

void TCPEndPoint::StartTCPUserTimeoutTimer()
{
uint32_t timeOut = mUserTimeoutMillis;

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
// Set timeout to the poll interval

timeOut = mTCPSendQueuePollPeriodMillis;

// Reset the poll count

mTCPSendQueueRemainingPollCount = MaxTCPSendQueuePolls();
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

ScheduleNextTCPUserTimeoutPoll(timeOut);

ScheduleNextTCPUserTimeoutPoll(mUserTimeoutMillis);
mUserTimeoutTimerRunning = true;
}

Expand Down
60 changes: 2 additions & 58 deletions src/inet/TCPEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,28 +533,6 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
*/
OnAcceptErrorFunct OnAcceptError;

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
/**
* @brief Type of TCP SendIdle changed signal handling function.
*
* @param[in] endPoint The TCP endpoint associated with the event.
*
* @param[in] isIdle True if the send channel of the TCP endpoint
* is Idle, otherwise false.
* @details
* Provide a function of this type to the \c OnTCPSendIdleChanged delegate
* member to process the event of the send channel of the TCPEndPoint
* changing state between being idle and not idle.
*/
typedef void (*OnTCPSendIdleChangedFunct)(TCPEndPoint * endPoint, bool isIdle);

/** The event handling function delegate of the endpoint signaling when the
* idleness of the TCP connection's send channel changes. This is utilized
* by upper layers to take appropriate actions based on whether sent data
* has been reliably delivered to the peer. */
OnTCPSendIdleChangedFunct OnTCPSendIdleChanged;
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

/**
* Size of the largest TCP packet that can be received.
*/
Expand All @@ -571,13 +549,6 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
,
mUserTimeoutMillis(INET_CONFIG_DEFAULT_TCP_USER_TIMEOUT_MSEC), mUserTimeoutTimerRunning(false)
#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
,
mIsTCPSendIdle(true), mTCPSendQueuePollPeriodMillis(INET_CONFIG_TCP_SEND_QUEUE_POLL_INTERVAL_MSEC),
mTCPSendQueueRemainingPollCount(
MaxTCPSendQueuePolls(INET_CONFIG_DEFAULT_TCP_USER_TIMEOUT_MSEC, INET_CONFIG_TCP_SEND_QUEUE_POLL_INTERVAL_MSEC)),
OnTCPSendIdleChanged(nullptr)
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
{}

Expand Down Expand Up @@ -619,44 +590,17 @@ class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
// return an error; zero means use system defaults.

#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
uint32_t mUserTimeoutMillis; // The configured TCP user timeout value in milliseconds.
// If 0, assume not set.
#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
bool mIsTCPSendIdle; // Indicates whether the send channel of the TCPEndPoint is Idle.

uint16_t mTCPSendQueueRemainingPollCount; // The current remaining number of TCP SendQueue polls before
// the TCP User timeout period is reached.

uint32_t mTCPSendQueuePollPeriodMillis; // The configured period of active polling of the TCP
// SendQueue. If 0, assume not set.
void SetTCPSendIdleAndNotifyChange(bool aIsSendIdle);

#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

uint32_t mUserTimeoutMillis; // The configured TCP user timeout value in milliseconds.
// If 0, assume not set.
bool mUserTimeoutTimerRunning; // Indicates whether the TCP UserTimeout timer has been started.

static void TCPUserTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState);
virtual void TCPUserTimeoutHandler() = 0;

void StartTCPUserTimeoutTimer();

void StopTCPUserTimeoutTimer();

void RestartTCPUserTimeoutTimer();

void ScheduleNextTCPUserTimeoutPoll(uint32_t aTimeOut);

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
static constexpr uint16_t MaxTCPSendQueuePolls(uint16_t userTimeout, uint16_t pollPeriod)
{
// If the UserTimeout is configured less than or equal to the poll interval,
// return 1 to poll at least once instead of returning zero and timing out
// immediately.
return (userTimeout > pollPeriod) ? (userTimeout / pollPeriod) : 1;
}
uint16_t MaxTCPSendQueuePolls(void) { return MaxTCPSendQueuePolls(mUserTimeoutMillis, mTCPSendQueuePollPeriodMillis); }
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

#endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT

TCPEndPoint(const TCPEndPoint &) = delete;
Expand Down
7 changes: 0 additions & 7 deletions src/inet/TCPEndPointImplLwIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,7 @@ void TCPEndPointImplLwIP::HandleDataSent(uint16_t lenSent)
if (RemainingToSend() == 0)
{
// If the output queue has been flushed then stop the timer.

StopTCPUserTimeoutTimer();

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
// Notify up if all outstanding data has been acknowledged

SetTCPSendIdleAndNotifyChange(true);
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
}
else
{
Expand Down
55 changes: 4 additions & 51 deletions src/inet/TCPEndPointImplSockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,6 @@ CHIP_ERROR TCPEndPointImplSockets::DriveSendingImpl()
OnDataSent(this, lenSent);
}

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
// TCP Send is not Idle; Set state and notify if needed

SetTCPSendIdleAndNotifyChange(false);
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS

#if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
mBytesWrittenSinceLastProbe += lenSent;

Expand Down Expand Up @@ -675,27 +669,12 @@ void TCPEndPointImplSockets::TCPUserTimeoutHandler()
// Set the timer running flag to false
mUserTimeoutTimerRunning = false;

CHIP_ERROR err = CHIP_NO_ERROR;
bool isProgressing = false;
err = CheckConnectionProgress(isProgressing);
SuccessOrExit(err);
CHIP_ERROR err = CheckConnectionProgress(isProgressing);

if (mLastTCPKernelSendQueueLen == 0)
{
#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
// If the kernel TCP send queue as well as the TCPEndPoint
// send queue have been flushed then notify application
// that all data has been acknowledged.

if (mSendQueue.IsNull())
{
SetTCPSendIdleAndNotifyChange(true);
}
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
}
else
// There is data in the TCP Send Queue
if (err == CHIP_NO_ERROR && mLastTCPKernelSendQueueLen != 0)
{
// There is data in the TCP Send Queue
if (isProgressing)
{
// Data is flowing, so restart the UserTimeout timer
Expand All @@ -706,31 +685,14 @@ void TCPEndPointImplSockets::TCPUserTimeoutHandler()
}
else
{
#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
// Data flow is not progressing.
// Decrement the remaining max TCP send queue polls.

mTCPSendQueueRemainingPollCount--;

VerifyOrExit(mTCPSendQueueRemainingPollCount != 0, err = INET_ERROR_TCP_USER_TIMEOUT);

// Restart timer to poll again

ScheduleNextTCPUserTimeoutPoll(mTCPSendQueuePollPeriodMillis);
#else
// Close the connection as the TCP UserTimeout has expired

ExitNow(err = INET_ERROR_TCP_USER_TIMEOUT);
#endif // !INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
err = INET_ERROR_TCP_USER_TIMEOUT;
}
}

exit:

if (err != CHIP_NO_ERROR)
{
// Close the connection as the TCP UserTimeout has expired

DoClose(err, false);
}
}
Expand Down Expand Up @@ -963,15 +925,6 @@ void TCPEndPointImplSockets::ReceiveData()
// If the output queue has been flushed then stop the timer.

StopTCPUserTimeoutTimer();

#if INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
// Notify up if all outstanding data has been acknowledged

if (mSendQueue.IsNull())
{
SetTCPSendIdleAndNotifyChange(true);
}
#endif // INET_CONFIG_ENABLE_TCP_SEND_IDLE_CALLBACKS
}
else if (isProgressing && mUserTimeoutTimerRunning)
{
Expand Down

0 comments on commit 92b9ef8

Please sign in to comment.