Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <2da66eca04092222313d8a662b@mail.gmail.com> Date: Thu, 23 Sep 2004 15:31:39 +1000 From: Mailing List Reply-To: Mailing List To: cygwin AT cygwin DOT com Subject: Re: Blocking accept() broken? In-Reply-To: <20040923051622.GH9804@trixie.casa.cgf.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <2da66eca04092222055f9bdc75 AT mail DOT gmail DOT com> <20040923051622 DOT GH9804 AT trixie DOT casa DOT cgf DOT cx> X-IsSubscribed: yes This is about as much as I can cut it down: /***************************************************************************************/ #include #include #include #include #include #include #include #include int main() { /* variable declarations */ int connfd, listenfd, flags; socklen_t clilen; struct sockaddr *cliaddr; struct sockaddr_in mysock; /* Create socket file descriptor */ listenfd = socket(AF_INET, SOCK_STREAM, 0); /* Set up socket details */ bzero(&mysock, sizeof(mysock)); mysock.sin_family = AF_INET; mysock.sin_addr.s_addr = htonl(INADDR_ANY); mysock.sin_port = htons(12201); /* Bind file descriptor to our socket */ bind(listenfd, (struct sockaddr *) &mysock, sizeof(mysock)); /* And make our socket listen for incomming conncetions */ listen(listenfd, 20); /* Set our listen socket blocking */ flags = fcntl(listenfd, F_GETFL, 0); flags = flags & ~FNDELAY; /* Turn blocking on */ fcntl(listenfd, F_SETFL, flags); /* Infinite loop waiting for connections */ for(;;) { connfd = accept(listenfd, (struct sockaddr *) cliaddr, &clilen); printf("If it were blocking, we shouldn't get here!\n"); /* Here would be a pthread_create to handle the incomming connection */ } return 0; } /***************************************************************************************/ The main point to focus on is the accept within the infinite for loop, and the fact that it gets past that and prints out the message continuously -- 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/