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