Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv_accept in one thread and uv_read_start from other thread #961

Closed
tigranbs opened this issue Jul 31, 2016 · 1 comment
Closed

uv_accept in one thread and uv_read_start from other thread #961

tigranbs opened this issue Jul 31, 2016 · 1 comment

Comments

@tigranbs
Copy link

tigranbs commented Jul 31, 2016

Hi I'm trying to develop network application with multithreaded network read write requirement.
I've implemented a lot with libuv, but now I can't find any resource to solve multithreaded issue.

I have thread A which is running only server binded socket and I want to use it only for accepting connections, and after having connection accepted I want to start reading from thread B which is running another libuv loop.
So the point is to have 1 loop just for accepting connections and another loop just for reading data from that connections.

Is there a way to do that ? (even by hacking something :) )

    // Accept connection
    if(uv_accept(server, (uv_stream_t *)client) == 0) {

       ..................
       ..................

        // how can I call uv_read_start for a different loop ???
        int r = uv_read_start((uv_stream_t *)client, alloc_cb, on_read);
        if(r) {
            uv_close((uv_handle_t*) client, close_client);
            return;
        }

    } else {
        uv_close((uv_handle_t*) client, close_client);
    }
@saghul
Copy link
Member

saghul commented Aug 1, 2016

What you need to do is send the handle over to the other thread and start reading there. See uv_write2.

PS: In the future please use the mailing list for questions.

@saghul saghul closed this as completed Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants