F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Drv::TcpServerSocket Class Reference

Helper for setting up Tcp using Berkeley sockets as a server. More...

#include <Drv/Ip/TcpServerSocket.hpp>

Inheritance diagram for Drv::TcpServerSocket:
Drv::IpSocket

Public Member Functions

 TcpServerSocket ()
 Constructor for client socket tcp implementation. More...
 
SocketIpStatus startup () override
 Opens the server socket and listens, does not block. More...
 
void shutdown () override
 Shutdown and close the server socket followed by the open client. More...
 
U16 getListenPort ()
 get the port being listened on More...
 
- Public Member Functions inherited from Drv::IpSocket
 IpSocket ()
 
virtual ~IpSocket ()
 
SocketIpStatus configure (const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
 configure the ip socket with host and transmission timeouts More...
 
bool isStarted ()
 Returns true when the socket is started. More...
 
bool isOpened ()
 check if IP socket has previously been opened More...
 
SocketIpStatus open ()
 open the IP socket for communications More...
 
SocketIpStatus send (const U8 *const data, const U32 size)
 send data out the IP socket from the given buffer More...
 
SocketIpStatus recv (U8 *const data, U32 &size)
 receive data from the IP socket from the given buffer More...
 
void close ()
 closes the socket More...
 

Protected Member Functions

SocketIpStatus openProtocol (NATIVE_INT_TYPE &fd) override
 Tcp specific implementation for opening a client socket connected to this server. More...
 
I32 sendProtocol (const U8 *const data, const U32 size) override
 Protocol specific implementation of send. Called directly with retry from send. More...
 
I32 recvProtocol (U8 *const data, const U32 size) override
 Protocol specific implementation of recv. Called directly with error handling from recv. More...
 
- Protected Member Functions inherited from Drv::IpSocket
virtual bool isValidPort (U16 port)
 Check if the given port is valid for the socket. More...
 
SocketIpStatus setupTimeouts (NATIVE_INT_TYPE socketFd)
 setup the socket timeout properties of the opened outgoing socket More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from Drv::IpSocket
static SocketIpStatus addressToIp4 (const char *address, void *ip4)
 converts a given address in dot form x.x.x.x to an ip address. ONLY works for IPv4. More...
 
- Protected Attributes inherited from Drv::IpSocket
Os::Mutex m_lock
 
NATIVE_INT_TYPE m_fd
 
U32 m_timeoutSeconds
 
U32 m_timeoutMicroseconds
 
U16 m_port
 IP address port used. More...
 
bool m_open
 Have we successfully opened. More...
 
bool m_started
 Have we successfully started the socket. More...
 
char m_hostname [SOCKET_MAX_HOSTNAME_SIZE]
 Hostname to supply. More...
 

Detailed Description

Helper for setting up Tcp using Berkeley sockets as a server.

Certain IP headers have conflicting definitions with the m_data member of various types in fprime. TcpServerSocket separates the ip setup from the incoming Fw::Buffer in the primary component class preventing this collision.

Definition at line 26 of file TcpServerSocket.hpp.

Constructor & Destructor Documentation

◆ TcpServerSocket()

Drv::TcpServerSocket::TcpServerSocket ( )

Constructor for client socket tcp implementation.

Definition at line 41 of file TcpServerSocket.cpp.

Member Function Documentation

◆ getListenPort()

U16 Drv::TcpServerSocket::getListenPort ( )

get the port being listened on

Most useful when listen was configured to use port "0", this will return the port used for listening after a port has been determined. Will return 0 if the connection has not been setup.

Returns
receive port

Definition at line 43 of file TcpServerSocket.cpp.

◆ openProtocol()

SocketIpStatus Drv::TcpServerSocket::openProtocol ( NATIVE_INT_TYPE fd)
overrideprotectedvirtual

Tcp specific implementation for opening a client socket connected to this server.

Parameters
fd(output) file descriptor opened. Only valid on SOCK_SUCCESS. Otherwise will be invalid
Returns
status of open

Implements Drv::IpSocket.

Definition at line 112 of file TcpServerSocket.cpp.

◆ recvProtocol()

I32 Drv::TcpServerSocket::recvProtocol ( U8 *const  data,
const U32  size 
)
overrideprotectedvirtual

Protocol specific implementation of recv. Called directly with error handling from recv.

Parameters
datadata pointer to fill
sizesize of data buffer
Returns
: size of data received, or -1 on error.

Implements Drv::IpSocket.

Definition at line 145 of file TcpServerSocket.cpp.

◆ sendProtocol()

I32 Drv::TcpServerSocket::sendProtocol ( const U8 *const  data,
const U32  size 
)
overrideprotectedvirtual

Protocol specific implementation of send. Called directly with retry from send.

Parameters
datadata to send
sizesize of data to send
Returns
: size of data sent, or -1 on error.

Implements Drv::IpSocket.

Definition at line 141 of file TcpServerSocket.cpp.

◆ shutdown()

void Drv::TcpServerSocket::shutdown ( )
overridevirtual

Shutdown and close the server socket followed by the open client.

First, this calls shutdown and close on the server socket and then calls the close method to shutdown and close the client.

Reimplemented from Drv::IpSocket.

Definition at line 101 of file TcpServerSocket.cpp.

◆ startup()

SocketIpStatus Drv::TcpServerSocket::startup ( )
overridevirtual

Opens the server socket and listens, does not block.

Opens the server's listening socket such that this server can listen for incoming client requests. Given the nature of this component, only one (1) client can be handled at a time. After this call succeeds, clients may connect. This call does not block, block occurs on open while waiting to accept incoming clients.

Returns
status of the server socket setup.

Reimplemented from Drv::IpSocket.

Definition at line 50 of file TcpServerSocket.cpp.


The documentation for this class was generated from the following files: