I have a tcp server that I'm running in a separate thread to receive log
messages and process them.
/* server */
uv_ip4_addr("127.0.0.1", PORT, &addr);
uv_tcp_init(uv_default_loop(), &lg_server);
uv_tcp_bind(&lg_server, (const struct sockaddr*) &addr, 0);
uv_listen((uv_stream_t*)&lg_server, 512, lg_connect);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
/*****/
void lg_connect(uv_stream_t* server, int status)
{
if (status == -1)
{
return;
}
uv_tcp_t *client = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));
uv_tcp_init(uv_default_loop(), client);
if (uv_accept(server, (uv_stream_t*)client) == 0)
{
uv_read_start((uv_stream_t*)client, lg_alloc, lg_read);
}
else
{
uv_close((uv_handle_t*)client, lg_close);
}
}
void lg_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf)
{
int msg_loop;
struct MESSAGES *msg_buffer;
if (nread != -1)
{
if (nread > 0)
{
msg_buffer = (struct MESSAGES *)buf->base;
msg_loop = _process_message(msg_buffer);
// If it was a shutdown message then close the queue
if (msg_buffer->id == SHUTDOWN_MESSAGE)
{
uv_close((uv_handle_t*)tcp, lg_close);
// stop run loop
uv_stop(uv_default_loop());
}
}
}
else
{
uv_close((uv_handle_t*)tcp, lg_close);
}
free(buf->base);
}
It seems to work ok but when I send a shutdown message, it is received
inside the read callback and calls uv_close and uv_stop, the default loop
is stoped and the code proceeds beyond the uv_run function. However if I
run netstat -tln I still see the socket and port active.
Does uv_close not close the socket.
--
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.