Skip to content

Commit

Permalink
#2074 Parameterize buffer size in UDP and TCP Server.
Browse files Browse the repository at this point in the history
  • Loading branch information
bshenker committed Oct 29, 2024
1 parent 2c8d0db commit 7b702f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion 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 notice

Code scanning / CodeQL

Use of basic integral type Note

buffer_size uses the basic integral type unsigned long rather than a typedef with size and signedness.

// 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 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

Check notice

Code scanning / CodeQL

Use of basic integral type Note

m_allocation_size uses the basic integral type unsigned long rather than a typedef with size and signedness.
};

} // 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) {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

hostname uses the basic integral type char rather than a typedef with size and signedness.

Check notice

Code scanning / CodeQL

Use of basic integral type Note

buffer_size uses the basic integral type unsigned long rather than a typedef with size and signedness.
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

Check notice

Code scanning / CodeQL

Use of basic integral type Note

m_allocation_size uses the basic integral type unsigned long rather than a typedef with size and signedness.
};

} // end namespace Drv
Expand Down

0 comments on commit 7b702f2

Please sign in to comment.