You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
I have to send file descriptors of some shared memory buffers from one process to another. I'm able to transfer the fds directly over UNIX Domain Sockets as below:
But when i use domain sockets through abstraction libuv_pipe_t provided by libuv, I was not able to transfer the fds. Does libuv provides any way to transfer file descriptors between server pipe and client pipe ? If yes how to send and receive fds exactly ?
uv_pipe_t server:
#include <assert.h>
#include <memory.h>
#include <stdlib.h>
#include <unistd.h>
#include <uv.h>
#define SOCKET_NAME "socket_name"
void alloc_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
static char buffer[1024];
buf->base = buffer;
buf->len = sizeof(buffer);
}
void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) {
if (nread < 0) {
uv_stop(stream->loop);
uv_close((uv_handle_t*)stream, NULL);
}
printf("message received : %s\n", buf->base);
}
static void connection_cb(uv_stream_t* server, int status) {
printf("new connection recevied\n");
int r;
uv_pipe_t connection;
r = uv_pipe_init(server->loop, &connection, 0);
assert(r == 0);
r = uv_accept(server, (uv_stream_t*)&connection);
assert(r == 0);
r = uv_read_start((uv_stream_t*)&connection, alloc_buffer, read_cb);
assert(r == 0);
// send file descriptor
int fds[2];
fds[0] = fileno(fopen("fd_test_0.txt", "w"));
fds[1] = fileno(fopen("fd_test_1.txt", "w"));
// how to send "fds" array to client ?
}
int main() {
uv_pipe_t p;
int r;
r = uv_pipe_init(uv_default_loop(), &p, 0);
assert(r == 0);
unlink(SOCKET_NAME);
r = uv_pipe_bind(&p, SOCKET_NAME);
assert(r == 0);
r = uv_listen((uv_stream_t*)&p, 128, connection_cb);
assert(r == 0);
printf("listening...\n");
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
uv_loop_close(uv_default_loop());
}
Does libuv provides any way to transfer file descriptors between server pipe and client pipe ?
Not random file descriptors, no, because of Windows. Libuv only supports what can be supported on all platforms (that's its raison d'être after all) and this is one of the things that fall in the "no can do" bucket.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have to send file descriptors of some shared memory buffers from one process to another. I'm able to transfer the fds directly over UNIX Domain Sockets as below:
Send FDs:
Receive FDs:
But when i use domain sockets through abstraction
libuv_pipe_t
provided bylibuv
, I was not able to transfer the fds. Doeslibuv
provides any way to transfer file descriptors between server pipe and client pipe ? If yes how to send and receive fds exactly ?uv_pipe_t server:
uv_pipe_t client:
this example shows how to transfer pipe handles over pipes but it's doesn't completely solve my problem.
Any help is appreciated !!!
The text was updated successfully, but these errors were encountered: