You need to actually read whatever data is available. On Tue, Dec 15, 2015 at 12:32 AM, <neil...@emerson.com> wrote:
> 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:p...@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...@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 > > >
_______________________________________________ gtk-list mailing list gtk-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-list