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/

Reply via email to