From: khan AT tobest DOT com (Ahn,Kyung-Hwa.) Subject: Maybe, socket() and fork() related bug. 6 Dec 1998 12:43:52 -0800 Message-ID: <19981206142030.22610.qmail.cygnus.gnu-win32@findmail.com> To: gnu-win32 AT cygnus DOT com Help me. this daemon can't disconnect child socket. After running this daemon, you can try to connect daemon by telnet. But, nerver can't disconnect. Maybe , socket() and fork() related bug. Of course, other unix os(solaris 2.x, linux 2.x) disconnect child socket fd after connected. My Com : P-II, Ram 64, Windows 95 korean version. /* this is simple echo server source */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(argc,argv) int argc; char *argv[]; { int sockfd, /* socket file descripter */ newsockfd, /* socket file descripter */ cli_len, /* for cli_addr */ childpid, /* for child process */ j; /* for temp */ char *ip; struct sockaddr_in cli_addr,serv_addr; if ( argc!=2 ) { printf("Usage : %s #port\n\n",argv[0]); exit(0); } if ( (sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0 ) { exit(0); } bzero( (char *) &serv_addr, sizeof(serv_addr) ); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons( atoi(argv[1]) ) ; if ( bind(sockfd, (struct sockaddr *) & serv_addr, sizeof(serv_addr)) <0) { exit(0); } listen ( sockfd, 5 ); while ( 1 ) { /* Wait for a connection from a cli_lent process. */ cli_len=sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) & cli_addr, &cli_len); if (newsockfd<0) perror("server: accept error"); /* Make child process */ if ( (childpid=fork()) <0 ) { perror("fork()"); } else if ( childpid==0) { /* for child */ close(sockfd); SendtoSocket(newsockfd,"Hello? Why don't you exit?\n"); exit(0); } signal(SIGCHLD, SIG_IGN); close(newsockfd); } return(0); } int SendtoSocket(sockfd,str) int sockfd; char *str; { if ( writen(sockfd,str,strlen(str)) !=strlen(str) ) perror("str_echo: writen error"); } int writen(fd,ptr,nbytes) register int fd; register char *ptr; register int nbytes; { int nleft, nwritten; nleft=nbytes; while ( nleft>0 ) { nwritten=write(fd,ptr,nleft); if ( nwritten <=0 ) return(nwritten); /* error */ nleft -= nwritten; ptr += nwritten; } return (nbytes - nleft); } - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".