> Hi.


> I have a similar task - process incoming connections in different thread. 
> And I don't have fixed set of working threads, they are started on demand 
> and depending on settings which can, in particular, say to start new thread 
> for each incoming connection.


> Creation and processing of pipe just to transfer socket inside one process 
> is not trivial task. Sorry, but it looks rather ... over-engineered, to use 
> this IPC method for inter-thread communication when without libuv the task 
> is very simple - just pass accepted FD to new thread. Especially when there 
> are many independent listening sockets (each can listen in different 
> loop/thread). And also using a pipe makes accepting new connection rather 
> long-timed task because requires several loop iterations.

 My idea is to accept connections in one thread / loop (same as listening) 
and then dup() accepted socket, close original accepted socket, pass dup'ed 
socket to new thread / loop. On Unix this looks like:

uv_tcp_t *client_sock=new uv_tcp_t;  //must not be local to be correctly 

uv_tcp_init(server->loop, client_sock);

uv_accept((uv_stream_t*)&server->sock, (uv_stream_t*)client_sock);

uv_os_fd_t client_fd, client_fd_dup;
uv_fileno((uv_handle_t*)client_sock, &client_fd);


uv_close((uv_handle_t*)&client_sock,  [](uv_handle_t* handle) -> void {
  uv_tcp_t *client_sock=(uv_tcp_t *)handle;
  delete  client_sock;
//pass client_fd_dup to another thread immediately OR inside uv_close 
//and do "uv_tcp_open(&client->sock, client_fd_dup)" for client->sock which 
was inited for loop of that thread

This method seams to work and be legal for libuv. Any problems to expect?

You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to libuv+unsubscr...@googlegroups.com.
To post to this group, send email to libuv@googlegroups.com.
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to