OK. So after the uv_run() I call

uv_close((uv_handle_t*) &lg_server, 0);

 Now when I check with netstat the socket is closed. Thanks. One down. 
However this code is inside a .so library which does not get unloaded after 
the shutdown. Now when it gets called again to startup I get the following 
when the uv_run() is called again

java: src/unix/core.c:178: uv__finish_close: Assertion `handle->flags & 
UV_CLOSING' failed.

I suspect the default loop needs to be re initialised but when I tried to 
uv_delete_loop(uv_default_loop()) after shutting down the server I got the 
following:

java: src/unix/loop.c:93: uv_loop_delete: Assertion `uv_loop_close(loop) == 
0' failed.

Both these cases caused other problems with the .so library code so some 
other memory is being touched.

Any thoughts
 
John

On Sunday, 18 May 2014 06:26:41 UTC-5, Saúl Ibarra Corretgé wrote:
>
> -----BEGIN PGP SIGNED MESSAGE----- 
> Hash: SHA1 
>
> On 05/18/2014 05:24 AM, John Preston wrote: 
> > 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. 
> > 
>
> Yes, uv_close does close the socket. I had a quick look and I don't 
> see where you are closing the server, so that socket will remain open, 
> even if the loop is stopped. 
>
>
> Cheers, 
>
> - -- 
> Saúl Ibarra Corretgé 
> bettercallsaghul.com 
>
> -----BEGIN PGP SIGNATURE----- 
> Version: GnuPG v1 
> Comment: Using GnuPG with Icedove - http://www.enigmail.net/ 
>
> iQIcBAEBAgAGBQJTeJjxAAoJEEEOVVOum8BZnM0P/2+Fzqn/WU9Nm7S0JnGJzYv1 
> 2ipm+z/cItQy0cfPn+0rF0NdlGAJfPOlJzSvqEohGrRegRXTukUI5rhF7o2INwr2 
> MXr5+UDQaYP7Ea9E/D9+wZMXccccgrKSIwHciGsrpw2G1DxFn8FrNinnWyTb5N+V 
> 2dVaSDolrUsXtzapZvyOzk2NaaD8kk6iXGKHUEWIq7jT5NOAbQIm63F9SivOkMMR 
> j4BeZMOx53aL+RdkiJn/8gLUqmyhd46FOVYkxLnj8X60k7VPJw4sttG6HA4oejWH 
> ebUFb2nNbRAztPUX11qsZtABk6TO4oxV6HpzOYjQ9gi83k/awEOLCglPMSW+NdJ8 
> brYfyrB71htlMSswsZKOmQoTgbKPedzeI77LpwqQe0RM2e0cE06MCtLu8qldccHe 
> o44Bof77YhwAqhHJQotb5o0nQtsceGvbmnu3l8TphVeKGZvJYjlvM1FyMdmMCWiS 
> wymJpG2wuokmqF2BaxyNN0Sw+etjEeLgjtFl8NWf4CYD1Tg3mf1+MRgZMP4QObIy 
> m/BRLqNCNSGUNfqOPRYg5NRKZDfetMTx3Q79MVF5x7Cw55C7uzgVqsI6j6LrDdWz 
> hInUjrCxEgSjsUuhMGlhpQZsFcSpNA23zo4bpC6jrIWh3jZh9aQLJePgRyYXyR8+ 
> 6pBzBqB8rYTG8WOJ3DkH 
> =AvJj 
> -----END PGP SIGNATURE----- 
>

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