F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
TcpServerComponentImpl.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title TcpServerComponentImpl.cpp
3 // \author mstarch
4 // \brief cpp file for TcpServerComponentImpl component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2020, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include <FpConfig.hpp>
15 #include "Fw/Types/Assert.hpp"
16 
17 namespace Drv {
18 
19 // ----------------------------------------------------------------------
20 // Construction, initialization, and destruction
21 // ----------------------------------------------------------------------
22 
24  : TcpServerComponentBase(compName),
25  SocketReadTask() {}
26 
28  const U16 port,
29  const U32 send_timeout_seconds,
30  const U32 send_timeout_microseconds) {
31  return m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
32 }
33 
35 
36 // ----------------------------------------------------------------------
37 // Implementations for socket read task virtual methods
38 // ----------------------------------------------------------------------
39 
41  return m_socket;
42 }
43 
45  return allocate_out(0, 1024);
46 }
47 
50  this->recv_out(0, buffer, recvStatus);
51 }
52 
55  this->ready_out(0);
56  }
57 
58 }
59 
60 // ----------------------------------------------------------------------
61 // Handler implementations for user-defined typed input ports
62 // ----------------------------------------------------------------------
63 
64 Drv::SendStatus TcpServerComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
65  Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
66  // Only deallocate buffer when the caller is not asked to retry
67  if (status == SOCK_INTERRUPTED_TRY_AGAIN) {
69  } else if (status != SOCK_SUCCESS) {
70  deallocate_out(0, fwBuffer);
72  }
73  deallocate_out(0, fwBuffer);
74  return SendStatus::SEND_OK;
75 }
76 
77 } // end namespace Drv
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
C++-compatible configuration header for fprime configuration.
Helper base-class for setting up Berkeley sockets.
Definition: IpSocket.hpp:46
SocketIpStatus send(const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
Definition: IpSocket.cpp:160
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
Definition: IpSocket.cpp:53
Status associated with the received data.
@ RECV_OK
Receive worked as expected.
@ RECV_ERROR
Receive error occurred retrying may succeed.
Status returned by the send call.
@ SEND_ERROR
Send error occurred retrying may succeed.
@ SEND_RETRY
Data send should be retried.
@ SEND_OK
Send worked as expected.
supports a task to read a given socket adaptation
Auto-generated base for TcpServer component.
bool isConnected_ready_OutputPort(NATIVE_INT_TYPE portNum)
void ready_out(NATIVE_INT_TYPE portNum)
Invoke output port ready.
Fw::Buffer allocate_out(NATIVE_INT_TYPE portNum, U32 size)
Invoke output port allocate.
void deallocate_out(NATIVE_INT_TYPE portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
void recv_out(NATIVE_INT_TYPE portNum, Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
Invoke output port recv.
~TcpServerComponentImpl()
Destroy the component.
Fw::Buffer getBuffer()
returns a buffer to fill with data
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)
sends a buffer to be filled with data
TcpServerComponentImpl(const char *const compName)
construct the TcpClient component.
IpSocket & getSocketHandler()
returns a reference to the socket handler
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)
Configures the TcpClient settings but does not open the connection.
void connected()
called when the IPv4 system has been connected
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:23
@ SOCK_SUCCESS
Socket operation successful.
Definition: IpSocket.hpp:24
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
Definition: IpSocket.hpp:30