实际上当需要传递大量的数据时,可以通过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
发表评论