Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to the new gen_server based connection handler (a checkout works)

  • Loading branch information...
commit 90fdbb761f80dc35d199a86af51159cf7c5545b9 1 parent 8db0f43
@Vagabond authored
Showing with 17 additions and 4 deletions.
  1. +14 −2 elibs/git_client.erl
  2. +3 −2 elibs/server.erl
View
16 elibs/git_client.erl
@@ -40,7 +40,15 @@ handle_cast(_Msg, State) ->
{noreply, State}.
-%handle_info({_SocketTyoe, Socket
+handle_info({Port, {data, Data}}, #state{socket = Sock, port = Port} = State) ->
+ %io:format("forwarding data to socket ~p~n", [Data]),
+ gen_tcp:send(Sock, Data),
+ {noreply, State};
+handle_info({_SocketType, Socket, Packet}, #state{socket = Socket, port = Port} = State) when is_port(Port) ->
+ %io:format("forwarding data to port ~p~n", [Packet]),
+ port_command(Port, Packet),
+ inet:setopts(Socket, [{active, once}]),
+ {noreply, State};
handle_info({_SocketType, Socket, <<_Length:4/binary, "git", _:1/binary, Rest/binary>>}, #state{socket = Socket} = State) ->
[Method, Other] = binary:split(Rest, <<" ">>),
[Args, <<"host=", Host/binary>>, <<>>] = binary:split(Other, <<0>>, [global]),
@@ -50,6 +58,8 @@ handle_info({_SocketType, Socket, _Packet}, #state{socket = Socket} = State) ->
gen_tcp:send(Socket, "Invalid method declaration. Upgrade to the latest git.\n"),
gen_tcp:close(Socket),
{stop, normal, State};
+handle_info({tcp_closed, Socket}, #state{socket = Socket} = State) ->
+ {stop, normal, State};
handle_info(_Info, State) ->
io:format("unhandled info ~p~n", [_Info]),
{noreply, State}.
@@ -77,6 +87,7 @@ dispatch_method(<<"upload-pack">>, Host, Path, #state{socket = Sock} = State) ->
%% all validated, yay
io:format("ready to do an upload-pack~n"),
Port = make_port(Sock, "upload-pack", Host, Path, RealPath),
+ inet:setopts(Sock, [{active, once}]),
{noreply, State#state{port = Port}};
false ->
throw({noexport, RealPath})
@@ -119,7 +130,8 @@ repo_existance(Path) ->
end
end.
-make_port(Sock, Method, _Host, _Path, FullPath) ->
+make_port(_Sock, Method, _Host, _Path, FullPath) ->
Command = lists:flatten(["git ", Method, " ", FullPath]),
+ io:format("making port with command ~p~n", [Command]),
open_port({spawn, Command}, [binary]).
View
5 elibs/server.erl
@@ -28,7 +28,7 @@ init_log(undefined) ->
try_listen(0) ->
error_logger:info_msg("Could not listen on port 9418~n");
try_listen(Times) ->
- Res = gen_tcp:listen(9418, [list, {packet, 0}, {active, false}]),
+ Res = gen_tcp:listen(9418, [binary, {packet, 0}, {active, false}]),
case Res of
{ok, LSock} ->
error_logger:info_msg("Listening on port 9418~n"),
@@ -41,7 +41,8 @@ try_listen(Times) ->
loop(LSock) ->
{ok, Sock} = gen_tcp:accept(LSock),
- spawn(fun() -> handle_method(Sock) end),
+ {ok, Pid} = git_client:start_link(Sock),
+ gen_tcp:controlling_process(Sock, Pid),
loop(LSock).
handle_method(Sock) ->
Please sign in to comment.
Something went wrong with that request. Please try again.