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 #else
24 #include <arpa/inet.h>
25 #include <sys/socket.h>
26 #endif
27 
28 namespace Drv {
29 
36 class UdpSocket : public IpSocket {
37  public:
41  UdpSocket();
45  virtual ~UdpSocket();
46 
52  SocketIpStatus configure(const char* hostname,
53  const U16 port,
54  const U32 send_timeout_seconds,
55  const U32 send_timeout_microseconds) override;
56 
75  SocketIpStatus configureSend(const char* hostname,
76  const U16 port,
77  const U32 send_timeout_seconds,
78  const U32 send_timeout_microseconds);
79 
93  SocketIpStatus configureRecv(const char* hostname, const U16 port);
94 
103  U16 getRecvPort();
104 
112  SocketIpStatus send(const SocketDescriptor& socketDescriptor, const U8* const data, const FwSizeType size) override;
113 
114  protected:
120  SocketIpStatus bind(const int fd);
126  SocketIpStatus openProtocol(SocketDescriptor& socketDescriptor) override;
134  FwSignedSizeType sendProtocol(const SocketDescriptor& socketDescriptor,
135  const U8* const data,
136  const FwSizeType size) override;
144  FwSignedSizeType recvProtocol(const SocketDescriptor& socketDescriptor,
145  U8* const data,
146  const FwSizeType size) override;
155  SocketIpStatus handleZeroReturn() override;
156 
157  private:
158  struct sockaddr_in m_addr_send;
159  struct sockaddr_in m_addr_recv;
160  bool m_recv_configured;
161 };
162 } // namespace Drv
163 
164 #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:36
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