-module(sock_spin).

-compile(export_all).

working(Port) ->
    spin(Port, []).

broken(Port) ->
    spin(Port, [{active, false}]).

spin(Port, Opts) ->
    {ok, LSock} = gen_tcp:listen(Port, Opts),
    {ok, Sock} = gen_tcp:accept(LSock),
    ok = gen_tcp:close(LSock),
    send(Sock, list_to_binary(lists:duplicate(10000, $A))).

send(Sock, B) ->
    case gen_tcp:send(Sock, B) of
        ok    -> send(Sock, B);
        Other -> Other
    end.
