i agree with you, but i don't know hoe design a single loop that run and 
tcp client allocation.

I was thinking about to use uv_run in a thread using UV_RUN_ONCE and use 
read/write lock between run thread and forward thread to submit new client 
within the loop.

What do you think about that?

Il giorno lunedì 7 luglio 2014 07:46:35 UTC+2, Fedor Indutny ha scritto:
>
> Hm... I'd suggest to profile it, but it is probably just a bit wrong idea 
> to use run loop synchronously in a `processBufferElement` handler.
>
>
> On Mon, Jul 7, 2014 at 12:38 AM, Iñaki Baz Castillo <[email protected] 
> <javascript:>> wrote:
>
>> No idea, but you are creating a new UV loop for each request to send!
>> not sure if you are releasing them after used. Anyhow I cannot help
>> too much with that design as IMHO it makes no sense at all to create a
>> UV loop for each action in your program.
>>
>> 2014-07-06 22:06 GMT+02:00 Claudio Bisegni <[email protected] 
>> <javascript:>>:
>> > Hi,
>> > i have the same setup of last my post. I have a class that need to send
>> > different message to a different server. So here is a queue of message 
>> and
>> > some thread that call the follow method:
>> >
>> > void TCPUVClient::processBufferElement(NetworkForwardInfo *messageInfo,
>> > ElementManagingPolicy& elementPolicy) throw(CException) {
>> >
>> > struct sockaddr_in req_addr;
>> >
>> > std::vector<std::string> server_desc_tokens;
>> >
>> > boost::algorithm::split(server_desc_tokens, 
>> messageInfo->destinationAddr,
>> > boost::algorithm::is_any_of(":"), boost::algorithm::token_compress_on);
>> >
>> > uv_ip4_addr(server_desc_tokens[0].c_str(),
>> > boost::lexical_cast<int>(server_desc_tokens[1]), &req_addr);
>> >
>> >
>> >         uv_loop_t   client_loop;
>> >
>> >         uv_tcp_t    tcp_connection;
>> >
>> >         uv_loop_init(&client_loop);
>> >
>> > uv_tcp_init(&client_loop, &tcp_connection);
>> >
>> > uv_tcp_keepalive(&tcp_connection, 1, 60);
>> >
>> >
>> >
>> > //prepare the data param of handle
>> >
>> > RequestInfo * ri = (RequestInfo*)std::calloc(1, sizeof(RequestInfo));
>> >
>> > ri->messageInfo = messageInfo;
>> >
>> > //exec thennection
>> >
>> > tcp_connection.data = static_cast<void*>(ri);
>> >
>> > //start the connection
>> >
>> > uv_connect_t *conn = (uv_connect_t*)malloc(sizeof(uv_connect_t));
>> >
>> > uv_tcp_connect(conn, &tcp_connection, (const struct sockaddr*)&req_addr,
>> > TCPUVClient::on_connect);
>> >
>> >         uv_run(&client_loop, UV_RUN_DEFAULT);
>> >
>> >         uv_loop_close(&client_loop);
>> >
>> > }
>> >
>> >
>> > I'm trying the case where the server is down so the on_connect method is
>> > called with status in error.
>> >
>> >
>> > void TCPUVClient::on_connect(uv_connect_t *connection, int status) {
>> >
>> > TCPUVClientLDBG << "on_connect " << status;
>> >
>> > RequestInfo *ri = static_cast<RequestInfo*>(connection->handle->data);
>> >
>> > if (status) {
>> >
>> > TCPUVClientLERR << "error on_connect" << uv_strerror(status);
>> >
>> > switch (status) {
>> >
>> > case ECONNREFUSED:
>> >
>> > TCPUVClientLERR << "ECONNREFUSED";
>> >
>> > break;
>> >
>> > default:
>> >
>> > break;
>> >
>> > }
>> >
>> >         
>> uv_close((uv_handle_t*)connection->handle,TCPUVClient::on_close);
>> >
>> >     } else {
>> >
>> >         //get the data to send
>> >
>> >         ri->serializationBuffer = 
>> ri->messageInfo->message->getBSONData();
>> >
>> >
>> >
>> >         //initialize uv buffer
>> >
>> >         uv_buf_t buf =
>> > uv_buf_init((char*)ri->serializationBuffer->getBufferPtr(), (unsigned
>> > int)ri->serializationBuffer->getBufferLen());
>> >
>> >
>> >
>> >         uv_write_t *request = (uv_write_t*)malloc(sizeof(uv_write_t));
>> >
>> >         uv_write(request, connection->handle, &buf, 1,
>> > TCPUVClient::on_write_end);
>> >
>> >     }
>> >
>> > free(connection);
>> >
>> > }
>> >
>> >
>> > the last callback called is on close
>> >
>> >
>> > void TCPUVClient::on_close(uv_handle_t* handle) {
>> >
>> > LDBG_ << "TCPUVClient::on_close";
>> >
>> >     RequestInfo *ri = static_cast<RequestInfo*>(handle->data);
>> >
>> > //free(handle);
>> >
>> >     DEALLOCATE_REQUEST_INFO(ri)
>> >
>> > }
>> >
>> >
>> > the DEALLOCATE_REQUEST_INFO macro erase all RequestInfo memory.
>> >
>> >
>> > All seems to work well except that after many connection all seems to 
>> slow
>> > down very fast... after on minute the process hang for some seconds then
>> > began to work again.
>> >
>> >
>> > All memory is released an no leak are found.  Any hints?
>> >
>> >
>> > thanks in advanced
>> >
>> >     claudio
>> >
>> > --
>> > 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 http://groups.google.com/group/libuv.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Iñaki Baz Castillo
>> <[email protected] <javascript:>>
>>
>> --
>> 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 http://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 http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to