Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
iconn.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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.h
10//! @brief Connection interface.
11
12#ifndef ROC_NETIO_ICONN_H_
13#define ROC_NETIO_ICONN_H_
14
16#include "roc_core/stddefs.h"
19
20namespace roc {
21namespace netio {
22
23//! Connection interface.
24//!
25//! All methods are thread-safe and non-blocking.
26//!
27//! All methods are also lock-free if there is no more than one simultaneous
28//! writer or reader. IConn operations are never blocked by network thread
29//! itself, but concurrent simultaneous writes and reads block each other.
30class IConn {
31public:
32 virtual ~IConn();
33
34 //! Return address of the local peer.
35 virtual const address::SocketAddr& local_address() const = 0;
36
37 //! Return address of the remote peer.
38 virtual const address::SocketAddr& remote_address() const = 0;
39
40 //! Return true if there was a failure.
41 virtual bool is_failed() const = 0;
42
43 //! Return true if the connection is writable.
44 virtual bool is_writable() const = 0;
45
46 //! Return true if the connection is readable.
47 virtual bool is_readable() const = 0;
48
49 //! Try writing @p buf of size @p len to the connection without blocking.
50 //! @remarks
51 //! - @p buf should not be NULL.
52 //! - @p buf should have size at least of @p len bytes.
53 //! @returns
54 //! number of bytes written (>= 0) or SocketError (< 0);
55 virtual ssize_t try_write(const void* buf, size_t len) = 0;
56
57 //! Try reading @p len bytes from the the connection to @p buf without blocking.
58 //! @remarks
59 //! - @p buf should not be NULL.
60 //! - @p buf should have size at least of @p len bytes.
61 //! @returns
62 //! number of bytes read (>= 0) or SocketError (< 0);
63 virtual ssize_t try_read(void* buf, size_t len) = 0;
64
65 //! Initiate asynchronous connection termination.
66 //! @remarks
67 //! When termination is complete, IConnHandler::connection_terminated()
68 //! is called, and then connection object is destroyed.
69 virtual void async_terminate(TerminationMode mode) = 0;
70};
71
72} // namespace netio
73} // namespace roc
74
75#endif // ROC_NETIO_ICONN_H_
Connection interface.
Definition iconn.h:30
virtual bool is_writable() const =0
Return true if the connection is writable.
virtual bool is_readable() const =0
Return true if the connection is readable.
virtual ssize_t try_write(const void *buf, size_t len)=0
Try writing buf of size len to the connection without blocking.
virtual ssize_t try_read(void *buf, size_t len)=0
Try reading len bytes from the the connection to buf without blocking.
virtual void async_terminate(TerminationMode mode)=0
Initiate asynchronous connection termination.
virtual const address::SocketAddr & remote_address() const =0
Return address of the remote peer.
virtual bool is_failed() const =0
Return true if there was a failure.
virtual const address::SocketAddr & local_address() const =0
Return address of the local peer.
TerminationMode
Connection termination mode.
Root namespace.
Socket address.
Socket operations.
Commonly used types and functions.
Connection termination mode.