delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/09/23/01:31:48

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <mailingster AT gmail DOT com>
Reply-To: Mailing List <mailingster AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Blocking accept() broken?
In-Reply-To: <20040923051622.GH9804@trixie.casa.cgf.cx>
Mime-Version: 1.0
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	<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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019