Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a problem with socket programming

Status
Not open for further replies.

wminghao

Programmer
May 29, 2000
24
US

I run a sample http server in an eternal loop.
I need to close the socket after I press ^c, so I use

signal(SIGTERM,cleanEXIT);
signal(SIGINT,cleanEXIT);

Then in the top of the program.
I use :

int listenfd;

void cleanEXIT()
{
close(listenfd);
/* clean up the garbage processes*/
while(waitpid(-1,NULL,WNOHANG)>0);
printf("Byebye");
exit(0);
}

But the problem is the the socket "listenfd" did not close.
I define listenfd as a global variable.
when I open it ,as :
ptnb=atoi(argv[1]);

listenfd=socket(AF_INET,SOCK_STREAM,0);

What is wrong with my program?



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top