You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/07/29 17:55:15 UTC

[46/50] mochiweb commit: updated refs/heads/upstream to b66b68d

exit when setopts result is {error,closed} #152


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

Branch: refs/heads/upstream
Commit: c3fb6aed018d47a9c313daa966657a157d88dbc6
Parents: ee5ba87
Author: Bob Ippolito <bo...@redivi.com>
Authored: Sat Feb 21 12:04:01 2015 -0800
Committer: Bob Ippolito <bo...@redivi.com>
Committed: Sat Feb 21 12:04:01 2015 -0800

----------------------------------------------------------------------
 .travis.yml                |  4 ++--
 CHANGES.md                 |  5 +++++
 src/mochiweb.app.src       |  2 +-
 src/mochiweb_http.erl      | 12 ++++++------
 src/mochiweb_request.erl   |  8 ++++----
 src/mochiweb_socket.erl    |  6 +++++-
 src/mochiweb_websocket.erl |  4 ++--
 7 files changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index d9c6fd8..5052773 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@ language: erlang
 notifications:
   email: false
 otp_release:
-  - 17.1
-  - 17.0
+  - 17.4
+  - 17.3
   - R16B03-1
   - R15B03

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index 6856381..88846b0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,8 @@
+Version 2.12.2 released 2015-02-21
+
+* Close connections quietly when setopts fails with a closed socket.
+  https://github.com/mochi/mochiweb/pull/152
+
 Version 2.12.1 released 2015-02-01
 
 * Fix active_socket accounting

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/src/mochiweb.app.src
----------------------------------------------------------------------
diff --git a/src/mochiweb.app.src b/src/mochiweb.app.src
index 0ebef8f..7431224 100644
--- a/src/mochiweb.app.src
+++ b/src/mochiweb.app.src
@@ -1,7 +1,7 @@
 %% This is generated from src/mochiweb.app.src
 {application, mochiweb,
  [{description, "MochiMedia Web Server"},
-  {vsn, "2.12.1"},
+  {vsn, "2.12.2"},
   {modules, []},
   {registered, []},
   {env, []},

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/src/mochiweb_http.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl
index 897d625..cfbe0b9 100644
--- a/src/mochiweb_http.erl
+++ b/src/mochiweb_http.erl
@@ -71,14 +71,14 @@ start_link(Options) ->
     mochiweb_socket_server:start_link(parse_options(Options)).
 
 loop(Socket, Opts, Body) ->
-    ok = mochiweb_socket:setopts(Socket, [{packet, http}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, http}])),
     request(Socket, Opts, Body).
 
 request(Socket, Opts, Body) ->
-    ok = mochiweb_socket:setopts(Socket, [{active, once}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{active, once}])),
     receive
         {Protocol, _, {http_request, Method, Path, Version}} when Protocol == http orelse Protocol == ssl ->
-            ok = mochiweb_socket:setopts(Socket, [{packet, httph}]),
+            ok = mochiweb_socket:exit_if_closed(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 ->
             request(Socket, Opts, Body);
@@ -104,10 +104,10 @@ reentry(Body) ->
 
 headers(Socket, Opts, Request, Headers, _Body, ?MAX_HEADERS) ->
     %% Too many headers sent, bad request.
-    ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
+    ok = mochiweb_socket:exit_if_closed(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}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{active, once}])),
     receive
         {Protocol, _, http_eoh} when Protocol == http orelse Protocol == ssl ->
             Req = new_request(Socket, Opts, Request, Headers),
@@ -156,7 +156,7 @@ handle_invalid_request(Socket, Opts, Request, RevHeaders) ->
     exit(normal).
 
 new_request(Socket, Opts, Request, RevHeaders) ->
-    ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, raw}])),
     mochiweb:new_request({Socket, Opts, Request, lists:reverse(RevHeaders)}).
 
 after_response(Body, Req) ->

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/src/mochiweb_request.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_request.erl b/src/mochiweb_request.erl
index 3866876..3559395 100644
--- a/src/mochiweb_request.erl
+++ b/src/mochiweb_request.erl
@@ -562,10 +562,10 @@ stream_unchunked_body(Length, Fun, FunState,
 %% @spec read_chunk_length(request()) -> integer()
 %% @doc Read the length of the next HTTP chunk.
 read_chunk_length({?MODULE, [Socket, _Opts, _Method, _RawPath, _Version, _Headers]}) ->
-    ok = mochiweb_socket:setopts(Socket, [{packet, line}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, line}])),
     case mochiweb_socket:recv(Socket, 0, ?IDLE_TIMEOUT) of
         {ok, Header} ->
-            ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
+            ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, raw}])),
             Splitter = fun (C) ->
                                C =/= $\r andalso C =/= $\n andalso C =/= $
                        end,
@@ -579,7 +579,7 @@ read_chunk_length({?MODULE, [Socket, _Opts, _Method, _RawPath, _Version, _Header
 %% @doc Read in a HTTP chunk of the given length. If Length is 0, then read the
 %%      HTTP footers (as a list of binaries, since they're nominal).
 read_chunk(0, {?MODULE, [Socket, _Opts, _Method, _RawPath, _Version, _Headers]}) ->
-    ok = mochiweb_socket:setopts(Socket, [{packet, line}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, line}])),
     F = fun (F1, Acc) ->
                 case mochiweb_socket:recv(Socket, 0, ?IDLE_TIMEOUT) of
                     {ok, <<"\r\n">>} ->
@@ -591,7 +591,7 @@ read_chunk(0, {?MODULE, [Socket, _Opts, _Method, _RawPath, _Version, _Headers]})
                 end
         end,
     Footers = F(F, []),
-    ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, raw}])),
     put(?SAVE_RECV, true),
     Footers;
 read_chunk(Length, {?MODULE, [Socket, _Opts, _Method, _RawPath, _Version, _Headers]}) ->

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/src/mochiweb_socket.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_socket.erl b/src/mochiweb_socket.erl
index 1e35e15..1756b8e 100644
--- a/src/mochiweb_socket.erl
+++ b/src/mochiweb_socket.erl
@@ -7,7 +7,7 @@
 -export([listen/4,
          accept/1, transport_accept/1, finish_accept/1,
          recv/3, send/2, close/1, port/1, peername/1,
-         setopts/2, getopts/2, type/1]).
+         setopts/2, getopts/2, type/1, exit_if_closed/1]).
 
 -define(ACCEPT_TIMEOUT, 2000).
 -define(SSL_TIMEOUT, 10000).
@@ -142,3 +142,7 @@ type({ssl, _}) ->
 type(_) ->
     plain.
 
+exit_if_closed({error, closed}) ->
+    exit(normal);
+exit_if_closed(Res) ->
+    Res.

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/c3fb6aed/src/mochiweb_websocket.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_websocket.erl b/src/mochiweb_websocket.erl
index 2768a3e..ceb6bd6 100644
--- a/src/mochiweb_websocket.erl
+++ b/src/mochiweb_websocket.erl
@@ -32,7 +32,7 @@
 -endif.
 
 loop(Socket, Body, State, WsVersion, ReplyChannel) ->
-    ok = mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}])),
     proc_lib:hibernate(?MODULE, request,
                        [Socket, Body, State, WsVersion, ReplyChannel]).
 
@@ -206,7 +206,7 @@ parse_hybi_frames(Socket, <<_Fin:1,
                            _MaskKey:4/binary,
                            _/binary-unit:8>> = PartFrame,
                   Acc) ->
-    ok = mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}]),
+    ok = mochiweb_socket:exit_if_closed(mochiweb_socket:setopts(Socket, [{packet, 0}, {active, once}])),
     receive
         {tcp_closed, _} ->
             mochiweb_socket:close(Socket),