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

Last change on this file since 466 was 238, checked in by Bayard Gildas, 6 years ago

correction sémaphore. bloquant tout ça...

File size: 3.0 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]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
[15]18namespace flair {
19namespace core {
[2]20
[15]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);
[2]34
[15]35 /*!
36 * \brief Destructor
37 *
38 */
39 ~ConnectedSocket();
[2]40
[15]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;
[2]51
[15]52 /*!
53 * \brief Returns a socket on a new incoming connexion
54 *
[238]55 * \param timeout timeout (in nanoseconds)
[15]56 */
57 virtual ConnectedSocket *Accept(
58 Time timeout) = 0; // should throw an exception if not a listening socket
[2]59
[15]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
[238]67 * \param timeout timeout (in nanoseconds)
[15]68 */
69 virtual bool Connect(const unsigned int port,
70 const std::string distantAddress, Time timeout) = 0;
[2]71
[15]72 /*!
[238]73 * \brief Send a message waiting up to timeout ns
[15]74 *
75 * \param message message
76 * \param message_len message length
[238]77 * \param timeout timeout (in nanoseconds)
[15]78 */
79 virtual ssize_t SendMessage(const char *message, size_t message_len,
80 Time timeout) = 0;
[2]81
[15]82 /*!
83 * \brief Receive a message
84 *
[238]85 * Receive a message and wait up to timeout ns. \n
[15]86 *
87 * \param buf buffer to put the message
88 * \param buf_len buffer length
[238]89 * \param timeout timeout (in nanoseconds)
[15]90 *
91 * \return size of the received message
92 */
93 virtual ssize_t RecvMessage(char *buf, size_t buf_len, Time timeout) = 0;
[2]94
[15]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);
[2]100
[15]101 //!! See Socket.h for a more generic implementation of network/host endianness
[16]102 // conversion
[15]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;
[2]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.