Exemplo n.º 1
0
static void mcap_mdl_connected_cb(struct mcap_mdl *mdl, void *data)
{
	struct health_channel *channel = data;
	int fd;

	if (!channel->mdl)
		channel->mdl = mcap_mdl_ref(mdl);

	DBG("Data channel connected: mdl %p channel %p", mdl, channel);

	fd = mcap_mdl_get_fd(channel->mdl);
	if (fd < 0) {
		error("health: error retrieving fd");
		goto fail;
	}

	if (channel->mdep_id == MDEP_ECHO) {
		GIOChannel *io;

		io = g_io_channel_unix_new(fd);
		g_io_add_watch(io, G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_IN,
							serve_echo, channel);
		g_io_channel_unref(io);

		return;
	}

	send_channel_state_notify(channel, HAL_HEALTH_CHANNEL_CONNECTED, fd);

	return;
fail:
	/* TODO: mcap_mdl_abort */
	destroy_channel(channel);
}
Exemplo n.º 2
0
static void mdl_close(struct mcap_mdl *mdl)
{
	int fd = -1;

	printf("%s\n", __func__);

	if (mdl_disconnect_timeout >= 0)
		sleep(mdl_disconnect_timeout);

	fd = mcap_mdl_get_fd(mdl);

	if (fd > 0)
		close(fd);
}
Exemplo n.º 3
0
static void free_health_channel(void *data)
{
	struct health_channel *channel = data;
	int fd;

	DBG("channel %p", channel);

	if (!channel)
		return;

	fd = mcap_mdl_get_fd(channel->mdl);
	if (fd >= 0)
		shutdown(fd, SHUT_RDWR);

	unref_mdl(channel);
	free(channel);
}