You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2014/02/13 17:05:57 UTC

[02/50] mochiweb commit: updated refs/heads/import-upstream to 8eb1f22

bump version to v2.6.0, make check_for_gen_tcp_fix a test


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

Branch: refs/heads/import-upstream
Commit: 92b8f5bd10ce69d40005c8e78e52db9003f0189d
Parents: 56a32a0
Author: Bob Ippolito <bo...@redivi.com>
Authored: Mon Apr 15 13:07:28 2013 -0700
Committer: Bob Ippolito <bo...@redivi.com>
Committed: Mon Apr 15 13:08:39 2013 -0700

----------------------------------------------------------------------
 CHANGES.md                        |  5 ++++
 rebar.config                      |  3 +--
 scripts/check_for_gen_tcp_fix.erl | 28 ---------------------
 src/mochiweb.app.src              |  2 +-
 src/mochiweb_http.erl             |  2 +-
 test/mochiweb_http_tests.erl      | 45 ++++++++++++++++++++++++++++++++++
 6 files changed, 53 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/92b8f5bd/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index 2ff0738..9d8a8c7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,8 @@
+Version 2.6.0 released 2013-04-15
+
+* Enable R15B gen_tcp workaround only on R15B
+  https://github.com/mochi/mochiweb/pull/107
+
 Version 2.5.0 released 2013-03-04
 
 * Replace now() with os:timestamp() in acceptor (optimization)

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/92b8f5bd/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index 8327fd7..101930a 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,7 +1,6 @@
 % -*- mode: erlang -*-
 {erl_opts, [debug_info,
-            {platform_define, "(R14|R16)", 'gen_tcp_fix'}
-           ]}.
+            {platform_define, "R15", 'gen_tcp_r15b_workaround'}]}.
 {cover_enabled, true}.
 {eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
 {dialyzer_opts, [{warnings, [no_return,

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/92b8f5bd/scripts/check_for_gen_tcp_fix.erl
----------------------------------------------------------------------
diff --git a/scripts/check_for_gen_tcp_fix.erl b/scripts/check_for_gen_tcp_fix.erl
deleted file mode 100755
index 646b548..0000000
--- a/scripts/check_for_gen_tcp_fix.erl
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env escript
-%% -*- mode: erlang -*-
-%%! -pa ../ebin
--export([main/1]).
-
-main([]) ->
-  application:start (inets),
-  mochiweb_http:start([{port, 5678},
-                       {loop,
-                        fun(Req) ->
-                          Req:respond({ 200,
-                          [ {"Content-Type", "text/html"} ],
-                          [ "<html><body>Hello</body></html>" ]
-                       })
-                       end}]),
-
-  io:format ("~p~n",[not has_bug(1000) and not has_bug(10000)]).
-
-has_bug (Len) ->
-  case
-    httpc:request (get, {"http://127.0.0.1:5678/",
-                   [{"X-Random", [$a || _ <- lists:seq(1,Len)]}]}, [], [])
-  of
-    {error,socket_closed_remotely} -> true;
-    {ok,{{"HTTP/1.1",200,"OK"}, _, "<html><body>Hello</body></html>"}} -> false;
-    {ok,{{"HTTP/1.1",400,"Bad Request"}, _, []}} -> false;
-    R -> io:format ("don't know what to make of ~p~n",[R]), undefined
-  end.

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/92b8f5bd/src/mochiweb.app.src
----------------------------------------------------------------------
diff --git a/src/mochiweb.app.src b/src/mochiweb.app.src
index 307a248..31a74b0 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.5.0"},
+  {vsn, "2.6.0"},
   {modules, []},
   {registered, []},
   {env, []},

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/92b8f5bd/src/mochiweb_http.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl
index bdfd047..931ecd0 100644
--- a/src/mochiweb_http.erl
+++ b/src/mochiweb_http.erl
@@ -50,7 +50,7 @@ loop(Socket, Body) ->
     ok = mochiweb_socket:setopts(Socket, [{packet, http}]),
     request(Socket, Body).
 
--ifndef(gen_tcp_fix).
+-ifdef(gen_tcp_r15b_workaround).
 -define(R15B_GEN_TCP_FIX, {tcp_error,_,emsgsize} ->
                  % R15B02 returns this then closes the socket, so close and exit
                  mochiweb_socket:close(Socket),

http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/92b8f5bd/test/mochiweb_http_tests.erl
----------------------------------------------------------------------
diff --git a/test/mochiweb_http_tests.erl b/test/mochiweb_http_tests.erl
new file mode 100644
index 0000000..0003451
--- /dev/null
+++ b/test/mochiweb_http_tests.erl
@@ -0,0 +1,45 @@
+-module(mochiweb_http_tests).
+-include_lib("eunit/include/eunit.hrl").
+
+-ifdef(gen_tcp_r15b_workaround).
+-define(SHOULD_HAVE_BUG, true).
+-else.
+-define(SHOULD_HAVE_BUG, false).
+-endif.
+
+has_acceptor_bug_test_() ->
+    {setup,
+     fun start_server/0,
+     fun mochiweb_http:stop/1,
+     fun has_acceptor_bug_tests/1}.
+
+start_server() ->
+    application:start(inets),
+    {ok, Pid} = mochiweb_http:start_link([{port, 0},
+                                          {loop, fun responder/1}]),
+    Pid.
+
+has_acceptor_bug_tests(Server) ->
+    Port = mochiweb_socket_server:get(Server, port),
+    [{"1000 should be fine even with the bug",
+      ?_assertEqual(false, has_bug(Port, 1000))},
+     {"10000 should trigger the bug if present",
+      ?_assertEqual(?SHOULD_HAVE_BUG, has_bug(Port, 10000))}].
+
+responder(Req) ->
+    Req:respond({200,
+                 [{"Content-Type", "text/html"}],
+                 ["<html><body>Hello</body></html>"]}).
+
+has_bug(Port, Len) ->
+  case
+    httpc:request(get, {"http://127.0.0.1:" ++ integer_to_list(Port) ++ "/",
+                        [{"X-Random", lists:duplicate(Len, $a)}]}, [], [])
+  of
+      {error, socket_closed_remotely} ->
+          true;
+      {ok, {{"HTTP/1.1", 200, "OK"}, _, "<html><body>Hello</body></html>"}} ->
+          false;
+      {ok, {{"HTTP/1.1", 400, "Bad Request"}, _, []}} ->
+          false
+  end.