srs-control
0.2.2
Toggle main menu visibility
Loading...
Searching...
No Matches
FecSwitchSocket.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
srs/connections/ConnectionTypeDef.hpp
"
4
#include "
srs/connections/SpecialSocketBase.hpp
"
5
#include "
srs/utils/AppReport.hpp
"
6
#include "
srs/utils/CommonAlias.hpp
"
7
#include <asio/awaitable.hpp>
8
#include <asio/deferred.hpp>
9
#include <asio/impl/co_spawn.hpp>
10
#include <asio/strand.hpp>
11
#include <asio/system_timer.hpp>
12
#include <chrono>
13
#include <cstddef>
14
#include <fmt/ranges.h>
15
#include <map>
16
#include <memory>
17
#include <mutex>
18
#include <span>
19
#include <spdlog/spdlog.h>
20
#include <string>
21
#include <utility>
22
#include <vector>
23
24
namespace
srs::connection
25
{
26
class
CommandBase
;
27
28
class
FecCommandSocket
:
public
SpecialSocket
29
{
30
public
:
31
using
SmallConnection
=
CommandBase
;
32
using
ConnectionType
=
SmallConnection
;
33
using
US
= std::chrono::microseconds;
34
using
USCount
=
decltype
(
US
{}.count());
35
using
StartEndTime
= std::pair<USCount, USCount>;
36
37
// getters:
38
auto
get_strand
() ->
auto
& {
return
strand_
; }
39
auto
get_time_us
() const ->
USCount
40
{
41
return
std::chrono::duration_cast<US>(std::chrono::steady_clock::now() -
start_time_
).count();
42
}
43
void
launch_send_actions
();
44
45
void
log_time_stamps
(std::string remote_port,
AppReport::FecSwitchStat
stat)
46
{
47
time_stamps_
.emplace_back(std::move(remote_port), stat);
48
}
49
50
void
before_socket_close
() {
register_report
(); }
51
52
private
:
53
friend
SpecialSocket
;
54
using
SmallConnections
= std::vector<std::shared_ptr<SmallConnection>>;
55
asio::strand<io_context_type::executor_type>
strand_
;
56
std::mutex
mut_
;
57
std::map<UDPEndpoint, SmallConnections>
all_connections_
;
58
std::vector<char>
read_msg_buffer_
;
59
std::chrono::time_point<std::chrono::steady_clock>
start_time_
= std::chrono::steady_clock::now();
60
std::vector<std::pair<std::string, AppReport::FecSwitchStat>>
time_stamps_
;
61
62
using
ActionType
=
decltype
(asio::co_spawn(
strand_
, asio::awaitable<void>(), asio::deferred));
63
std::vector<ActionType>
action_queue_
;
64
65
// constructor
66
explicit
FecCommandSocket
(
int
port_number,
io_context_type
& io_context);
67
68
void
register_send_action_imp
(asio::awaitable<void> action,
const
std::shared_ptr<SmallConnection>&
connection
);
69
auto
get_response_msg_buffer
() -> std::span<char> {
return
std::span{
read_msg_buffer_
}; }
70
auto
is_finished
() -> bool;
71
void
print_error
()
const
;
72
void
response_handler
(
const
UDPEndpoint
& endpoint, std::size_t read_size);
73
74
void
deregister_connection
(
const
UDPEndpoint
& endpoint,
75
std::span<char> response,
76
SmallConnections
& connections);
77
void
print_available_responses
()
const
;
78
79
void
register_report
();
80
};
81
82
}
// namespace srs::connection
AppReport.hpp
CommonAlias.hpp
ConnectionTypeDef.hpp
SpecialSocketBase.hpp
srs::connection::CommandBase
Definition
ConnectionBase.hpp:27
srs::connection::FecCommandSocket::FecCommandSocket
FecCommandSocket(int port_number, io_context_type &io_context)
Definition
FecSwitchSocket.cpp:55
srs::connection::FecCommandSocket::before_socket_close
void before_socket_close()
Definition
FecSwitchSocket.hpp:50
srs::connection::FecCommandSocket::deregister_connection
void deregister_connection(const UDPEndpoint &endpoint, std::span< char > response, SmallConnections &connections)
Definition
FecSwitchSocket.cpp:95
srs::connection::FecCommandSocket::all_connections_
std::map< UDPEndpoint, SmallConnections > all_connections_
Definition
FecSwitchSocket.hpp:57
srs::connection::FecCommandSocket::get_time_us
auto get_time_us() const -> USCount
Definition
FecSwitchSocket.hpp:39
srs::connection::FecCommandSocket::SpecialSocket
friend SpecialSocket
Definition
FecSwitchSocket.hpp:53
srs::connection::FecCommandSocket::register_report
void register_report()
Definition
FecSwitchSocket.cpp:182
srs::connection::FecCommandSocket::action_queue_
std::vector< ActionType > action_queue_
Definition
FecSwitchSocket.hpp:63
srs::connection::FecCommandSocket::get_response_msg_buffer
auto get_response_msg_buffer() -> std::span< char >
Definition
FecSwitchSocket.hpp:69
srs::connection::FecCommandSocket::response_handler
void response_handler(const UDPEndpoint &endpoint, std::size_t read_size)
Definition
FecSwitchSocket.cpp:158
srs::connection::FecCommandSocket::US
std::chrono::microseconds US
Definition
FecSwitchSocket.hpp:33
srs::connection::FecCommandSocket::log_time_stamps
void log_time_stamps(std::string remote_port, AppReport::FecSwitchStat stat)
Definition
FecSwitchSocket.hpp:45
srs::connection::FecCommandSocket::is_finished
auto is_finished() -> bool
Definition
FecSwitchSocket.cpp:175
srs::connection::FecCommandSocket::register_send_action_imp
void register_send_action_imp(asio::awaitable< void > action, const std::shared_ptr< SmallConnection > &connection)
Definition
FecSwitchSocket.cpp:63
srs::connection::FecCommandSocket::launch_send_actions
void launch_send_actions()
Definition
FecSwitchSocket.cpp:75
srs::connection::FecCommandSocket::ConnectionType
SmallConnection ConnectionType
Definition
FecSwitchSocket.hpp:32
srs::connection::FecCommandSocket::print_available_responses
void print_available_responses() const
Definition
FecSwitchSocket.cpp:130
srs::connection::FecCommandSocket::USCount
decltype(US{}.count()) USCount
Definition
FecSwitchSocket.hpp:34
srs::connection::FecCommandSocket::strand_
asio::strand< io_context_type::executor_type > strand_
Definition
FecSwitchSocket.hpp:55
srs::connection::FecCommandSocket::print_error
void print_error() const
Definition
FecSwitchSocket.cpp:140
srs::connection::FecCommandSocket::start_time_
std::chrono::time_point< std::chrono::steady_clock > start_time_
Definition
FecSwitchSocket.hpp:59
srs::connection::FecCommandSocket::ActionType
decltype(asio::co_spawn(strand_, asio::awaitable< void >(), asio::deferred)) ActionType
Definition
FecSwitchSocket.hpp:62
srs::connection::FecCommandSocket::time_stamps_
std::vector< std::pair< std::string, AppReport::FecSwitchStat > > time_stamps_
Definition
FecSwitchSocket.hpp:60
srs::connection::FecCommandSocket::StartEndTime
std::pair< USCount, USCount > StartEndTime
Definition
FecSwitchSocket.hpp:35
srs::connection::FecCommandSocket::SmallConnection
CommandBase SmallConnection
Definition
FecSwitchSocket.hpp:31
srs::connection::FecCommandSocket::mut_
std::mutex mut_
Definition
FecSwitchSocket.hpp:56
srs::connection::FecCommandSocket::get_strand
auto get_strand() -> auto &
Definition
FecSwitchSocket.hpp:38
srs::connection::FecCommandSocket::read_msg_buffer_
std::vector< char > read_msg_buffer_
Definition
FecSwitchSocket.hpp:58
srs::connection::FecCommandSocket::SmallConnections
std::vector< std::shared_ptr< SmallConnection > > SmallConnections
Definition
FecSwitchSocket.hpp:54
srs::connection
Definition
Application.hpp:34
srs::connection::UDPEndpoint
asio::ip::basic_endpoint< asio::ip::udp > UDPEndpoint
Definition
ConnectionTypeDef.hpp:17
srs::io_context_type
asio::thread_pool io_context_type
Definition
CommonAlias.hpp:12
srs::AppReport::FecSwitchStat
Definition
AppReport.hpp:24
backend
srs
connections
FecSwitchSocket.hpp
Impressum
Datenschutzerklärung
Generated by
1.17.0