My network_server program take all my cpu time

익명 사용자의 이미지

my network program is simeple chatting program useing fork() in linux-c.

"top" says >> myprogram take all my com'resource (almost 99% cputime).

below is source.

---------------------------
....
basic connect socket

while(1)
{
read message client;
send message all connected client
}

The end;

----------------
Above program is always top_cpu_time when have no connected client.

How do i solve?

익명 사용자의 이미지

while (true)
{
...
}

무한 루프를 돌고 있기 때문입니다. 뭐 사용자 입장에서는 쓸데없는 문장
이지만 cpu에서는 뭔가 하고 있는 거죠. ^^;

익명 사용자의 이미지


;while(1)
;{
; read message client;
; send message all connected client
;}

위의 문장에서 "read message client"의 문장을 알 수가 없네요.
만약 read에서 data의 도착을 알기위해 "select/poll"을 쓴다면
많은 해결이 있을 겁니다. 단 window의 select는 unix/linux와는
달리 fds = 0일때는 tv의 값과 상관없이 즉시 return을 하기
때문에 connect된 fds = 0일때 다른 방법을 사용해야 합니다.