F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
UdpSocket.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title UdpSocket.hpp
3 // \author mstarch
4 // \brief hpp file for UdpSocket core implementation classes
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 #ifndef DRV_IP_UDPSOCKET_HPP_
13 #define DRV_IP_UDPSOCKET_HPP_
14 
15 #include <Drv/Ip/IpSocket.hpp>
16 #include <Fw/FPrimeBasicTypes.hpp>
17 #include <config/IpCfg.hpp>
18 
19 // Include system headers for sockaddr_in
20 #ifdef TGT_OS_TYPE_VXWORKS
21 #include <inetLib.h>
22 #include <socket.h>
23 
24 // Undefine these Vxworks-defined macros because
25 // they collide with member variables in F Prime.
26 // These macros are defined somewhere in inetLib.h.
27 #undef m_type
28 #undef m_data
29 
30 #else
31 #include <arpa/inet.h>
32 #include <sys/socket.h>
33 #endif
34 
35 namespace Drv {
36 
43 class UdpSocket : public IpSocket {
44  public:
48  UdpSocket();
52  virtual ~UdpSocket();
53 
59  SocketIpStatus configure(const char* hostname,
60  const U16 port,
61  const U32 send_timeout_seconds,
62  const U32 send_timeout_microseconds) override;
63 
82  SocketIpStatus configureSend(const char* hostname,
83  const U16 port,
84  const U32 send_timeout_seconds,
85  const U32 send_timeout_microseconds);
86 
100  SocketIpStatus configureRecv(const char* hostname, const U16 port);
101 
110  U16 getRecvPort();
111 
119  SocketIpStatus send(const SocketDescriptor& socketDescriptor, const U8* const data, const FwSizeType size) override;
120 
121  protected:
127  SocketIpStatus bind(const int fd);
133  SocketIpStatus openProtocol(SocketDescriptor& socketDescriptor) override;
141  FwSignedSizeType sendProtocol(const SocketDescriptor& socketDescriptor,
142  const U8* const data,
143  const FwSizeType size) override;
151  FwSignedSizeType recvProtocol(const SocketDescriptor& socketDescriptor,
152  U8* const data,
153  const FwSizeType size) override;
162  SocketIpStatus handleZeroReturn() override;
163 
164  private:
165  struct sockaddr_in m_addr_send;
166  struct sockaddr_in m_addr_recv;
167  bool m_recv_configured;
168 };
169 } // namespace Drv
170 
171 #endif /* DRV_IP_UDPSOCKET_HPP_ */
U16 getRecvPort()
get the port being received on
Definition: UdpSocket.cpp:87
SocketIpStatus send(const SocketDescriptor &socketDescriptor, const U8 *const data, const FwSizeType size) override
UDP-specific implementation of send that handles zero-length datagrams correctly. ...
Definition: UdpSocket.cpp:236
PlatformSizeType FwSizeType
FwSignedSizeType sendProtocol(const SocketDescriptor &socketDescriptor, const U8 *const data, const FwSizeType size) override
Protocol specific implementation of send. Called directly with retry from send.
Definition: UdpSocket.cpp:200
PlatformSignedSizeType FwSignedSizeType
SocketIpStatus configureRecv(const char *hostname, const U16 port)
configure the udp socket for incoming transmissions
Definition: UdpSocket.cpp:67
virtual ~UdpSocket()
to cleanup state created at instantiation
Helper for setting up Udp using Berkeley sockets as a client.
Definition: UdpSocket.hpp:43
UdpSocket()
Constructor for client socket udp implementation.
Definition: UdpSocket.cpp:42
SocketIpStatus bind(const int fd)
bind the UDP to a port such that it can receive packets at the previously configured port ...
Definition: UdpSocket.cpp:91
FwSignedSizeType recvProtocol(const SocketDescriptor &socketDescriptor, U8 *const data, const FwSizeType size) override
Protocol specific implementation of recv. Called directly with error handling from recv...
Definition: UdpSocket.cpp:212
SocketIpStatus configureSend(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the udp socket for outgoing transmissions
Definition: UdpSocket.cpp:57
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:29
Helper base-class for setting up Berkeley sockets.
Definition: IpSocket.hpp:57
SocketIpStatus handleZeroReturn() override
Handle zero return from recvProtocol for UDP.
Definition: UdpSocket.cpp:267
SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds) override
configure is disabled
Definition: UdpSocket.cpp:49
SocketIpStatus openProtocol(SocketDescriptor &socketDescriptor) override
udp specific implementation for opening a socket.
Definition: UdpSocket.cpp:115