Hi, Paul
Thank you for your reply. I don’t know how to clean the “data ready†condition on the socket. Please help me know how to do it.
Â
Thanks
Neil
Â
From: Paul Davis [mailto:paul linuxaudiosystems com]
Sent: Tuesday, December 15, 2015 11:33 AM
To: Wu, Neil [CLIMATE/RS/CN]
Cc: ML-gtk
Subject: Re: After use g_io_add_watch , the cpu usage to 100%Â
You're probably not clearing the "data ready" condition on the socket in the callback. As soon as you return to main event loop, the socket still has data ready.
Â
On Mon, Dec 14, 2015 at 10:07 PM, <Neil Wu emerson com> wrote:
Hi, all
Â
I upload the glib-2.0 library from 2.38.2 to 2.44.1, then the cpu usage to 100%.
After testing , I find the problem is caused by g_io_add_watch function. Following is the part code about the glib.
Â
              struct sockaddr_can addr;
               struct ifreq ifr;
               int loopback = 0;
               gint fd;
               GIOChannel *io;
               guint ev_id;
Â
               if (getenv("CANLOOPBACK"))
                               loopback = 1;
Â
               memset(&addr, 0, sizeof(addr));
               memset(&ifr, 0, sizeof(ifr));
               fd = socket(PF_CAN, SOCK_RAW, CAN_RAW)                  Â
Â
               addr.can_family = AF_CAN;
Â
               strcpy(ifr.ifr_name,â€can0â€);
ioctl(fd, SIOCGIFINDEX, &ifr
               addr.can_ifindex = ifr.ifr_ifindex;
Â
               setsockopt(dcan->fd, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback));
Â
                bind(dcan->fd, (struct sockaddr *) &addr, sizeof(addr))
                io = g_io_channel_unix_new(fd);
               g_assert(io);
               g_io_channel_set_encoding(io, NULL, NULL);
               g_io_channel_set_buffered(io, FALSE);
               ev_id = g_io_add_watch(io, G_IO_IN, NULL, NULL); / ev_id = g_io_add_watch(io, G_IO_IN, my_function, NULL);
Â
If any people know how to solve the problem, or any information may lead to this problem, please tell me . Â Â Thanks very much
Â
Neil
Â
Â
_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-listÂ