diff options
author | Nick Vatamaniuc <vatamane@gmail.com> | 2022-04-29 17:41:31 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2022-05-18 14:02:53 -0400 |
commit | d1b5e5fcc774b79131a0cb2d2b5868a2b8f028a5 (patch) | |
tree | e36f7863a62c5f3ded409f67e55fde1da7a8e438 | |
parent | 0bc85e9400aa78e6782c5aa2c2303876bc17d527 (diff) | |
download | couchdb-d1b5e5fcc774b79131a0cb2d2b5868a2b8f028a5.tar.gz |
Minor DRY-ing up of logic to handle hello_from_writer MP parser messages
-rw-r--r-- | src/couch/src/couch_httpd_multipart.erl | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/couch/src/couch_httpd_multipart.erl b/src/couch/src/couch_httpd_multipart.erl index ba1c79315..11ee6790e 100644 --- a/src/couch/src/couch_httpd_multipart.erl +++ b/src/couch/src/couch_httpd_multipart.erl @@ -105,8 +105,7 @@ mp_parse_atts(eof, {Ref, Chunks, Offset, Counters, Waiting}) -> abort_parsing -> ok; {hello_from_writer, Ref, WriterPid} -> - WriterRef = erlang:monitor(process, WriterPid), - NewCounters = orddict:store(WriterPid, {WriterRef, 0}, Counters), + NewCounters = handle_hello(WriterPid, Counters), mp_parse_atts(eof, {Ref, Chunks, Offset, NewCounters, Waiting}); {get_bytes, Ref, From} -> C2 = update_writer(From, Counters), @@ -139,8 +138,7 @@ mp_abort_parse_atts(_, _) -> maybe_send_data({Ref, Chunks, Offset, Counters, Waiting}) -> receive {hello_from_writer, Ref, WriterPid} -> - WriterRef = erlang:monitor(process, WriterPid), - NewCounters = orddict:store(WriterPid, {WriterRef, 0}, Counters), + NewCounters = handle_hello(WriterPid, Counters), maybe_send_data({Ref, Chunks, Offset, NewCounters, Waiting}); {get_bytes, Ref, From} -> NewCounters = update_writer(From, Counters), @@ -204,8 +202,7 @@ maybe_send_data({Ref, Chunks, Offset, Counters, Waiting}) -> maybe_send_data(NewAcc) end; {hello_from_writer, Ref, WriterPid} -> - WriterRef = erlang:monitor(process, WriterPid), - C2 = orddict:store(WriterPid, {WriterRef, 0}, Counters), + C2 = handle_hello(WriterPid, Counters), maybe_send_data({Ref, NewChunks, NewOffset, C2, Waiting}); {get_bytes, Ref, X} -> C2 = update_writer(X, Counters), @@ -216,6 +213,10 @@ maybe_send_data({Ref, Chunks, Offset, Counters, Waiting}) -> end end. +handle_hello(WriterPid, Counters) -> + WriterRef = erlang:monitor(process, WriterPid), + orddict:store(WriterPid, {WriterRef, 0}, Counters). + update_writer(WriterPid, Counters) -> case orddict:find(WriterPid, Counters) of {ok, {WriterRef, Count}} -> |