-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatagram_socket_manager.h
More file actions
67 lines (55 loc) · 2.07 KB
/
Copy pathdatagram_socket_manager.h
File metadata and controls
67 lines (55 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef DATAGRAM_SOCKET_MANAGER_H
#define DATAGRAM_SOCKET_MANAGER_H
#include <chrono>
#include <cstdint>
#include <iterator>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#include <sys/socket.h>
#include <sys/types.h>
#include <errno.h>
#include "beehive_config.h"
#include "beehive_message.h"
#include "message_segment.h"
#include "port_manager.h"
#include "threadsafe_blocking_queue.h"
#include "threadsafe_unordered_map.h"
#include "tx_request_64_frame.h"
#include "uart_frame.h"
struct datagram_segment
{
uint64_t source_address;
std::shared_ptr<message_segment> segment;
};
class datagram_socket_manager
{
public:
datagram_socket_manager(const beehive_config &config,
std::shared_ptr<threadsafe_blocking_queue<std::shared_ptr<std::vector<uint8_t>>>>
write_queue);
bool try_create_passive_socket(int control_socket_fd, uint16_t listen_port);
bool try_create_active_socket(int control_socket_fd);
void process_segment(uint64_t source_address, std::shared_ptr<message_segment> segment);
private:
static uint32_t get_next_socket_suffix();
void passive_socket_manager(int control_socket_fd, int listen_socket_fd, uint16_t listen_port,
std::shared_ptr<threadsafe_blocking_queue<datagram_segment>> segment_queue);
void active_socket_manager(int control_socket_fd);
void destroy_socket(uint16_t port);
void payload_read_handler(int communication_socket_fd,
std::shared_ptr<threadsafe_blocking_queue<datagram_segment>> segment_queue,
std::shared_ptr<bool> running);
void payload_write_handler(
int communication_socket_fd, uint16_t source_port, std::shared_ptr<bool> running);
static uint32_t socket_suffix;
static std::mutex socket_suffix_lock;
const std::string dgram_path_prefix;
std::shared_ptr<threadsafe_blocking_queue<std::shared_ptr<std::vector<uint8_t>>>> write_queue;
threadsafe_unordered_map<uint16_t, std::shared_ptr<threadsafe_blocking_queue<datagram_segment>>>
segment_queue_map;
port_manager _port_manager;
};
#endif