windows - Monitoring UDP socket in glib(mm) eats up CPU time -


I have a GTKmm Windows application (built with Minzid) which gets UDP packet (no send) . The socket is the original winsock and I use the glibmm IOChannel to connect to the main loop application. The socket is read from Revoft.

My problem is this: This setup accounts 25% percent CPU time on a 3GHz workstation. Can anyone tell me?

In this case the application is inactive, and if I remove the UDP code, the CPU usage goes up to almost zero as the application has to perform some CPU intensive tasks, I spend 25% of the image

Here are some code excerpts: (sorry for printf;))

  / * Tie * / Zero UDPInterface :: BindToPort (unsigned mini port) {struct sockaddr_in target; WSADATA wsaData; Target.sin_family = AF_INET; Target.sin_port = htons (port); Target.sin_addr.s_addr = 0; If (WSAStartup (0x0202, and wsaData)) {printf ("WSAStartup failed! \ N"); Exit (0); // :) WSACleanup (); } Sock = socket (AF_INET, SOCK_DGRAM, 0); If (maus == INVALID_SOCKET) {printf ("illegal socket! \ N"); Exit (0); } If the (bund (sock, (stroke socadra *) and target, size (straight sockaddr_in)) == SOCKET_ERROR {printf ("failed to bind to port! \ N"); Exit (0);} Printf "[UDPInterface :: bindToPort] Port% i \ n", listening on the port);} / * Reading * / Bull UDPInterface :: UDPEvent (glib :: IOCondition io_condition) {recvfrom (sock, (four *) buf, BUF_SIZE * 4, 0, zero, faucet); / * Process packet ... * * * * * Glibmm Connect * / Glib :: RefPtr Channel = Globe :: IOChannel :: create_from_win32_socket (udp.sock); Glib :: Signal_O () Connect (sigc :: mem_fun (udp, and UDPInterface :: UDPEvent), Channel, Globe :: IO_IN);  

I In any other question and even Global Documents (g_io_channel_win32_new_socket ()), the socket has been inserted into non-blocking mode, and this is a "side effects of implementation and inevitable" explain this CPU effect Is it unclear to me?

I'm using glib to use Sibas or do not seem to have much difference in calling directly to reverseform () Also the handler is applied before reading and packet arrival. In addition to glibmm docs state that recvfrom () is OK to call, even if the socket is polled (Glib :: IOChannel :: create_from_win32_socket ())

I have tried to compile with the program And GP built GPRF function with CPU usage report It was not useful because my schedule has not been spent, but in some external glib / glibmm dll.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -