diff --git a/otherlibs/threads/unix.ml b/otherlibs/threads/unix.ml index 80ca75b6b..fc60121b7 100644 --- a/otherlibs/threads/unix.ml +++ b/otherlibs/threads/unix.ml @@ -844,7 +844,7 @@ let establish_server server_fun sockaddr = socket domain SOCK_STREAM 0 in setsockopt sock SO_REUSEADDR true; bind sock sockaddr; - listen sock 3; + listen sock 5; while true do let (s, caller) = accept sock in (* The "double fork" trick, the process which calls server_fun will not @@ -854,8 +854,11 @@ let establish_server server_fun sockaddr = let inchan = in_channel_of_descr s in let outchan = out_channel_of_descr s in server_fun inchan outchan; - close_in inchan; - close_out outchan + close_out outchan; + (* The file descriptor was already closed by close_out. + close_in inchan; + *) + exit 0 | id -> close s; ignore(waitpid [] id) (* Reclaim the son *) done