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].
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