连接多路复用
通过单个或多个物理链路,承载多个逻辑TCP连接。
高性能传输
跨平台调优
连接管理
vmux_net
(网络层)示例:添加链路的代码片段
bool vmux_net::add_linklayer(
const VirtualEthernetTcpipConnectionPtr& connection,
vmux_linklayer_ptr& linklayer)
{
rx_links_.emplace_back(linklayer); // 添加接收链路
tx_links_.emplace_back(linklayer); // 添加发送链路
// 启动链路转发协程
ppp::coroutines::YieldContext::Spawn(
[this, linklayer](auto& y){
forwarding(linklayer, y);
});
}
vmux_skt
(连接层)bool vmux_skt::rx_congestions(int64_t value) {
rx_congestions_ += value;
if (rx_congestions_ >= max_congestions && status_.rx_acceleration_) {
// 触发减速
mux_->post(cmd_acceleration, &FALSE);
} else if (rx_congestions_ <= 0 && !status_.rx_acceleration_) {
// 触发加速
mux_->post(cmd_acceleration, &TRUE);
}
}
seq
)填补间隙if (status_.rx_ack_ == seq) {
// 当前包连续
status_.rx_ack_++;
// 检查后续包是否连续
while (!rx_queue_.empty() && rx_queue_.begin()->first == status_.rx_ack_) {
status_.rx_ack_++;
}
}
bool vmux_skt::rx_congestions(int64_t value) {
rx_congestions_ += value;
if (rx_congestions_ >= max_congestions && status_.rx_acceleration_) {
// 减速
mux_->post(cmd_acceleration, &FALSE);
} else if (rx_congestions_ <= 0 && !status_.rx_acceleration_) {
// 加速
mux_->post(cmd_acceleration, &TRUE);
}
}
#if defined(_WIN32)
bool apply_qos(SOCKET sock, const ip_address& ip) {
qoss_ = ppp::net::QoSS::New(sock);
if (qoss_) {
return qoss_->Set(ip, DSCP_AF42);
}
return false;
}
#endif
#if defined(_LINUX)
bool protect_socket(int fd, ppp::coroutines::YieldContext& y) {
if (protector_network) {
return protector_network->Protect(fd, y);
}
return true;
}
#endif
make_byte_array(size); // 从缓冲池获取
shared_ptr
传递数据包,避免复制bool underlyin_sent(const std::shared_ptr<Byte>& packet) {
transmission->Write(packet.get(), ...);
}
vmux_spawn(context, strand, [](auto y){
// 同步操作
});
场景 | 描述 |
---|---|
VNP多路复用 | 多物理连接承载多个TCP会话,降低连接建立成本 |
物联网网关 | 低功耗设备连接管理,心跳维持长连接 |
游戏服务器 | 高并发连接处理,低延迟数据传输 |
VMUX技术以创新的多路复用架构,结合高效的调度与管理策略,
在确保TCP兼容的前提下,极大提升连接密度和传输效率。
特别适合高并发、低延迟的网络应用,
其模块化设计也为未来协议升级和硬件加速打下坚实基础。