Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
udp_receiver_port.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc 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/udp_receiver_port.h
10//! @brief UDP receiver.
11
12#ifndef ROC_NETIO_UDP_RECEIVER_PORT_H_
13#define ROC_NETIO_UDP_RECEIVER_PORT_H_
14
15#include <uv.h>
16
18#include "roc_core/iallocator.h"
19#include "roc_core/list.h"
20#include "roc_core/list_node.h"
21#include "roc_core/refcnt.h"
24#include "roc_packet/address.h"
25#include "roc_packet/iwriter.h"
27
28namespace roc {
29namespace netio {
30
31//! UDP receiver.
32class UDPReceiverPort : public BasicPort {
33public:
34 //! Initialize.
36 const packet::Address&,
37 uv_loop_t& event_loop,
38 packet::IWriter& writer,
39 packet::PacketPool& packet_pool,
40 core::BufferPool<uint8_t>& buffer_pool,
41 core::IAllocator& allocator);
42
43 //! Destroy.
45
46 //! Get bind address.
47 virtual const packet::Address& address() const;
48
49 //! Open receiver.
50 virtual bool open();
51
52 //! Asynchronously close receiver.
53 virtual void async_close();
54
55private:
56 static void close_cb_(uv_handle_t* handle);
57 static void alloc_cb_(uv_handle_t* handle, size_t size, uv_buf_t* buf);
58 static void recv_cb_(uv_udp_t* handle,
59 ssize_t nread,
60 const uv_buf_t* buf,
61 const sockaddr* addr,
62 unsigned flags);
63
64 ICloseHandler& close_handler_;
65
66 uv_loop_t& loop_;
67
68 uv_udp_t handle_;
69 bool handle_initialized_;
70
71 bool recv_started_;
72 bool closed_;
73
74 packet::Address address_;
75 packet::IWriter& writer_;
76
77 packet::PacketPool& packet_pool_;
78 core::BufferPool<uint8_t>& buffer_pool_;
79
80 unsigned packet_counter_;
81};
82
83} // namespace netio
84} // namespace roc
85
86#endif // ROC_NETIO_UDP_RECEIVER_PORT_H_
Network address.
Basic network port.
Buffer pool.
Memory allocator interface.
Definition: iallocator.h:23
Basic port interface.
Definition: basic_port.h:24
Close handler interface.
virtual void async_close()
Asynchronously close receiver.
virtual const packet::Address & address() const
Get bind address.
virtual bool open()
Open receiver.
UDPReceiverPort(ICloseHandler &close_handler, const packet::Address &, uv_loop_t &event_loop, packet::IWriter &writer, packet::PacketPool &packet_pool, core::BufferPool< uint8_t > &buffer_pool, core::IAllocator &allocator)
Initialize.
Network address.
Definition: address.h:24
Packet writer interface.
Definition: iwriter.h:21
Memory allocator interface.
Close handler.
Intrusive doubly-linked list.
Linked list node.
Root namespace.
Packet pool.
Base class for reference countable objects.
Packet writer interface.