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 #undef m_len
30 
31 #else
32 #include <arpa/inet.h>
33 #include <sys/socket.h>
34 #endif
35 
36 namespace Drv {
37 
44 class UdpSocket : public IpSocket {
45  public:
49  UdpSocket();
53  virtual ~UdpSocket();
54 
60  SocketIpStatus configure(const char* hostname,
61  const U16 port,
62  const U32 send_timeout_seconds,
63  const U32 send_timeout_microseconds) override;
64 
83  SocketIpStatus configureSend(const char* hostname,
84  const U16 port,
85  const U32 send_timeout_seconds,
86  const U32 send_timeout_microseconds);
87 
101  SocketIpStatus configureRecv(const char* hostname, const U16 port);
102 
111  U16 getRecvPort();
112 
120  SocketIpStatus send(const SocketDescriptor& socketDescriptor, const U8* const data, const FwSizeType size) override;
121 
122  protected:
128  SocketIpStatus bind(const int fd);
134  SocketIpStatus openProtocol(SocketDescriptor& socketDescriptor) override;
142  FwSignedSizeType sendProtocol(const SocketDescriptor& socketDescriptor,
143  const U8* const data,
144  const FwSizeType size) override;
152  FwSignedSizeType recvProtocol(const SocketDescriptor& socketDescriptor,
153  U8* const data,
154  const FwSizeType size) override;
163  SocketIpStatus handleZeroReturn() override;
164 
165  private:
166  struct sockaddr_in m_addr_send;
167  struct sockaddr_in m_addr_recv;
168  bool m_recv_configured;
169 };
170 } // namespace Drv
171 
172 #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:44
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