Flair
Framework Libre Air
ConnectedSocket.h
Go to the documentation of this file.
1 // %flair:license{
2 // This file is part of the Flair framework distributed under the
3 // CECILL-C License, Version 1.0.
4 // %flair:license}
13 #ifndef CONNECTEDSOCKET_H
14 #define CONNECTEDSOCKET_H
15 
16 #include <Object.h>
17 
18 namespace flair {
19 namespace core {
20 
27 class ConnectedSocket : public Object {
28 public:
33  ConnectedSocket(const Object *parent, const std::string name);
34 
40 
49  virtual void Listen(const unsigned int port,
50  const std::string localAddress = "ANY") = 0;
51 
57  virtual ConnectedSocket *Accept(
58  Time timeout) = 0; // should throw an exception if not a listening socket
59 
69  virtual bool Connect(const unsigned int port,
70  const std::string distantAddress, Time timeout) = 0;
71 
79  virtual ssize_t SendMessage(const char *message, size_t message_len,
80  Time timeout) = 0;
81 
93  virtual ssize_t RecvMessage(char *buf, size_t buf_len, Time timeout) = 0;
94 
95  std::string ReadString(const size_t &stringLength, Time timeout);
96  uint16_t ReadUInt16(Time const &timeout);
97  void WriteUInt16(uint16_t const &data, Time const &timeout);
98  uint32_t ReadUInt32(Time const &timeout);
99  void WriteUInt32(uint32_t const &data, Time const &timeout);
100 
102  // conversion
103  virtual uint16_t NetworkToHost16(uint16_t data) = 0;
104  virtual uint16_t HostToNetwork16(uint16_t data) = 0;
105  virtual uint32_t NetworkToHost32(uint32_t data) = 0;
106  virtual uint32_t HostToNetwork32(uint32_t data) = 0;
107 };
108 
109 } // end namespace core
110 } // end namespace flair
111 
112 #endif // CONNECTEDSOCKET_H
Interface class encapsulating a connected socket. Preserves packets order and guaranty delivery...
Definition: ConnectedSocket.h:27
virtual void Listen(const unsigned int port, const std::string localAddress="ANY")=0
Returns a socket which listens on a specific port/address.
virtual ssize_t SendMessage(const char *message, size_t message_len, Time timeout)=0
Send a message waiting up to timeout ns.
Base class for all Framework's classes.
Definition: Object.h:83
namespace of the flair Framework
Definition: Ahrs.h:19
unsigned long long Time
Time definition, in ns.
Definition: Object.h:55
ConnectedSocket(const Object *parent, const std::string name)
Constructor.
virtual bool Connect(const unsigned int port, const std::string distantAddress, Time timeout)=0
Returns a socket connected to a distant host.
Base class for all Framework's classes.
virtual ssize_t RecvMessage(char *buf, size_t buf_len, Time timeout)=0
Receive a message.
virtual uint16_t NetworkToHost16(uint16_t data)=0
! See Socket.h for a more generic implementation of network/host endianness
virtual ConnectedSocket * Accept(Time timeout)=0
Returns a socket on a new incoming connexion.