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

Last change on this file since 2 was 2, checked in by Sanahuja Guillaume, 6 years ago

flaircore

File size: 3.3 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
19{
20namespace core
21{
22
23 /*! \class ConnectedSocket
24 *
25 * \brief Interface class encapsulating a connected socket. Preserves packets order and guaranty delivery.
26 *
27 */
28 class ConnectedSocket: public Object {
29 public:
30 /*!
31 * \brief Constructor
32 *
33 */
34 ConnectedSocket(const Object* parent,const std::string name);
35
36 /*!
37 * \brief Destructor
38 *
39 */
40 ~ConnectedSocket();
41
42 /*!
43 * \brief Returns a socket which listens on a specific port/address
44 *
45 * \param const Object* parentObject
46 * \param const string name
47 * \param unsigned int port
48 * \param const localAddress (defaults to any)
49 */
50 virtual void Listen(const unsigned int port,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(Time timeout)=0; //should throw an exception if not a listening socket
58
59 /*!
60 * \brief Returns a socket connected to a distant host
61 *
62 * \param const Object* parentObject
63 * \param const string name
64 * \param unsigned int port
65 * \param const distantAddress
66 * \param timeout timeout (in milliseconds)
67 */
68 virtual bool Connect(const unsigned int port,const std::string distantAddress,Time timeout)=0;
69
70 /*!
71 * \brief Send a message
72 *
73 * \param message message
74 * \param message_len message length
75 * \param timeout timeout (in milliseconds)
76 */
77 virtual ssize_t SendMessage(const char* message,size_t message_len,Time timeout)=0;
78
79 /*!
80 * \brief Receive a message
81 *
82 * Receive a message and wait up to timeout. \n
83 *
84 * \param buf buffer to put the message
85 * \param buf_len buffer length
86 * \param timeout timeout (in milliseconds)
87 *
88 * \return size of the received message
89 */
90 virtual ssize_t RecvMessage(char* buf,size_t buf_len,Time timeout)=0;
91
92 std::string ReadString(const size_t &stringLength, Time timeout);
93 uint16_t ReadUInt16(Time const& timeout);
94 void WriteUInt16(uint16_t const& data,Time const& timeout);
95 uint32_t ReadUInt32(Time const& timeout);
96 void WriteUInt32(uint32_t const& data,Time const& timeout);
97
98 //!! See Socket.h for a more generic implementation of network/host endianness conversion
99 virtual uint16_t NetworkToHost16(uint16_t data)=0;
100 virtual uint16_t HostToNetwork16(uint16_t data)=0;
101 virtual uint32_t NetworkToHost32(uint32_t data)=0;
102 virtual uint32_t HostToNetwork32(uint32_t data)=0;
103};
104
105} // end namespace core
106} // end namespace flair
107
108#endif // CONNECTEDSOCKET_H
Note: See TracBrowser for help on using the repository browser.