Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
tcp_server_port.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 Roc Streaming authors
3
*
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
*/
8
9
//! @file roc_netio/target_libuv/roc_netio/tcp_server_port.h
10
//! @brief TCP server.
11
12
#ifndef ROC_NETIO_TCP_SERVER_PORT_H_
13
#define ROC_NETIO_TCP_SERVER_PORT_H_
14
15
#include <uv.h>
16
17
#include "
roc_address/socket_addr.h
"
18
#include "
roc_core/iarena.h
"
19
#include "
roc_core/list.h
"
20
#include "
roc_core/shared_ptr.h
"
21
#include "
roc_core/stddefs.h
"
22
#include "
roc_netio/basic_port.h
"
23
#include "
roc_netio/iclose_handler.h
"
24
#include "
roc_netio/iconn_acceptor.h
"
25
#include "
roc_netio/iterminate_handler.h
"
26
#include "
roc_netio/socket_ops.h
"
27
#include "
roc_netio/tcp_connection_port.h
"
28
29
namespace
roc
{
30
namespace
netio
{
31
32
//! TCP server parameters.
33
struct
TcpServerConfig :
TcpConnectionConfig
{
34
//! Server will bind to this address.
35
//! If IP is zero, INADDR_ANY is used, i.e. the socket is bound to all network
36
//! interfaces. If port is zero, a random free port is selected.
37
address::SocketAddr
bind_address
;
38
39
//! Maximum length to which the queue of pending connections may grow.
40
size_t
backlog_limit
;
41
42
TcpServerConfig()
43
:
backlog_limit
(128) {
44
}
45
};
46
47
//! TCP server.
48
class
TcpServerPort
:
public
BasicPort
,
private
ITerminateHandler
,
private
ICloseHandler
{
49
public
:
50
//! Initialize.
51
TcpServerPort
(
const
TcpServerConfig
& config,
52
IConnAcceptor
& conn_acceptor,
53
uv_loop_t& loop,
54
core::IArena
&
arena
);
55
56
//! Destroy.
57
virtual
~TcpServerPort
();
58
59
//! Get bind address.
60
const
address::SocketAddr
&
bind_address
()
const
;
61
62
//! Open TCP server.
63
//!
64
//! @remarks
65
//! Should be called from the network loop thread.
66
virtual
bool
open
();
67
68
//! Asynchronously close TCP server.
69
//!
70
//! @remarks
71
//! Should be called from network loop thread.
72
virtual
AsyncOperationStatus
async_close
(
ICloseHandler
& handler,
void
* handler_arg);
73
74
protected
:
75
//! Format descriptor.
76
virtual
void
format_descriptor
(
core::StringBuilder
& b);
77
78
private
:
79
static
void
poll_cb_(uv_poll_t* handle,
int
status,
int
events);
80
static
void
close_cb_(uv_handle_t* handle);
81
82
virtual
void
handle_terminate_completed(
IConn
& conn,
void
* arg);
83
virtual
void
handle_close_completed(
BasicPort
& port,
void
* arg);
84
85
AsyncOperationStatus
async_close_server_();
86
void
finish_closing_server_();
87
88
size_t
num_connections_()
const
;
89
void
async_close_all_connections_();
90
void
async_terminate_connection_(
const
core::SharedPtr<TcpConnectionPort>
&);
91
void
async_close_connection_(
const
core::SharedPtr<TcpConnectionPort>
&);
92
void
finish_closing_connection_(
const
core::SharedPtr<TcpConnectionPort>
&);
93
94
TcpServerConfig
config_;
95
96
IConnAcceptor
& conn_acceptor_;
97
98
ICloseHandler
* close_handler_;
99
void
* close_handler_arg_;
100
101
uv_loop_t& loop_;
102
103
SocketHandle
socket_;
104
105
uv_poll_t poll_handle_;
106
bool
poll_handle_initialized_;
107
bool
poll_handle_started_;
108
109
core::List<TcpConnectionPort>
open_conns_;
110
core::List<TcpConnectionPort>
closing_conns_;
111
112
bool
want_close_;
113
bool
closed_;
114
};
115
116
}
// namespace netio
117
}
// namespace roc
118
119
#endif
// ROC_NETIO_TCP_SERVER_PORT_H_
basic_port.h
Base class for ports.
roc::address::SocketAddr
Socket address.
Definition
socket_addr.h:26
roc::core::ArenaAllocation::arena
IArena & arena() const
Get arena.
Definition
allocation_policy.h:37
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::List
Intrusive doubly-linked list.
Definition
list.h:40
roc::core::SharedPtr
Shared ownership intrusive pointer.
Definition
shared_ptr.h:32
roc::core::StringBuilder
String builder.
Definition
string_builder.h:34
roc::netio::BasicPort::BasicPort
BasicPort(core::IArena &)
Initialize.
roc::netio::ICloseHandler
Close handler interface.
Definition
iclose_handler.h:21
roc::netio::IConnAcceptor
Connection acceptor interface.
Definition
iconn_acceptor.h:25
roc::netio::IConn
Connection interface.
Definition
iconn.h:30
roc::netio::ITerminateHandler
Termination handler interface.
Definition
iterminate_handler.h:22
roc::netio::TcpServerPort::TcpServerPort
TcpServerPort(const TcpServerConfig &config, IConnAcceptor &conn_acceptor, uv_loop_t &loop, core::IArena &arena)
Initialize.
roc::netio::TcpServerPort::async_close
virtual AsyncOperationStatus async_close(ICloseHandler &handler, void *handler_arg)
Asynchronously close TCP server.
roc::netio::TcpServerPort::bind_address
const address::SocketAddr & bind_address() const
Get bind address.
roc::netio::TcpServerPort::~TcpServerPort
virtual ~TcpServerPort()
Destroy.
roc::netio::TcpServerPort::open
virtual bool open()
Open TCP server.
roc::netio::TcpServerPort::format_descriptor
virtual void format_descriptor(core::StringBuilder &b)
Format descriptor.
iarena.h
Memory arena interface.
iclose_handler.h
Close handler interface.
iconn_acceptor.h
Connection acceptor interface.
iterminate_handler.h
Termination handler interface.
list.h
Intrusive doubly-linked list.
roc::netio
Network I/O.
roc::netio::SocketHandle
int SocketHandle
Platform-specific socket handle.
Definition
socket_ops.h:51
roc::netio::AsyncOperationStatus
AsyncOperationStatus
Asynchronous operation status.
Definition
operation_status.h:19
roc
Root namespace.
shared_ptr.h
Shared ownership intrusive pointer.
socket_addr.h
Socket address.
socket_ops.h
Socket operations.
stddefs.h
Commonly used types and functions.
roc::netio::TcpConnectionConfig
TCP connection parameters.
Definition
tcp_connection_port.h:34
roc::netio::TcpServerConfig
TCP server parameters.
Definition
tcp_server_port.h:33
roc::netio::TcpServerConfig::bind_address
address::SocketAddr bind_address
Server will bind to this address. If IP is zero, INADDR_ANY is used, i.e. the socket is bound to all ...
Definition
tcp_server_port.h:37
roc::netio::TcpServerConfig::backlog_limit
size_t backlog_limit
Maximum length to which the queue of pending connections may grow.
Definition
tcp_server_port.h:40
tcp_connection_port.h
TCP connection.
roc_netio
target_libuv
roc_netio
tcp_server_port.h
Generated by
1.17.0