This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Maybe a bug with sockets


Hello,

Please send your answer to ms.frings@mail.isis.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]