Hi,
thank you for your answer.

so the uv_loop_t is run by a thread (the one created by  reader_start())
how can I async send the loop the uv_tcp_connect() request?

or should I tell to the reader_start() to create the two clients and in the 
two threads just send_message() to the clients?

thanks,
nico 

Le vendredi 21 avril 2017 22:09:38 UTC+2, Fedor Indutny a écrit :
>
> Hello!
>
> I might have got it wrong, but it looks like you are trying to share a 
> `uv_loop_t` between two threads. libuv is generally not thread safe, the 
> only thread-safe primitive is `uv_async_send` which may be used to invoke a 
> callback on a loop that runs in some other thread.
>
> Hope this helps,
> Fedor.
>
> On Fri, Apr 21, 2017 at 4:01 PM, nicolas bats <[email protected] 
> <javascript:>> wrote:
>
>> Hi guys,
>> I'm discovering libuv and things are going well _on osx_ and things are 
>> going not well _on windows_...
>> I'm trying to set up a tcp server and example I'm following is from here :
>> https://github.com/litesync/libuv_message_framing
>>
>> I have two threads that listen on usb inputs and I want them to send a 
>> copy of their buffer to the tcp server.
>> first, is tcp the good choice for that task?
>>
>> at start of the program, I set up a uv_loop for the server like in 
>> https://github.com/litesync/libuv_message_framing/blob/master/test/test.c
>> so it's a threaded server:
>>
>>         uv_barrier_init(&(loop_ptr->barrier), 2);
>>
>>         uv_thread_create(&(loop_ptr->reader_thread), reader_start, 
>> loop_ptr);
>>
>>         /* wait until the listening socket is ready on the reader thread 
>> */
>>
>>         uv_barrier_wait(&(loop_ptr->barrier));
>>
>>
>> with reader_start() that start an uv loop.
>>
>>
>> right after, the two threads are created and each one is setting up a 
>> socket which attempt to connect to the server:
>>
>>     struct sockaddr_in dest;
>>
>>     uv_ip4_addr("127.0.0.1", loop_ptr->serverPort ,&dest);
>>
>>     uv_connect_t* connect = malloc(sizeof(uv_connect_t));
>>
>>             
>>
>>     uv_msg_t* socket = malloc(sizeof(uv_msg_t));
>>
>>     rc = uv_msg_init(loop_ptr->server_loop, socket, UV_TCP);
>>
>>             
>>
>>     uv_tcp_connect(connect, (uv_tcp_t*)socket, (const struct 
>> sockaddr*)&dest, 
>> on_connect);
>>
>>
>> and at this early point, it's not clear for me why it works on osx and 
>> why it fails on windows...
>>
>> on windows (uv-1.10.2 MSYS2/GCC), it tells that an assertion failed 
>> ((handle))->activecnt > 0... but not always....
>>
>>
>> so, can you please tell me what I'm doing wrong.
>>
>>
>> many thanks,
>>
>> nico
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> Visit this group at https://groups.google.com/group/libuv.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to