![]() |
| | #1 |
| Registered User Join Date: Jul 2002
Posts: 3
| cpu resources. I believe there's something wrong with my main loop, but can't seem to fix it, even though I gone to various measures to find the source of the problem. Tutorials on the subject suggests that my method is already pretty efficient, though I can't be sure. Anyone has time, please look at the code attached and give me comments please? Thanks! Teng Junbin void MainLoop(int sockfd) { fd_set rea_set, err_set; static struct timeval nulltime; for (;;) { // Check for incoming data and errors FD_ZERO(&rea_set); FD_ZERO(&err_set); FD_SET(fileno(stdin), &rea_set); FD_SET(sockfd, &rea_set); FD_SET(sockfd, &err_set); if (select(fileno(stdin) > sockfd ? fileno(stdin) + 1 : sockfd + 1, &rea_set, NULL, &err_set, &nulltime) < 0) { puts("ERROR: Unable to pool incoming data and errors\n"); puts(CONNECTIONCLOSED); close(sockfd); exit(3); } // Check for error in connection if (FD_ISSET(sockfd, &err_set)) { // Disconnected close(sockfd); puts(CONNECTIONCLOSED); break; } else { // Get server input if (FD_ISSET(sockfd, &rea_set)) { if (!ProcessData(sockfd)) { // Disconnected close(sockfd); puts(CONNECTIONCLOSED); break; } } // Get keyboard input if (FD_ISSET(fileno(stdin), &rea_set)) { if (!ProcessData(fileno(stdin)) { // IO Error puts("ERROR: Unable to read from stdin\n\n"); close(sockfd); exit(5); } } } } }[quote] |
| junbin is offline | |
| | #2 |
| Im back! Join Date: Jun 2002 Location: Bangalore, India
Posts: 345
| Are there more processes running when you get this 99%? And is this 99% constant throughout till this proram is alive? If no, it's just common, try running more processes simultanesouly and check to see if you still get this 99% for this program, if you do, there's some serious problem, while the code looks optimized. |
| shaik786 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HPUX sockets vs Linux? | cpjust | Linux Programming | 4 | 12-06-2007 02:51 PM |
| A table for errno values by linux sockets? | hardi | Networking/Device Communication | 2 | 12-20-2006 02:10 PM |
| Segfault with C sockets on Linux | arti_valekar | C Programming | 3 | 02-16-2005 02:25 AM |
| Problems with sockets under linux | principii | Linux Programming | 5 | 09-18-2004 03:09 PM |