[erlang-questions] using a socket to send and receive
Roberto Ostinelli
roberto@REDACTED
Thu Aug 19 18:47:29 CEST 2010
2010/8/19 Hynek Vychodil <hynek@REDACTED>:
> sock_loop(Sock, Len, Rest0) when size(Rest0) >= Len ->
> % We have enough data
> <<Data:Len,Rest1/binary>> = Rest0,
> worker_proc ! {data, Data},
> sock_loop(Sock, Len, Rest1);
> sock_loop(Sock, Len, Rest) ->
> inet:setopts(Sock, [{active, once}]),
> receive
> {http, Sock, Data} ->
> sock_loop(Sock, Len, <<Rest/binary, Data/binary>>)
> {send, DataToSend} ->
> % data received from external processes, send
> it to socket
> gen_tpc:send(Sock, DataToSend)
> sock_loop(Sock, Len, Rest)
> end.
>
> It is still too complicated?
no, definitely a considerable improvement on readability.
thank you,
r.
More information about the erlang-questions
mailing list