Created
December 5, 2018 20:02
-
-
Save pmurias/b80128944e9a49fb97161c170ed93961 to your computer and use it in GitHub Desktop.
random erlang code from the internet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loop(Users, N) -> | |
receive | |
{connect, Pid, User, Password} -> | |
io:format("connection request from:~p ~p ~p~n", | |
[Pid, User, Password]), | |
case member({User, Password}, Users) of | |
true -> | |
Max = max_connections(), | |
if | |
N > Max -> | |
Pid ! {ftp_server, | |
{error, too_many_connections}}, | |
loop(Users, N); | |
true -> | |
New = spawn_link(?MODULE, handler, [Pid]), | |
Pid ! {ftp_server, {ok, New}}, | |
loop(Users, N + 1) | |
end; | |
false -> | |
Pid ! {ftp_server, {error, rejected}}, | |
loop(Users, N) | |
end; | |
{'EXIT', Pid} -> | |
io:format("Handler ~p died~n", [Pid]), | |
loop(Users, lists:max(N-1, 0)); | |
Any -> | |
io:format("received:~p~n",[Any]), | |
loop(Users, N) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment