Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
iconn_handler.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/iconn_handler.h
10//! @brief Connection event handler interface.
11
12#ifndef ROC_NETIO_ICONN_HANDLER_H_
13#define ROC_NETIO_ICONN_HANDLER_H_
14
16#include "roc_netio/iconn.h"
17
18namespace roc {
19namespace netio {
20
21//! Connection event handler interface.
22//!
23//! Workflow
24//! --------
25//!
26//! - first, either connection_refused() or connection_established() is called
27//! excactly once for connection
28//!
29//! - these two calls are the point where the user can obtain IConn reference
30//! for the first time; the same reference will be then passed to other callbacks
31//!
32//! - after obtaining IConn reference, the user is responsible for terminating
33//! connection when it's no longer needed
34//!
35//! - connection_refused() call is possible only for client-side conenction
36//!
37//! - after connection is established, connection_writable() and
38//! connection_readable() are called repeatedly whenever it becomes
39//! possible to write or read data from connection
40//!
41//! - if an established connection fails asynchronously, it becomes readable
42//! and writable, and the next I/O operation will return error
43//!
44//! - after an asynchronous terminate is issued, no other callbacks
45//! except connection_terminated() are ever called
46//!
47//! - when an asynchronous terminate is completed, connection_terminated()
48//! is called; connection is still usable inside this callback
49//!
50//! - after connection_terminated() returns, the handler is never ever used for
51//! this connection, and the connection is destroyed
52//!
53//! - even after connection_terminated() call, the handler should not be
54//! destroyed until IConnAcceptor callback
55//!
56//! @note
57//! - Methods are called from the network loop thread.
58//! - Methods should not block.
60public:
61 virtual ~IConnHandler();
62
63 //! Connection can't be established.
64 virtual void connection_refused(IConn& conn) = 0;
65
66 //! Connection successfully established.
67 virtual void connection_established(IConn& conn) = 0;
68
69 //! Connection becomes available for writing.
70 virtual void connection_writable(IConn& conn) = 0;
71
72 //! Connection becomes available for reading.
73 virtual void connection_readable(IConn& conn) = 0;
74
75 //! Connection is terminated and can't be accessed after this call.
76 virtual void connection_terminated(IConn& conn) = 0;
77};
78
79} // namespace netio
80} // namespace roc
81
82#endif // ROC_NETIO_ICONN_HANDLER_H_
Base class for object with usage counter.
Definition: usage_counter.h:28
Connection event handler interface.
Definition: iconn_handler.h:59
virtual void connection_terminated(IConn &conn)=0
Connection is terminated and can't be accessed after this call.
virtual void connection_readable(IConn &conn)=0
Connection becomes available for reading.
virtual void connection_refused(IConn &conn)=0
Connection can't be established.
virtual void connection_established(IConn &conn)=0
Connection successfully established.
virtual void connection_writable(IConn &conn)=0
Connection becomes available for writing.
Connection interface.
Definition: iconn.h:30
Connection interface.
Root namespace.
Base class for object with usage counter.