couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [45/45] mochiweb commit: updated refs/heads/master to cb521b3
Date Tue, 25 Aug 2015 17:39:03 GMT
Don't use message queue for request handling


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/cb521b34
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/cb521b34
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/cb521b34

Branch: refs/heads/master
Commit: cb521b34cfdd38f2ff833efbd8af4dc208ee599e
Parents: 0f5a3cc
Author: Robert Newson <rnewson@apache.org>
Authored: Tue Aug 25 18:34:14 2015 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Aug 25 18:34:14 2015 +0100

----------------------------------------------------------------------
 src/mochiweb_http.erl | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/cb521b34/src/mochiweb_http.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl
index 1ea1f15..9e32d7d 100644
--- a/src/mochiweb_http.erl
+++ b/src/mochiweb_http.erl
@@ -57,26 +57,22 @@ loop(Socket, Opts, Body) ->
     request(Socket, Opts, Body).
 
 request(Socket, Opts, Body) ->
-    ok = mochiweb_socket:setopts(Socket, [{active, once}]),
-    receive
-        {Protocol, _, {http_request, Method, Path, Version}} when Protocol == http orelse
Protocol == ssl ->
+    case mochiweb_socket:recv(Socket, 0, ?REQUEST_RECV_TIMEOUT) of
+        {ok, {http_request, Method, Path, Version}} ->
             ok = mochiweb_socket:setopts(Socket, [{packet, httph}]),
             headers(Socket, Opts, {Method, Path, Version}, [], Body, 0);
-        {Protocol, _, {http_error, "\r\n"}} when Protocol == http orelse Protocol == ssl
->
+        {error, {http_error, "\r\n"}} ->
             request(Socket, Opts, Body);
-        {Protocol, _, {http_error, "\n"}} when Protocol == http orelse Protocol == ssl ->
+        {error, {http_error, "\n"}} ->
             request(Socket, Opts, Body);
-        {tcp_closed, _} ->
+        {error, closed} ->
             mochiweb_socket:close(Socket),
             exit(normal);
-        {ssl_closed, _} ->
+        {error, timeout} ->
             mochiweb_socket:close(Socket),
             exit(normal);
         Other ->
             handle_invalid_msg_request(Other, Socket, Opts)
-    after ?REQUEST_RECV_TIMEOUT ->
-        mochiweb_socket:close(Socket),
-        exit(normal)
     end.
 
 reentry(Body) ->
@@ -89,23 +85,22 @@ headers(Socket, Opts, Request, Headers, _Body, ?MAX_HEADERS) ->
     ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
     handle_invalid_request(Socket, Opts, Request, Headers);
 headers(Socket, Opts, Request, Headers, Body, HeaderCount) ->
-    ok = mochiweb_socket:setopts(Socket, [{active, once}]),
-    receive
-        {Protocol, _, http_eoh} when Protocol == http orelse Protocol == ssl ->
+    case mochiweb_socket:recv(Socket, 0, ?REQUEST_RECV_TIMEOUT) of
+        {ok, http_eoh} ->
             Req = new_request(Socket, Opts, Request, Headers),
             call_body(Body, Req),
             ?MODULE:after_response(Body, Req);
-        {Protocol, _, {http_header, _, Name, _, Value}} when Protocol == http orelse Protocol
== ssl ->
+        {ok, {http_header, _, Name, _, Value}} ->
             headers(Socket, Opts, Request, [{Name, Value} | Headers], Body,
                     1 + HeaderCount);
-        {tcp_closed, _} ->
+        {error, closed} ->
+            mochiweb_socket:close(Socket),
+            exit(normal);
+        {error, timeout} ->
             mochiweb_socket:close(Socket),
             exit(normal);
         Other ->
             handle_invalid_msg_request(Other, Socket, Opts, Request, Headers)
-    after ?HEADERS_RECV_TIMEOUT ->
-        mochiweb_socket:close(Socket),
-        exit(normal)
     end.
 
 call_body({M, F, A}, Req) ->


Mime
View raw message