Skip to content

Commit

Permalink
#2074 Parameterize buffer size in UDP and TCP Server. (#2998)
Browse files Browse the repository at this point in the history
* #2074 Parameterize buffer size in UDP and TCP Server.

* Fixing m_allocate pssing

* Fixing cast

---------

Co-authored-by: bdshenker <[email protected]>
Co-authored-by: M Starch <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent f63b511 commit 0acc49c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
12 changes: 10 additions & 2 deletions Drv/TcpServer/TcpServerComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
// ======================================================================

#include <limits>
#include <Drv/TcpServer/TcpServerComponentImpl.hpp>
#include <FpConfig.hpp>
#include "Fw/Types/Assert.hpp"
Expand All @@ -27,7 +28,14 @@ TcpServerComponentImpl::TcpServerComponentImpl(const char* const compName)
SocketIpStatus TcpServerComponentImpl::configure(const char* hostname,
const U16 port,
const U32 send_timeout_seconds,
const U32 send_timeout_microseconds) {
const U32 send_timeout_microseconds,
FwSizeType buffer_size) {

// Check that ensures the configured buffer size fits within the limits fixed-width type, U32

FW_ASSERT(buffer_size <= std::numeric_limits<U32>::max(), static_cast<FwAssertArgType>(buffer_size));
m_allocation_size = buffer_size; // Store the buffer size
//
(void)m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
return startup();
}
Expand All @@ -47,7 +55,7 @@ IpSocket& TcpServerComponentImpl::getSocketHandler() {
}

Fw::Buffer TcpServerComponentImpl::getBuffer() {
return allocate_out(0, 1024);
return allocate_out(0, static_cast<U32>(m_allocation_size));
}

void TcpServerComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) {
Expand Down
6 changes: 5 additions & 1 deletion Drv/TcpServer/TcpServerComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ class TcpServerComponentImpl : public TcpServerComponentBase, public SocketCompo
* \param send_timeout_seconds: send timeout seconds component. Defaults to: SOCKET_TIMEOUT_SECONDS
* \param send_timeout_microseconds: send timeout microseconds component. Must be less than 1000000. Defaults to:
* SOCKET_TIMEOUT_MICROSECONDS
* \param buffer_size: size of the buffer to be allocated. Defaults to 1024.
* \return status of the configure
*/
SocketIpStatus configure(const char* hostname,
const U16 port,
const U32 send_timeout_seconds = SOCKET_SEND_TIMEOUT_SECONDS,
const U32 send_timeout_microseconds = SOCKET_SEND_TIMEOUT_MICROSECONDS);
const U32 send_timeout_microseconds = SOCKET_SEND_TIMEOUT_MICROSECONDS,
FwSizeType buffer_size = 1024);

/**
* \brief is started
Expand Down Expand Up @@ -161,6 +163,8 @@ class TcpServerComponentImpl : public TcpServerComponentBase, public SocketCompo
Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) override;

Drv::TcpServerSocket m_socket; //!< Socket implementation

FwSizeType m_allocation_size; //!< Member variable to store the buffer size
};

} // end namespace Drv
Expand Down
8 changes: 6 additions & 2 deletions Drv/Udp/UdpComponentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
// ======================================================================

#include <limits>
#include <Drv/Udp/UdpComponentImpl.hpp>
#include <IpCfg.hpp>
#include <FpConfig.hpp>
Expand All @@ -32,7 +33,10 @@ SocketIpStatus UdpComponentImpl::configureSend(const char* hostname,
return m_socket.configureSend(hostname, port, send_timeout_seconds, send_timeout_microseconds);
}

SocketIpStatus UdpComponentImpl::configureRecv(const char* hostname, const U16 port) {
SocketIpStatus UdpComponentImpl::configureRecv(const char* hostname, const U16 port, FwSizeType buffer_size) {
FW_ASSERT(buffer_size <= std::numeric_limits<U32>::max(), static_cast<FwAssertArgType>(buffer_size));
m_allocation_size = buffer_size; // Store the buffer size

return m_socket.configureRecv(hostname, port);
}

Expand All @@ -51,7 +55,7 @@ IpSocket& UdpComponentImpl::getSocketHandler() {
}

Fw::Buffer UdpComponentImpl::getBuffer() {
return allocate_out(0, 1024);
return allocate_out(0, static_cast<U32>(m_allocation_size));
}

void UdpComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) {
Expand Down
6 changes: 5 additions & 1 deletion Drv/Udp/UdpComponentImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ class UdpComponentImpl : public UdpComponentBase, public SocketComponentHelper {
*
* \param hostname: ip address of remote tcp server in the form x.x.x.x
* \param port: port of remote tcp server
* \param buffer_size: size of the buffer to be allocated. Defaults to 1024.
* \return status of the configure
*/
SocketIpStatus configureRecv(const char* hostname, const U16 port);
SocketIpStatus configureRecv(const char* hostname, const U16 port, FwSizeType buffer_size = 1024);

/**
* \brief get the port being received on
Expand Down Expand Up @@ -147,7 +148,10 @@ class UdpComponentImpl : public UdpComponentBase, public SocketComponentHelper {
* \return SEND_OK on success, SEND_RETRY when critical data should be retried and SEND_ERROR upon error
*/
Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer);

Drv::UdpSocket m_socket; //!< Socket implementation

FwSizeType m_allocation_size; //!< Member variable to store the buffer size
};

} // end namespace Drv
Expand Down

0 comments on commit 0acc49c

Please sign in to comment.