1.2.3.1.23 TCPIP_TCP_FifoSizeAdjust Function

C

bool TCPIP_TCP_FifoSizeAdjust(
    TCP_SOCKET hTCP, 
    uint16_t wMinRXSize, 
    uint16_t wMinTXSize, 
    TCP_ADJUST_FLAGS vFlags
);

Description

This function can be used to simultaneously adjust the sizes of the RX and TX FIFOs.

Adjusting the size of the TX/RX FIFO on the fly can allow for optimal transmission speed for one-sided application protocols. For example, HTTP typically begins by receiving large amounts of data from the client, then switches to serving large amounts of data back. Adjusting the FIFO at these points can increase performance in systems that have limited resources. Once the FIFOs are adjusted, a window update is sent.

Although the TX and RX socket buffers are completely independent, for the purpose of this function they can be considered together if neither TCP_ADJUST_TX_ONLY nor TCP_ADJUST_RX_ONLY flags are set.

In these conditions the TCP_ADJUST_FLAGS control the distribution of the available space between the TX and RX FIFOs. If neither or both of TCP_ADJUST_GIVE_REST_TO_TX and TCP_ADJUST_GIVE_REST_TO_RX are set, the function distributes the remaining space (if any) equally. If the new requested FIFOs space is greater that the old existing FIFOs space the TCP_ADJUST_GIVE_REST_TO_TX and TCP_ADJUST_GIVE_REST_TO_RX are ignored.

TCP_ADJUST_PRESERVE_RX and TCP_ADJUST_PRESERVE_TX request the preserving of the existing data. Existing data can be preserved as long as the old data in the buffer does not exceed the capacity of the new buffer.

Preconditions

TCP is initialized.

Parameters

ParametersDescription
hTCPThe socket to be adjusted.
wMinRXSizeMinimum number of bytes for the RX FIFO.
wMinTXSizeMinimum number of bytes for the TX FIFO.
vFlagsIf TCP_ADJUST_TX_ONLY or TCP_ADJUST_RX_ONLY are not set, the TX and RX buffers are evaluated together and any combination of the following flags is valid: - TCP_ADJUST_GIVE_REST_TO_RX, TCP_ADJUST_GIVE_REST_TO_TX - TCP_ADJUST_PRESERVE_RX, TCP_ADJUST_PRESERVE_TX- If TCP_ADJUST_TX_ONLY or TCP_ADJUST_RX_ONLY is set TX and RX buffers are treated individually and TCP_ADJUST_GIVE_REST_TO_TX, TCP_ADJUST_GIVE_REST_TO_RX values are irrelevant.- TCP_ADJUST_TX_ONLY and TCP_ADJUST_RX_ONLY both set is invalid.

Remarks

The function will automatically maintain minimal values for both TX and RX buffers.

To avoid having a socket with no associated buffers, the function first allocates the new buffers and, if succeeded, it frees the old ones.

The TX and RX FIFOs (buffers) associated with a socket are completely separate and independent. However, when TCP_ADJUST_TX_ONLY or TCP_ADJUST_RX_ONLY are not set, for the purpose of this function, the TX and RX FIFOs are considered to be contiguous so that the total FIFO space is divided between the TX and RX FIFOs. This provides backward compatibility with previous versions of this function.

The new flags TCP_ADJUST_TX_ONLY and TCP_ADJUST_RX_ONLY allow changing the size of TX and RX buffers independently. This is the preferred option.

TX or RX associated buffer sizes can be changed too using the socket options. See TCPIP_TCP_OptionsSet.

The size of the buffers should NOT be decreased when the socket has pending data to be sent to the remote party or to be received by the socket user. Doing this may disrupt the communication, make the TCP algorithm fail or have an unpredicted behavior.