Message-Id: <200311030704.hA374FHO012847@delorie.com>
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Date: Mon, 3 Nov 2003 15:4:0 +0800
From: "zhouxin" <zhoux@harbournetworks.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: Re: Re: select() take 100% CPU with cygwin1.5.5-1 in WinXP/Win2000
Mime-Version: 1.0
Content-Type: text/plain;
      charset="GB2312"
Note-from-DJ: This may be spam
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id hA374FHO012847

I set a timeout for recvfrom() by calling select() on a UDP socket:
socket()=>sendto()=>select()=>recvfrom().
It seems that it need not call bind() or connect() for UDP socket here. 
This method is recommended by
"UNIX Network Programming Volum1 Networking APIs: Sockets and XTI(Second Edition)", W.Richard Stevens
 Chapter 13 section 2.
source code:
http://www.cs.odu.edu/~cs779/stevens2nd/lib/readable_timeo.c
http://www.cs.odu.edu/~cs779/stevens2nd/advio/dgclitimeo.c   

>>     if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
>>         fprintf(stderr, "cannot open socket for udp packet!\n");
>>         exit(1);
>>     }
>>         
>>     while(1){
>>         struct timeval    tv;
>>         fd_set            fds;

>>         radius_send(sockfd, NULL, secret);
>>         FD_ZERO(&fds);
>>         FD_SET(sockfd, &fds);
>>         
>>         tv.tv_sec  =  timeout;
>>         tv.tv_usec = 0;
>>         printf("select the socket_fd : d, thread_id is : d\n", 
>>                 sockfd, tid);
>>         if((ret=select(sockfd + 1, &fds, NULL, NULL, &tv))==1) 
>>				*rep = radius_recv(sockfd);
>>    ...
This test code is cut from a multi-thread radius(Authentication,Accounting protocol,UDP) client.
if radius thread count > 18,some thread's select() will take 100% CPU in cygwin envirionment,
but the same code work ok in solaris and linux envirionment.









>On Fri, Oct 31, 2003 at 01:14:17PM +0800, zhouxin wrote:
>> Cygwin implementation of select() take 100 CPU under multi-thread environment sometimes.
>> [...]
>>     if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
>>         fprintf(stderr, "cannot open socket for udp packet!\n");
>>         exit(1);
>>     }
>>         
>>     while(1){
>>         struct timeval    tv;
>>         fd_set            fds;
>>         
>>         FD_ZERO(&fds);
>>         FD_SET(sockfd, &fds);
>>         
>>         tv.tv_sec  =  timeout;
>>         tv.tv_usec = 0;
>>         printf("select the socket_fd : d, thread_id is : d\n", 
>>                 sockfd, tid);
>>         select(sockfd + 1, &fds, NULL, NULL, &tv);
>>     }
>
>That's not allowed.  What is the select call waiting for?  You
>didn't bind or connect it.
>
>Corinna
>
>-- 
>Corinna Vinschen                  Please, send mails regarding Cygwin to
>Cygwin Developer                                mailto:cygwin@cygwin.com
>Red Hat, Inc.
>
>--
>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>Problem reports:       http://cygwin.com/problems.html
>Documentation:         http://cygwin.com/docs.html
>FAQ:                   http://cygwin.com/faq/
>
>
>.

= = = = = = = = = = = = = = = = = = = =
			

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ
Àñ£¡
 
				 
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡zhouxin
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡zhoux@harbournetworks.com
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2003-11-03





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


