source: flair-src/trunk/lib/FlairCore/src/ConnectedSocket.h@ 19

Last change on this file since 19 was 16, checked in by Bayard Gildas, 9 years ago

Reformatting

File size: 3.0 KB
Line 
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}
5/*!
6 * \file ConnectedSocket.h
7 * \brief Class defining a socket working in connected mode
8 * \author Gildas Bayard, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2015/04/21
10 * \version 4.0
11 */
12
13#ifndef CONNECTEDSOCKET_H
14#define CONNECTEDSOCKET_H
15
16#include <Object.h>
17
18namespace flair {
19namespace core {
20
21/*! \class ConnectedSocket
22*
23* \brief Interface class encapsulating a connected socket. Preserves packets
24*order and guaranty delivery.
25*
26*/
27class ConnectedSocket : public Object {
28public:
29 /*!
30 * \brief Constructor
31 *
32 */
33 ConnectedSocket(const Object *parent, const std::string name);
34
35 /*!
36 * \brief Destructor
37 *
38 */
39 ~ConnectedSocket();
40
41 /*!
42 * \brief Returns a socket which listens on a specific port/address
43 *
44 * \param const Object* parentObject
45 * \param const string name
46 * \param unsigned int port
47 * \param const localAddress (defaults to any)
48 */
49 virtual void Listen(const unsigned int port,
50 const std::string localAddress = "ANY") = 0;
51
52 /*!
53 * \brief Returns a socket on a new incoming connexion
54 *
55 * \param ConnectedSocket &listeningSocket
56 */
57 virtual ConnectedSocket *Accept(
58 Time timeout) = 0; // should throw an exception if not a listening socket
59
60 /*!
61 * \brief Returns a socket connected to a distant host
62 *
63 * \param const Object* parentObject
64 * \param const string name
65 * \param unsigned int port
66 * \param const distantAddress
67 * \param timeout timeout (in milliseconds)
68 */
69 virtual bool Connect(const unsigned int port,
70 const std::string distantAddress, Time timeout) = 0;
71
72 /*!
73 * \brief Send a message
74 *
75 * \param message message
76 * \param message_len message length
77 * \param timeout timeout (in milliseconds)
78 */
79 virtual ssize_t SendMessage(const char *message, size_t message_len,
80 Time timeout) = 0;
81
82 /*!
83 * \brief Receive a message
84 *
85 * Receive a message and wait up to timeout. \n
86 *
87 * \param buf buffer to put the message
88 * \param buf_len buffer length
89 * \param timeout timeout (in milliseconds)
90 *
91 * \return size of the received message
92 */
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
101 //!! See Socket.h for a more generic implementation of network/host endianness
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
Note: See TracBrowser for help on using the repository browser.