delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/01/09/12:33:24

Message-Id: <200201091733.g09HXMu02464@delorie.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: Stefan Frings <s DOT frings AT mail DOT isis DOT de>
To: cygwin AT cygwin DOT com
Subject: Maybe a bug with sockets
Date: Wed, 9 Jan 2002 18:32:12 +0100
X-Mailer: KMail [version 1.3.1]
MIME-Version: 1.0

Hello,

Please send your answer to ms DOT frings AT mail DOT isis DOT de because I do not read the 
mailing list very often. Thanks.

I think I found a bug in cygwin. I open a socket connection and start a 
child process after that. Then I cannot close the socket. The following is 
a reduced source code with that problem. It works fine on Linux but not on 
CygWin.

Compile and run it. The use "telnet localhost 80" to test it. You should 
see the message "Hello" and then a disconnect message. But the disconnect 
message is missed until you kill the child process.



#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <errno.h>

#define PORT 80                         // Port for TCP/IP Sockets


int main(int argc,char** argv)
{
  struct sockaddr_in address;
  int sock;
  sock=socket(PF_INET,SOCK_STREAM,0);
  setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,0,0);
  address.sin_family=AF_INET;
  address.sin_port=htons(PORT);
  memset(&address.sin_addr,0,sizeof(address.sin_addr));
  bind(sock,(struct sockaddr *) &address,sizeof(address));
  listen(sock,5);
  {
    size_t addrlength;
    int verbindung;
    addrlength=sizeof(address);
    verbindung=accept(sock,(struct sockaddr *) &address,&addrlength);
    if (verbindung>=0)
    {
      printf("Verbindung aufgebaut\n");
      write(verbindung,"Hello\n",6);


      if (fork()==0)
              {
                // Child
                close(verbindung);
                while (1)
                {
                  printf("Child is running\n");
                  sleep(3);
                }
                exit(0);
              }
      else
      {
        // Mother
        close(verbindung);
      }


    }
  }
  return 0;
}

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.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