| 701 | } |
| 702 | |
| 703 | mainloop_io_t * |
| 704 | mainloop_add_fd( |
| 705 | const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks) |
| 706 | { |
| 707 | mainloop_io_t *client = NULL; |
| 708 | if(fd > 0) { |
| 709 | client = calloc(1, sizeof(mainloop_io_t)); |
| 710 | client->name = strdup(name); |
| 711 | client->userdata = userdata; |
| 712 | |
| 713 | if(callbacks) { |
| 714 | client->destroy_fn = callbacks->destroy; |
| 715 | client->dispatch_fn_io = callbacks->dispatch; |
| 716 | } |
| 717 | |
| 718 | client->channel = g_io_channel_unix_new(fd); |
| 719 | client->source = g_io_add_watch_full( |
| 720 | client->channel, priority, (G_IO_IN|G_IO_HUP|G_IO_NVAL|G_IO_ERR), |
| 721 | mainloop_gio_callback, client, mainloop_gio_destroy); |
| 722 | |
| 723 | /* Now that mainloop now holds a reference to adaptor->channel, |
| 724 | * thanks to g_io_add_watch_full(), drop ours from g_io_channel_unix_new(). |
| 725 | * |
| 726 | * This means that adaptor->channel will be free'd by: |
| 727 | * g_main_context_dispatch() or g_source_remove() |
| 728 | * -> g_source_destroy_internal() |
| 729 | * -> g_source_callback_unref() |
| 730 | * shortly after mainloop_gio_destroy() completes |
| 731 | */ |
| 732 | g_io_channel_unref(client->channel); |
| 733 | crm_trace("Added connection %d for %s[%p].%d %d", client->source, client->name, client, fd, mainloop_gio_refcount(client)); |
| 734 | } |
| 735 | |
| 736 | return client; |
| 737 | } |
| 738 | |
| 739 | void |
| 740 | mainloop_del_fd(mainloop_io_t *client) |
no test coverage detected