GIOChannel + socketcan



Hello.

I am trying to handle a socketcan device in GTK.

I would like to accomplish the following:
 * create a socketcan device
 * get notified when it is ready to read
 * handle errors when it becomes unavailable. (possibly restart it)

I am trying the following:

int sfd = try_connect("can0"); //creates an socketcan fd
if(sfd!=-1){
	channel = g_io_channel_unix_new(sfd);

	g_io_channel_set_encoding( channel, NULL, NULL );
	g_io_channel_set_buffered( channel, FALSE );

	g_io_add_watch(channel,G_IO_IN|G_IO_PRI,do_can_stuff,NULL);

	g_io_add_watch(channel,G_IO_ERR|G_IO_HUP|G_IO_NVAL,do_can_error,NULL);
}

....

gboolean do_can_error( GIOChannel *source, GIOCondition condition,
gpointer data){
	g_io_channel_shutdown(source,FALSE,NULL);

	return(FALSE);
}

gboolean do_can_stuff( GIOChannel *source, GIOCondition condition,
gpointer data){

	int sfd = g_io_channel_unix_get_fd(source);

	... do some binary reading from sfd

	return(TRUE);
}

First off, can I accomplish what i want with GIO? Secondly, when i run
the above code, and remove the socketcan device, CPU usage skyrockets.
What causes this?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]