diff --git a/CHANGES.md b/CHANGES.md index 2ff07388..9d8a8c70 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) diff --git a/rebar.config b/rebar.config index 8327fd7a..101930ab 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, diff --git a/scripts/check_for_gen_tcp_fix.erl b/scripts/check_for_gen_tcp_fix.erl deleted file mode 100755 index 646b548e..00000000 --- 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"} ], - [ "Hello" ] - }) - 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"}, _, "Hello"}} -> false; - {ok,{{"HTTP/1.1",400,"Bad Request"}, _, []}} -> false; - R -> io:format ("don't know what to make of ~p~n",[R]), undefined - end. diff --git a/src/mochiweb.app.src b/src/mochiweb.app.src index 307a2489..31a74b01 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, []}, diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl index bdfd0476..931ecd0e 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), diff --git a/test/mochiweb_http_tests.erl b/test/mochiweb_http_tests.erl new file mode 100644 index 00000000..00034519 --- /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"}], + ["Hello"]}). + +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"}, _, "Hello"}} -> + false; + {ok, {{"HTTP/1.1", 400, "Bad Request"}, _, []}} -> + false + end.