Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
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
15
#include "
roc_address/socket_addr.h
"
16
#include "
roc_core/stddefs.h
"
17
#include "
roc_netio/socket_ops.h
"
18
#include "
roc_netio/termination_mode.h
"
19
20
namespace
roc
{
21
namespace
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.
30
class
IConn
{
31
public
:
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_
roc::address::SocketAddr
Socket address.
Definition
socket_addr.h:26
roc::netio::IConn
Connection interface.
Definition
iconn.h:30
roc::netio::IConn::is_writable
virtual bool is_writable() const =0
Return true if the connection is writable.
roc::netio::IConn::is_readable
virtual bool is_readable() const =0
Return true if the connection is readable.
roc::netio::IConn::try_write
virtual ssize_t try_write(const void *buf, size_t len)=0
Try writing buf of size len to the connection without blocking.
roc::netio::IConn::try_read
virtual ssize_t try_read(void *buf, size_t len)=0
Try reading len bytes from the the connection to buf without blocking.
roc::netio::IConn::async_terminate
virtual void async_terminate(TerminationMode mode)=0
Initiate asynchronous connection termination.
roc::netio::IConn::remote_address
virtual const address::SocketAddr & remote_address() const =0
Return address of the remote peer.
roc::netio::IConn::is_failed
virtual bool is_failed() const =0
Return true if there was a failure.
roc::netio::IConn::local_address
virtual const address::SocketAddr & local_address() const =0
Return address of the local peer.
roc::netio
Network I/O.
roc::netio::TerminationMode
TerminationMode
Connection termination mode.
Definition
termination_mode.h:19
roc
Root namespace.
socket_addr.h
Socket address.
socket_ops.h
Socket operations.
stddefs.h
Commonly used types and functions.
termination_mode.h
Connection termination mode.
roc_netio
target_libuv
roc_netio
iconn.h
Generated by
1.17.0