dl
dl_net.h
浏览该文件的文档.
1
12#pragma once
13
14#include "io/dl_log.h"
15#include "base/dl_string.h"
16#include "system/dl_thread.h"
17
18
19namespace dl
20{
21 constexpr uint32_t NETWORK_MESSAGE_TAG = 0x1efe9722;
22
23 struct MsgHead
24 {
25 uint32_t _magic;
26 uint32_t _size;
27 uint32_t _check;
29 };
30
31class ClientImp;
32class Client
33{
34public:
35 bool Connent();
36 void Send(BufferView buf);
37
40private:
41 ClientImp* _imp;
42 Thread* _t;
43 std::atomic_bool _bEnd;
44
45 std::mutex _mutexSend;// send队列锁
46 std::list<Buffer> _listSend;// send队列
47 std::list<Buffer> _listSendTemp;// 主线程send缓冲
48 static void _thread_run(void*);// 主循环
49};
50
51
52class ServerImp;
53class Server
54{
55public:
56 bool Accept();
57 void Run();
58
61private:
62 ServerImp* _imp;
63 Thread* _t;
64
65 static void _thread_run(void*);
66};
67
68
70{
71public:
73 {
74 //Debug();
75 }
76
79 static std::string GetHostName();
80
84 static std::vector<std::string> GetIpAddressLocal(bool ipv4 = true);
88 static std::string GetIpAddressLocalFirst(bool ipv4 = true)
89 {
90 std::vector<std::string> vec = GetIpAddressLocal(ipv4);
91 return vec.empty() ? "127.0.0.1" : vec[0];
92 }
93
94 void Debug()
95 {
96 log_msg("----------------网络信息-------------\n"
97 "主机名:{}\n"
98 "本地ip:{}\n",
100 String::Splicing(GetIpAddressLocal()));
101 }
102};
103
104extern Network* g_net;
105}
bool Connent()
void Send(BufferView buf)
static std::string GetIpAddressLocalFirst(bool ipv4=true)
返回第一个本地ip,失败返回127.0.0.1
static std::vector< std::string > GetIpAddressLocal(bool ipv4=true)
返回本地ip
static std::string GetHostName()
返回主机名
void Run()
bool Accept()
日志系统
#define log_msg(...)
字符串相关
线程封装
constexpr uint32_t NETWORK_MESSAGE_TAG
std::span< std::byte > BufferView
Network * g_net
uint32_t _size
uint32_t _magic
uint32_t _check