<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16825" name=GENERATOR></HEAD>
<BODY>
<DIV>ok, but it's not gen_server compatible !</DIV>
<DIV> </DIV>
<DIV>James Hague wrote:</DIV>
<DIV>>
> Many examples uses the async_accept primitive from the module prim_inet.</DIV>
<DIV>>
> This primitive is not documented (low level) and might change or dissapear.</DIV>
<DIV>>
> Do you know examples which don't use it but use a "clean" solution for the blocking accept call ?</DIV>
<DIV>>
> Or could you show an elegant solution in this forum ?</DIV>
<DIV>> </DIV>
<DIV>> You could always put the blocking call into it's own process. When a</DIV>
<DIV>> connection occurs, change the port's owner and send the port in a</DIV>
<DIV>> message. (And open the port in passive mode to make sure messages</DIV>
<DIV>> aren't received before switching the owner.)</DIV>
<DIV> </DIV>
<DIV>The way I've always done it is to spawn the acceptor as:</DIV>
<DIV> </DIV>
<DIV>L = listen(...),</DIV>
<DIV>listen_loop(L).</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>listen_loop(L) - ></DIV>
<DIV> Top = self(),</DIV>
<DIV> spawn(fun() - ></DIV>
<DIV> Sock = accept(L),</DIV>
<DIV> Top ! one_more,</DIV>
<DIV> handle_sock(Sock)</DIV>
<DIV> end),</DIV>
<DIV> receive</DIV>
<DIV> one_more - ></DIV>
<DIV> listen_loop(L)</DIV>
<DIV> end.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>/klacke</DIV>
<DIV>_______________________________________________</DIV>
<DIV>erlang-questions mailing list</DIV>
<DIV>erlang-questions@erlang.org</DIV>
<DIV><A
href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</A></DIV></BODY></HTML>