libuv: ¿cómo salir correctamente de la aplicación en caso de error?

I have an application which uses libuv library. it runs default loop:


How can the application be gracefully exited in case of a failure? Currently I am doing it like in the following example:

uv_tcp_t* tcp = malloc(sizeof(uv_tcp_t));
int r = uv_tcp_init(uv_default_loop(), tcp);

if (r) {

debería uv_loop_delete function be called? What does it do? Does it drop all pending callback functions? Does it close all currently opened TCP connections? Do I have to do it manually before exiting?

P.S.: Can't add the tag 'libuv' (less than 1500 reputation). Can somebody create and add it?

preguntado el 31 de enero de 12 a las 08:01

Please edit the description of libuv, I am not 100% sure what libuv means. -

thanks! edited. can you review it please? -

probably because stackoverflow crashed when I saved the description. Now it doesn't show me the link to edit wiki. Here is excerpt and description that I added: Excerpt: "platform layer for node.js" Description: "libuv is a platform layer for node.js. Its purpose is to abstract IOCP on Windows and libev on Unix systems. It is intended to eventually contain all platform differences in this library. [libuv on github][1] [1] -

Ah, I don't have tag the rep to edit tag descriptions either, I can only create tags. -

1 Respuestas

Declaration of uv_loop_delete is aquí and source code is aquí. Se parece a esto:

void uv_loop_delete(uv_loop_t* loop) {
  uv_ares_destroy(loop, loop->channel);
#if __linux__
  if (loop->inotify_fd == -1) return;
  ev_io_stop(loop->ev, &loop->inotify_read_watcher);
  loop->inotify_fd = -1;
  if (loop->fs_fd != -1)

It will, effectively, clean every file descriptor it's possible to clean. It will close TCP connection, Inotify connections, Socket used to read events, Pipe fds, etc, etc.

=> Yes, this function will close everything you have opened through libuv.

NB: Anyway, when your application exit, your Operating System will clean and close everything you have left open, without any mercy.

contestado el 18 de mayo de 12 a las 20:05

Sounds logical. OS should release all resources. Thanks Coren - Andrei Sedoi

Does this answer still apply for releases 1.x and beyond? - David

@dave yes. uv_loop_delete now calls uv_loop_close which is, in 1.x version, the main entry point for closing everything. - Coren

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.