CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
streaming
detail
tcp
streaming/detail/tcp/Server.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "
carla/NonCopyable.h
"
10
#include "
carla/Time.h
"
11
#include "
carla/streaming/detail/tcp/ServerSession.h
"
12
13
#include <boost/asio/io_context.hpp>
14
#include <boost/asio/ip/tcp.hpp>
15
#include <boost/asio/post.hpp>
16
17
#include <atomic>
18
19
namespace
carla
{
20
namespace
streaming
{
21
namespace
detail
{
22
namespace
tcp
{
23
24
/// @warning This server cannot be destructed before its @a io_context is
25
/// stopped.
26
class
Server
:
private
NonCopyable
{
27
public
:
28
29
using
endpoint
= boost::asio::ip::tcp::endpoint;
30
using
protocol_type
= endpoint::protocol_type;
31
32
explicit
Server
(boost::asio::io_context &io_context,
endpoint
ep);
33
34
endpoint
GetLocalEndpoint
()
const
{
35
return
_acceptor
.local_endpoint();
36
}
37
38
/// Set session time-out. Applies only to newly created sessions. By default
39
/// the time-out is set to 10 seconds.
40
void
SetTimeout
(
time_duration
timeout) {
41
_timeout
= timeout;
42
}
43
44
/// Start listening for connections. On each new connection, @a
45
/// on_session_opened is called, and @a on_session_closed when the session
46
/// is closed.
47
template
<
typename
FunctorT1,
typename
FunctorT2>
48
void
Listen
(FunctorT1 on_session_opened, FunctorT2 on_session_closed) {
49
boost::asio::post(
_io_context
, [=,
this
]() {
50
OpenSession
(
51
_timeout
,
52
std::move(on_session_opened),
53
std::move(on_session_closed));
54
});
55
}
56
57
void
SetSynchronousMode
(
bool
is_synchro) {
58
_synchronous
= is_synchro;
59
}
60
61
bool
IsSynchronousMode
()
const
{
62
return
_synchronous
;
63
}
64
65
private
:
66
67
void
OpenSession
(
68
time_duration
timeout,
69
ServerSession::callback_function_type
on_session_opened,
70
ServerSession::callback_function_type
on_session_closed);
71
72
boost::asio::io_context &
_io_context
;
73
74
boost::asio::ip::tcp::acceptor
_acceptor
;
75
76
std::atomic<time_duration>
_timeout
;
77
78
bool
_synchronous
;
79
};
80
81
}
// namespace tcp
82
}
// namespace detail
83
}
// namespace streaming
84
}
// namespace carla
NonCopyable.h
ServerSession.h
Time.h
carla::NonCopyable::NonCopyable
NonCopyable()=default
carla::streaming::detail::tcp::ServerSession::callback_function_type
std::function< void(std::shared_ptr< ServerSession >)> callback_function_type
Definition
ServerSession.h:49
carla::streaming::detail::tcp::Server::protocol_type
endpoint::protocol_type protocol_type
Definition
streaming/detail/tcp/Server.h:30
carla::streaming::detail::tcp::Server::IsSynchronousMode
bool IsSynchronousMode() const
Definition
streaming/detail/tcp/Server.h:61
carla::streaming::detail::tcp::Server::_io_context
boost::asio::io_context & _io_context
Definition
streaming/detail/tcp/Server.h:72
carla::streaming::detail::tcp::Server::SetTimeout
void SetTimeout(time_duration timeout)
Set session time-out.
Definition
streaming/detail/tcp/Server.h:40
carla::streaming::detail::tcp::Server::endpoint
boost::asio::ip::tcp::endpoint endpoint
Definition
streaming/detail/tcp/Server.h:29
carla::streaming::detail::tcp::Server::GetLocalEndpoint
endpoint GetLocalEndpoint() const
Definition
streaming/detail/tcp/Server.h:34
carla::streaming::detail::tcp::Server::_synchronous
bool _synchronous
Definition
streaming/detail/tcp/Server.h:78
carla::streaming::detail::tcp::Server::OpenSession
void OpenSession(time_duration timeout, ServerSession::callback_function_type on_session_opened, ServerSession::callback_function_type on_session_closed)
Definition
Server.cpp:33
carla::streaming::detail::tcp::Server::Listen
void Listen(FunctorT1 on_session_opened, FunctorT2 on_session_closed)
Start listening for connections.
Definition
streaming/detail/tcp/Server.h:48
carla::streaming::detail::tcp::Server::Server
Server(boost::asio::io_context &io_context, endpoint ep)
Definition
Server.cpp:21
carla::streaming::detail::tcp::Server::_timeout
std::atomic< time_duration > _timeout
Definition
streaming/detail/tcp/Server.h:76
carla::streaming::detail::tcp::Server::_acceptor
boost::asio::ip::tcp::acceptor _acceptor
Definition
streaming/detail/tcp/Server.h:74
carla::streaming::detail::tcp::Server::SetSynchronousMode
void SetSynchronousMode(bool is_synchro)
Definition
streaming/detail/tcp/Server.h:57
carla::time_duration
Positive time duration up to milliseconds resolution.
Definition
Time.h:20
carla::streaming::detail::tcp
Definition
streaming/detail/tcp/Client.cpp:26
carla::streaming::detail
Definition
Dispatcher.cpp:17
carla::streaming
Definition
client/detail/Client.h:61
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0