ithewei / libhv

🔥 比libevent/libuv/asio更易用的网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket/MQTT client/server.

Home Page:https://github.com/ithewei/libhv/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regarding whether the channel encapsulates sendmsg() and recvmsg() functions

zixiai opened this issue · comments

english:
Does the channel provide encapsulation of sendmsg() and recvmsg() functions to pass file descriptors (such as anonymous shared memory file descriptors) between processes using Uinx domain sockets? The existing framework seems to communicate using read()/write() or send()/rece() ..., and I haven't found an interface to pass file descriptors yet. I want to modify the source code, but I don't know how to get started.
中文:
channel是否提供sendmsg()和recvmsg()函数的封装,以便使用Uinx域套接字在进程之间传递文件描述符(例如匿名共享内存文件描述符)?现有的框架似乎使用read()/write()、send()/rece()等进行通信,我没有发现传递文件描述符的接口。我想修改源代码,但不知道如何下手。

可以使用hio_t* io = hio_get(loop, fd);通过fd拿到io对象
然后就可以使用hio_readhio_write读写了

static int __nio_read(hio_t* io, void* buf, int len) {

static int __nio_write(hio_t* io, const void* buf, int len) {

我仔细研究了下,这两个函数是不是没有针对 Unix Domain Socket 封装sendmsg()recvmsg()函数?因为基于 AF_UNIX 的 Unix Domain Socket 或者 socketpair() 可以使用这两个函数附带的辅助数据(msg_control)跨进程传递文件描述符,用其他的套接字和读写函数都实现不了,所以比较关注这个

没有封装sendmsgrecvmsg,你可以使用hio_add(io, cb, HV_READ)函数监听读事件,然后在回调里去自行调用recvmsg接收数据