caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* fork question...
@ 2005-02-25 10:20 Micha
  2005-02-25 11:02 ` [Caml-list] " Keith Wansbrough
  0 siblings, 1 reply; 3+ messages in thread
From: Micha @ 2005-02-25 10:20 UTC (permalink / raw)
  To: caml-list

hi,

below is a code piece of the ocaml-book. What I don't understand is why is 
there the second fork() ? Maybe that's a Unix question, but I saw it the 
first time in the ocaml book :-)


Michael



let establish_server server_fun sockaddr =
   let domain = domain_of sockaddr in
   let sock = Unix.socket domain Unix.SOCK_STREAM 0 
   in Unix.bind sock sockaddr ;
      Unix.listen sock 3;
      while true do
        let (s, caller) = Unix.accept sock 
        in match Unix.fork() with
               0 -> if Unix.fork() <> 0 then exit 0 ;          (* <<<< ???? *)
                    let inchan = Unix.in_channel_of_descr s 
                    and outchan = Unix.out_channel_of_descr s 
                    in server_fun inchan outchan ;
                       close_in inchan ;
                       close_out outchan ;
                       exit 0
             | id -> Unix.close s; ignore(Unix.waitpid [] id)
      done ;;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-02-25 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-25 10:20 fork question Micha
2005-02-25 11:02 ` [Caml-list] " Keith Wansbrough
2005-02-25 13:26   ` Christophe TROESTLER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).