source: flair-src/trunk/lib/FlairCore/src/UdpSocket.h@ 221

Last change on this file since 221 was 178, checked in by Bayard Gildas, 7 years ago

Change Udp socket object name (from "Socket" to "UdpSocket")

File size: 2.5 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 Socket.h
7 * \brief Class defining a UDP socket
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2013/11/17
10 * \version 4.0
11 */
12
[178]13#ifndef UDPSOCKET_H
14#define UDPSOCKET_H
[2]15
16#include <unistd.h>
17#include <stdint.h>
18#include <Object.h>
19
[178]20class UdpSocket_impl;
[2]21
[15]22namespace flair {
23namespace core {
[2]24
[178]25/*! \class UdpSocket
[15]26*
27* \brief Class encapsulating a UDP socket. It assumes packets are coming from
28*only one distant host on a given port.
29*
30*/
[178]31class UdpSocket : public Object {
[15]32public:
33 /*!
34 * \brief Constructor
35 *
36 * Construct the client side of the socket
37 *
38 * \param parent parent
39 * \param name name
40 * \param address server address (ex 192.168.1.1:9000)
41 * \param broadcast true if address is a broadcast address
42 */
[178]43 UdpSocket(const Object *parent, std::string name, std::string address,
[15]44 bool broadcast = false);
[2]45
[15]46 /*!
47 * \brief Constructor
48 *
49 * Construct the server side of the socket
50 *
51 * \param parent parent
52 * \param name name
53 * \param port listening port
54 */
[178]55 UdpSocket(const Object *parent, std::string name, uint16_t port);
[2]56
[15]57 /*!
58 * \brief Destructor
59 *
60 */
[178]61 ~UdpSocket();
[2]62
[15]63 /*!
64 * \brief Send a message
65 *
66 * In case of a broadcast Socket, Parent()->ObjectName() is used as source of
67 *the message, this name should be unique.
68 *
69 * \param message message
70 */
71 void SendMessage(std::string message);
[2]72
[15]73 /*!
74 * \brief Send a message
75 *
76 * \param message message
77 * \param message_len message length
78 */
79 void SendMessage(const char *message, size_t message_len);
[2]80
[15]81 /*!
82 * \brief Receive a message
83 *
84 * Receive a message and wait up to timeout. \n
85 * If src and src_len are specified, the source of the message will be
86 * copied in the src buffer. \n
87 * Note that in case of a broadcast socket, own messages are filtered and
88 * are not received.
89 *
90 * \param buf buffer to put the message
91 * \param buf_len buffer length
92 * \param timeout timeout
93 * \param src buffer to put source name
94 * \param src_len buffer length
95 *
96 * \return size of the received message
97 */
98 ssize_t RecvMessage(char *buf, size_t buf_len, Time timeout, char *src = NULL,
99 size_t *src_len = NULL);
[2]100
[15]101 void NetworkToHost(char *data, size_t dataSize);
102 void HostToNetwork(char *data, size_t dataSize);
[2]103
[15]104private:
[178]105 class UdpSocket_impl *pimpl_;
[15]106};
[2]107
108} // end namespace core
109} // end namespace flair
110
[178]111#endif // UDPSOCKET_H
Note: See TracBrowser for help on using the repository browser.