Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 90fdbb761f80dc35d199a86af51159cf7c5545b9 1 parent 8db0f43
Andrew Thompson authored
16  elibs/git_client.erl
@@ -40,7 +40,15 @@ handle_cast(_Msg, State) ->
40 40
   {noreply, State}.
41 41
 
42 42
 
43  
-%handle_info({_SocketTyoe, Socket
  43
+handle_info({Port, {data, Data}}, #state{socket = Sock, port = Port} = State) ->
  44
+  %io:format("forwarding data to socket ~p~n", [Data]),
  45
+  gen_tcp:send(Sock, Data),
  46
+  {noreply, State};
  47
+handle_info({_SocketType, Socket, Packet}, #state{socket = Socket, port = Port} = State) when is_port(Port) ->
  48
+  %io:format("forwarding data to port ~p~n", [Packet]),
  49
+  port_command(Port, Packet),
  50
+  inet:setopts(Socket, [{active, once}]),
  51
+  {noreply, State};
44 52
 handle_info({_SocketType, Socket, <<_Length:4/binary, "git", _:1/binary, Rest/binary>>}, #state{socket = Socket} = State) ->
45 53
   [Method, Other] = binary:split(Rest, <<" ">>),
46 54
   [Args, <<"host=", Host/binary>>, <<>>] = binary:split(Other, <<0>>, [global]),
@@ -50,6 +58,8 @@ handle_info({_SocketType, Socket, _Packet}, #state{socket = Socket} = State) ->
50 58
   gen_tcp:send(Socket, "Invalid method declaration. Upgrade to the latest git.\n"),
51 59
   gen_tcp:close(Socket),
52 60
   {stop, normal, State};
  61
+handle_info({tcp_closed, Socket}, #state{socket = Socket} = State) ->
  62
+  {stop, normal, State};
53 63
 handle_info(_Info, State) ->
54 64
   io:format("unhandled info ~p~n", [_Info]),
55 65
   {noreply, State}.
@@ -77,6 +87,7 @@ dispatch_method(<<"upload-pack">>, Host, Path, #state{socket = Sock} = State) ->
77 87
               %% all validated, yay
78 88
               io:format("ready to do an upload-pack~n"),
79 89
               Port = make_port(Sock, "upload-pack", Host, Path, RealPath),
  90
+              inet:setopts(Sock, [{active, once}]),
80 91
               {noreply, State#state{port = Port}};
81 92
             false ->
82 93
               throw({noexport, RealPath})
@@ -119,7 +130,8 @@ repo_existance(Path) ->
119 130
       end
120 131
   end.
121 132
 
122  
-make_port(Sock, Method, _Host, _Path, FullPath) ->
  133
+make_port(_Sock, Method, _Host, _Path, FullPath) ->
123 134
   Command = lists:flatten(["git ", Method, " ", FullPath]),
  135
+  io:format("making port with command ~p~n", [Command]),
124 136
   open_port({spawn, Command}, [binary]).
125 137
 
5  elibs/server.erl
@@ -28,7 +28,7 @@ init_log(undefined) ->
28 28
 try_listen(0) ->
29 29
   error_logger:info_msg("Could not listen on port 9418~n");
30 30
 try_listen(Times) ->
31  
-  Res = gen_tcp:listen(9418, [list, {packet, 0}, {active, false}]),
  31
+  Res = gen_tcp:listen(9418, [binary, {packet, 0}, {active, false}]),
32 32
   case Res of
33 33
     {ok, LSock} ->
34 34
       error_logger:info_msg("Listening on port 9418~n"),
@@ -41,7 +41,8 @@ try_listen(Times) ->
41 41
     
42 42
 loop(LSock) ->
43 43
   {ok, Sock} = gen_tcp:accept(LSock),
44  
-  spawn(fun() -> handle_method(Sock) end),
  44
+  {ok, Pid} = git_client:start_link(Sock),
  45
+  gen_tcp:controlling_process(Sock, Pid),
45 46
   loop(LSock).
46 47
   
47 48
 handle_method(Sock) ->

0 notes on commit 90fdbb7

Please sign in to comment.
Something went wrong with that request. Please try again.