UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
message.hpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2021 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37#ifndef UG_HOLE_PUNCH_MESSAGE_HPP
38#define UG_HOLE_PUNCH_MESSAGE_HPP
39
40#include <string_view>
41#include <functional>
42#include <asio.hpp>
43#include "status_code.hpp"
44
45class Message{
46public:
47 using CompletionCallback = std::function<void(CompletionStatus)>;
48 Message() = default;
49
50 void async_readMsg(asio::ip::tcp::socket& socket,
51 CompletionCallback onComplete);
52
53 std::string_view getStr() const;
54
55 void setStr(std::string_view msg);
56 void async_sendMsg(asio::ip::tcp::socket& socket,
57 CompletionCallback onComplete);
58
59 size_t getSize() const { return size; }
60 bool empty() const { return size == 0; }
61 bool isSendingNow() const { return sendingNow; }
62 void clear();
63
64private:
65 void async_readBody(asio::ip::tcp::socket& socket,
66 CompletionCallback onComplete,
67 const std::error_code& ec, size_t readLen);
68
70 const std::error_code& ec, size_t readLen);
71
73 const std::error_code& ec, size_t sentLen);
74
75 size_t size = 0;
76
77 bool sendingNow = false;
78
79 static constexpr size_t headerSize = 5;
80 static constexpr size_t bodySize = 2048;
82};
83
84#endif
std::string_view getStr() const
Definition message.cpp:43
void async_readMsg(asio::ip::tcp::socket &socket, CompletionCallback onComplete)
Definition message.cpp:47
void async_sendComplete(CompletionCallback onComplete, const std::error_code &ec, size_t sentLen)
Definition message.cpp:121
size_t getSize() const
Definition message.hpp:59
size_t size
Definition message.hpp:75
Message()=default
void async_sendMsg(asio::ip::tcp::socket &socket, CompletionCallback onComplete)
Definition message.cpp:67
static constexpr size_t bodySize
Definition message.hpp:80
bool sendingNow
Definition message.hpp:77
static constexpr size_t headerSize
Definition message.hpp:79
void clear()
void async_readBody(asio::ip::tcp::socket &socket, CompletionCallback onComplete, const std::error_code &ec, size_t readLen)
Definition message.cpp:78
bool empty() const
Definition message.hpp:60
char data[headerSize+bodySize]
Definition message.hpp:81
bool isSendingNow() const
Definition message.hpp:61
void setStr(std::string_view msg)
Definition message.cpp:57
std::function< void(CompletionStatus)> CompletionCallback
Definition message.hpp:47
void async_readBodyComplete(CompletionCallback onComplete, const std::error_code &ec, size_t readLen)
Definition message.cpp:106
CompletionStatus