memcpy(chr_info->UUID, uuid, 16);
channel = g_io_channel_unix_new(fd);
+
+ chr_info->io_channel = channel;
+
g_io_channel_set_encoding(channel, NULL, NULL);
g_io_channel_set_buffered(channel, FALSE);
- g_io_channel_set_close_on_unref(channel, FALSE);
+ g_io_channel_set_close_on_unref(channel, TRUE);
g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP),
+
+ chr_info->watch_id = g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP),
bluetooth_gatt_client_notify_channel_watch_cb, chr_info);
return chr_info;
if (chr_info && !is_notify) {
BT_INFO("Already CCCD enabled. fd %d", chr_info->notify_fd);
- close(chr_info->notify_fd);
+ if (chr_info->watch_id > 0)
+ g_source_remove(chr_info->watch_id);
+
+ if (chr_info->io_channel) {
+ g_io_channel_shutdown(chr_info->io_channel, TRUE, NULL);
+ g_io_channel_unref(chr_info->io_channel);
+ }
+
+ gatt_characteristic_notify_list = g_slist_remove(gatt_characteristic_notify_list, chr_info);
+
+ g_free(chr_info);
+
return result;
}
#endif