Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
network_task.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 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/network_task.h
10//! @brief Network task.
11
12#ifndef ROC_NETIO_NETWORK_TASK_H_
13#define ROC_NETIO_NETWORK_TASK_H_
14
15#include "roc_core/atomic.h"
17#include "roc_core/optional.h"
18#include "roc_core/semaphore.h"
19#include "roc_core/shared_ptr.h"
21
22namespace roc {
23namespace netio {
24
25class NetworkLoop;
26class INetworkTaskCompleter;
27
28//! Base class for network loop tasks.
30public:
32
33 //! Check that the task finished and succeeded.
34 bool success() const;
35
36protected:
37 friend class NetworkLoop;
38
40
41 //! Task state.
42 enum State {
43 StateInitialized,
44 StatePending,
45 StateClosingPort,
46 StateFinishing,
47 StateFinished
48 };
49
50 //! Task implementation method.
52
53 //! Task state, defines whether task is finished already.
54 //! The task becomes immutable after setting state to Finished.
56
57 //! Task result, defines wether finished task succeeded or failed.
58 //! Makes sense only after setting state_ to Finished.
59 //! This atomic should be assigned before setting state_ to Finished.
61
62 core::SharedPtr<BasicPort> port_; //!< On which port the task operates.
63 void* port_handle_; //!< Port handle.
64
65 INetworkTaskCompleter* completer_; //!< Completion handler.
66 core::Optional<core::Semaphore> sem_; //!< Completion semaphore.
67};
68
69} // namespace netio
70} // namespace roc
71
72#endif // ROC_NETIO_NETWORK_TASK_H_
Atomic.
Base class for ports.
Base class for MpscQueue element.
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Network task completion handler.
Network event loop thread.
Base class for network loop tasks.
core::SharedPtr< BasicPort > port_
On which port the task operates.
void(NetworkLoop::* func_)(NetworkTask &)
Task implementation method.
void * port_handle_
Port handle.
INetworkTaskCompleter * completer_
Completion handler.
core::Atomic< int > state_
Task state, defines whether task is finished already. The task becomes immutable after setting state ...
bool success() const
Check that the task finished and succeeded.
core::Optional< core::Semaphore > sem_
Completion semaphore.
core::Atomic< int > success_
Task result, defines wether finished task succeeded or failed. Makes sense only after setting state_ ...
MpscQueue node.
Root namespace.
Optionally constructed object.
Shared ownership intrusive pointer.