GKD.RoboCtrl
载入中...
搜索中...
未找到
udp.h
浏览该文件的文档.
1
6#pragma once
7#include <asio.hpp>
8#include <format>
9#include <string_view>
10#include <span>
11
12#include "core/async.hpp"
13#include "io/base.hpp"
14#include "core/logger.h"
15
16namespace roboctrl::io{
17
21class udp : public bare_io_base{
22public:
26 struct info_type{
27 using key_type = std::string_view;
28 using owner_type = udp;
29
30 std::string_view key_;
31 std::string_view address;
32 int port;
33
34 std::string_view key()const{
35 return key_;
36 }
37 };
38
42 udp(info_type info);
43
48
53
54 inline std::string desc()const{
55 return std::format("udp socket ({} to {}:{})",info_.key_,info_.address,info_.port);
56 }
57
58private:
59 asio::ip::udp::socket socket_;
60 info_type info_;
61 std::array<std::byte,1024> buffer_;
62};
63
64static_assert(bare_io<udp>);
65}
异步任务上下文组件。
裸IO组件。
Definition base.hpp:65
UDP 通信端点。
Definition udp.h:21
awaitable< void > task()
接收循环任务。
Definition udp.cpp:23
awaitable< void > send(byte_span data)
异步发送一段字节数据。
Definition udp.cpp:18
IO的基础组件。
std::span< std::byte > byte_span
byte span,实际上就是一个std::span<std::byte>;
Definition base.hpp:42
用于日志输出的组件。
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:42
UDP 初始化参数。
Definition udp.h:26