[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

help with socket programming[OFF TOPIC]



Hi,
	Sorry about the none debian specific question.

	I am writing a server which will handle all the cgi request coming
	from our website.
	My server function looks like this:

	while (1) {
		if ((NewHandle = accept(CGIHandle, (struct sockaddr *)&CGI_addr, \
		&sin_size)) == -1) {
			perror("cannot accept");
			continue;
		}

       		if (!fork() ) { /* this is the child */
			/* process the cgi request; */

			close(NewHandle);
			exit(0);
		}

		close(NewHandle); /* parent does not need this */
	}

	My problem is I have to close the NewHandle for the parent process.
	But once I did this, when another request comes
	in, accept will allocate a new file descriptor with the same number it
	allocated before, since it is thinking the last one is closed.
	If the last child process still has not finished, then I will have two
	child process with the same descriptor, and then the child
	will return the request to the wrong location.

	In my situation, the child process can take as long as 90 seconds or above,
	I really cannot afford to wait for them.

	Please help me with this problem. Thank you very much in advance.

Shao.

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


Reply to: