Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Message-ID: <2da66eca04092222313d8a662b@mail.gmail.com>
Date: Thu, 23 Sep 2004 15:31:39 +1000
From: Mailing List <mailingster@gmail.com>
Reply-To: Mailing List <mailingster@gmail.com>
To: cygwin@cygwin.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@mail.gmail.com> <20040923051622.GH9804@trixie.casa.cgf.cx>
X-IsSubscribed: yes

This is about as much as I can cut it down:
/***************************************************************************************/

#include	<sys/types.h>	
#include	<sys/socket.h>
#include	<netinet/in.h>
#include	<arpa/inet.h>
#include	<fcntl.h>
#include	<signal.h>
#include	<stdio.h>
#include	<stdlib.h>


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/

