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

Re: how to implement multiple child "accept" within one socket..



On Fri, 27 Mar 1998, Won-Ho Kye wrote:

> I am implementing the server application which have serval child
> process.
> Like this
> 
> [parent]
>     |
>     +------+------+---+
>     |          |          |     |
>    child1    child2    ... ....
> 
> The childs are forked from parent.
> I oberved if the each child accept the socket simultaneous,
> then the "accept" failed..
> Then I use the semophore to prevent simultaneous acception between
> child processes.
> Is there other efficient method?

Wow, looks like my homework.  See if this makes sense:
1) accept the connection in the parent
2) fork the child
3) close the listener fd in the child and do stuff with the accept fd
4) close the accept fd in the parent and wait on the listener fd

This way you only have one thing doing the accepts and the children doing
all the data transfers.  You'll also want something like a wait3 at the
end or a "signal based reaper" as my teacher calls it:

void reaper() {
  while(wait3(NULL< WNOHANG, 0) > 0);
}
signal (SIGCHILD, reaper);



-----
Brandon Mitchell <bhmit1@mail.wm.edu>   "We all know linux is great... it
PGP: finger -l bhmit1@cs.wm.edu          does infinite loops in 5 seconds"
Phone: (757) 221-4847                      --Linus Torvalds



--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: