Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
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
16#include "roc_core/iallocator.h"
17#include "roc_core/list_node.h"
22
23namespace roc {
24namespace 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
39class BasicPort : public core::RefCounted<BasicPort, core::StandardAllocation>,
40 public core::ListNode {
42
43public:
44 //! Initialize.
46
47 //! Destroy.
48 virtual ~BasicPort();
49
50 //! Get a human-readable port description.
51 //!
52 //! @note
53 //! Port descriptor may change during initial configuration.
54 const char* descriptor() const;
55
56 //! Open port.
57 //!
58 //! @remarks
59 //! Should be called from the event loop thread.
60 virtual bool open() = 0;
61
62 //! Asynchronous close.
63 //!
64 //! @remarks
65 //! Should be called from the event loop thread.
66 //!
67 //! @returns
68 //! status code indicating whether operation was completed immediately or
69 //! is scheduled for asynchronous execution
71 void* handler_arg) = 0;
72
73protected:
74 //! Format descriptor and store into internal buffer.
76
77 //! Implementation of descriptor formatting.
79
80private:
81 enum { MaxDescriptorLen = address::SocketAddr::MaxStrLen * 2 + 48 };
82
83 char descriptor_[MaxDescriptorLen];
84};
85
86} // namespace netio
87} // namespace roc
88
89#endif // ROC_NETIO_BASIC_PORT_H_
Memory allocator interface.
Definition iallocator.h:23
Base class for list element.
Definition list_node.h:26
Base class for reference counted object.
Definition ref_counted.h:39
Base class for ports.
Definition basic_port.h:40
const char * descriptor() const
Get a human-readable port description.
virtual bool open()=0
Open port.
virtual AsyncOperationStatus async_close(ICloseHandler &handler, void *handler_arg)=0
Asynchronous close.
virtual void format_descriptor(core::StringBuilder &b)=0
Implementation of descriptor formatting.
BasicPort(core::IAllocator &)
Initialize.
void update_descriptor()
Format descriptor and store into internal buffer.
virtual ~BasicPort()
Destroy.
Close handler interface.
Memory allocator interface.
Close handler interface.
Linked list node.
AsyncOperationStatus
Asynchronous operation status.
Root namespace.
Asynchronous operation status.
Base class for reference counted object.
Socket address.
String builder.