Commits

Anonymous committed 65c5b79

Added monitoring for process where body is streamed to during partial body download

  • Participants
  • Parent commits 7915b82

Comments (0)

Files changed (1)

File src/lhttpc_client.erl

         true ->
             Response = {ok, {Status, Hdrs, self()}},
             State#client_state.requester ! {response, self(), Response},
-            read_partial_body(State, Vsn, Hdrs, body_type(Hdrs));
+            MonRef = erlang:monitor(process, State#client_state.requester),
+            Res = read_partial_body(State, Vsn, Hdrs, body_type(Hdrs)),
+            erlang:demonitor(MonRef, [flush]),
+            Res;
         false ->
             {Status, Hdrs, undefined}
     end.
 read_partial_finite_body(State = #client_state{requester = To}, Hdrs, 
         ContentLength, 0) ->
     receive
-        {ack, To} -> read_partial_finite_body(State, Hdrs, ContentLength, 1)
-        %%TODO: Timeout or monitor requester process??
+        {ack, To} -> read_partial_finite_body(State, Hdrs, ContentLength, 1);
+        {'DOWN', _, process, To, _} -> exit(normal)
     end;
 read_partial_finite_body(State = #client_state{requester = To}, Hdrs, 
         ContentLength, Window) when Window >= 0->
     State#client_state.requester ! {body_part, self(), Bin},
     receive
         {ack, To} -> read_partial_finite_body(State, Hdrs, 
-                        ContentLength - iolist_size(Bin), Window)
+                        ContentLength - iolist_size(Bin), Window);
+        {'DOWN', _, process, To, _} -> exit(normal)
     after 0 ->
         read_partial_finite_body(State, Hdrs, ContentLength - iolist_size(Bin), 
             lhttpc_lib:dec(Window))
     
 read_partial_infinite_body(State = #client_state{requester = To}, Hdrs, 0) ->
     receive
-        {ack, To} -> read_partial_infinite_body(State, Hdrs, 1)
-        %%TODO: Timeout??
+        {ack, To} -> read_partial_infinite_body(State, Hdrs, 1);
+        {'DOWN', _, process, To, _} -> exit(normal)
     end;
 read_partial_infinite_body(State = #client_state{requester = To}, Hdrs, Window) 
         when Window >= 0 ->
         Bin ->
             State#client_state.requester ! {body_part, self(), Bin},
             receive
-                {ack, To} -> read_partial_infinite_body(State, Hdrs, Window)
+                {ack, To} -> read_partial_infinite_body(State, Hdrs, Window);
+                {'DOWN', _, process, To, _} -> exit(normal)
             after 0 ->
                 read_partial_infinite_body(State, Hdrs, lhttpc_lib:dec(Window))
             end