Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
basic_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/basic_port.h
10
//! @brief Base class for ports.
11
12
#ifndef ROC_NETIO_BASIC_PORT_H_
13
#define ROC_NETIO_BASIC_PORT_H_
14
15
#include "
roc_address/socket_addr.h
"
16
#include "
roc_core/iarena.h
"
17
#include "
roc_core/list_node.h
"
18
#include "
roc_core/ref_counted.h
"
19
#include "
roc_core/string_builder.h
"
20
#include "
roc_netio/iclose_handler.h
"
21
#include "
roc_netio/operation_status.h
"
22
23
namespace
roc
{
24
namespace
netio
{
25
26
//! Base class for ports.
27
//!
28
//! Port is a transport-level endpoint, sending or receiving data from remote
29
//! peer, like UDP sender or receiver, TCP listening socket, or TCP connection.
30
//!
31
//! The following rules must be followed:
32
//!
33
//! - if you called open(), you're responsible for calling async_close(),
34
//! even if open() failed
35
//! - if async_close() returned AsyncOp_Completed, the port was closed
36
//! immediately, and you can now destroy it
37
//! - if async_close() returned AsyncOp_Started, you should wait until
38
//! close handler callback is invoked before destroying port
39
class
BasicPort
:
public
core::RefCounted
<BasicPort, core::ArenaAllocation>,
40
public
core::ListNode
<> {
41
public
:
42
//! Initialize.
43
explicit
BasicPort
(
core::IArena
&);
44
45
//! Destroy.
46
virtual
~BasicPort
();
47
48
//! Get a human-readable port description.
49
//!
50
//! @note
51
//! Port descriptor may change during initial configuration.
52
const
char
*
descriptor
()
const
;
53
54
//! Open port.
55
//!
56
//! @remarks
57
//! Should be called from the event loop thread.
58
virtual
bool
open
() = 0;
59
60
//! Asynchronous close.
61
//!
62
//! @remarks
63
//! Should be called from the event loop thread.
64
//!
65
//! @returns
66
//! status code indicating whether operation was completed immediately or
67
//! is scheduled for asynchronous execution
68
virtual
AsyncOperationStatus
async_close
(
ICloseHandler
& handler,
69
void
* handler_arg) = 0;
70
71
protected
:
72
//! Format descriptor and store into internal buffer.
73
void
update_descriptor
();
74
75
//! Implementation of descriptor formatting.
76
virtual
void
format_descriptor
(
core::StringBuilder
& b) = 0;
77
78
private
:
79
enum
{ MaxDescriptorLen = address::SocketAddr::MaxStrLen * 2 + 48 };
80
81
char
descriptor_[MaxDescriptorLen];
82
};
83
84
}
// namespace netio
85
}
// namespace roc
86
87
#endif
// ROC_NETIO_BASIC_PORT_H_
roc::core::IArena
Memory arena interface.
Definition
iarena.h:23
roc::core::ListNode
Base class for List element.
Definition
list_node.h:48
roc::core::RefCounted
Base class for object with reference counter.
Definition
ref_counted.h:40
roc::core::StringBuilder
String builder.
Definition
string_builder.h:34
roc::netio::BasicPort::descriptor
const char * descriptor() const
Get a human-readable port description.
roc::netio::BasicPort::open
virtual bool open()=0
Open port.
roc::netio::BasicPort::async_close
virtual AsyncOperationStatus async_close(ICloseHandler &handler, void *handler_arg)=0
Asynchronous close.
roc::netio::BasicPort::format_descriptor
virtual void format_descriptor(core::StringBuilder &b)=0
Implementation of descriptor formatting.
roc::netio::BasicPort::BasicPort
BasicPort(core::IArena &)
Initialize.
roc::netio::BasicPort::update_descriptor
void update_descriptor()
Format descriptor and store into internal buffer.
roc::netio::BasicPort::~BasicPort
virtual ~BasicPort()
Destroy.
roc::netio::ICloseHandler
Close handler interface.
Definition
iclose_handler.h:21
iarena.h
Memory arena interface.
iclose_handler.h
Close handler interface.
list_node.h
Linked list node.
roc::netio
Network I/O.
roc::netio::AsyncOperationStatus
AsyncOperationStatus
Asynchronous operation status.
Definition
operation_status.h:19
roc
Root namespace.
operation_status.h
Asynchronous operation status.
ref_counted.h
Base class for object with reference counter.
socket_addr.h
Socket address.
string_builder.h
String builder.
roc_netio
target_libuv
roc_netio
basic_port.h
Generated by
1.17.0