fprime/Drv/Ip/TcpClientSocket.hpp
Thomas Boyer-Chammard 6915c93c10
Update Drv IP stack to use FwSizeType instead of U32 (#4013)
* Update IP stack source to use SizeType instead of I/U32

* Update UTs reflecting U32/I32 change to SizeType

* Static cast sizes per review

* Fix commented out thing
2025-08-21 08:55:17 -07:00

76 lines
2.9 KiB
C++

// ======================================================================
// \title TcpClientSocket.hpp
// \author mstarch
// \brief cpp file for TcpClientSocket core implementation classes
//
// \copyright
// Copyright 2009-2020, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#ifndef DRV_TCPCLIENT_TCPHELPER_HPP_
#define DRV_TCPCLIENT_TCPHELPER_HPP_
#include <Drv/Ip/IpSocket.hpp>
#include <Fw/FPrimeBasicTypes.hpp>
#include <config/IpCfg.hpp>
namespace Drv {
/**
* \brief Helper for setting up Tcp using Berkeley sockets as a client
*
* Certain IP headers have conflicting definitions with the m_data member of various types in fprime. TcpClientSocket
* separates the ip setup from the incoming Fw::Buffer in the primary component class preventing this collision.
*/
class TcpClientSocket : public IpSocket {
public:
/**
* \brief Constructor for client socket tcp implementation
*/
TcpClientSocket();
protected:
/**
* \brief Check if the given port is valid for the socket
*
* Some ports should be allowed for sockets and disabled on others (e.g. port 0 is a valid tcp server port but not a
* client. This will check the port and return "true" if the port is valid, or "false" otherwise. In the tcp client
* implementation, all ports are considered valid except for "0".
*
* \param port: port to check
* \return true if valid, false otherwise
*/
bool isValidPort(U16 port) override;
/**
* \brief Tcp specific implementation for opening a client socket.
* \param socketDescriptor: (output) descriptor opened. Only valid on SOCK_SUCCESS. Otherwise will be invalid
* \return status of open
*/
SocketIpStatus openProtocol(SocketDescriptor& socketDescriptor) override;
/**
* \brief Protocol specific implementation of send. Called directly with retry from send.
* \param socketDescriptor: descriptor to send to
* \param data: data to send
* \param size: size of data to send
* \return: size of data sent, or -1 on error.
*/
FwSignedSizeType sendProtocol(const SocketDescriptor& socketDescriptor,
const U8* const data,
const FwSizeType size) override;
/**
* \brief Protocol specific implementation of recv. Called directly with error handling from recv.
* \param socketDescriptor: descriptor to recv from
* \param data: data pointer to fill
* \param size: size of data buffer
* \return: size of data received, or -1 on error.
*/
FwSignedSizeType recvProtocol(const SocketDescriptor& socketDescriptor,
U8* const data,
const FwSizeType size) override;
};
} // namespace Drv
#endif /* DRV_TCPCLIENT_TCPHELPER_HPP_ */