Linux开发:进程间通过Unix Domain Socket传递文件描述符
Linux开发:进程间通过Unix Domain Socket传递数据-CSDN博客
介绍了通过UDS传递数据
实际上当需要传递大量的数据时,可以通过UDS直接传递文件描述符,这样接收文件描述符的一方,可以直接从传递过来的文件描述符读取数据
先举例说明:
//uds_fd.hpp
#pragma once
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string>
#include <iostream>
#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
class UDSFd{
public:
UDSFd()
{
//创建基于数据包的通信,类似UDP
m_sockFd = socket(AF_UNIX, SOCK_DGRAM, 0);
if(m_sockFd == -1)
{
cout << "create socket failed" <<endl;
}
}
int bindFile(const string& sockFilePath)
{
if(m_sock
原文地址:https://blog.csdn.net/jiemashizhen/article/details/140279816
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!