Permalink
Browse files

bump version to v2.6.0, make check_for_gen_tcp_fix a test

  • Loading branch information...
1 parent 56a32a0 commit 92b8f5bd10ce69d40005c8e78e52db9003f0189d @etrepum etrepum committed Apr 15, 2013
Showing with 53 additions and 32 deletions.
  1. +5 −0 CHANGES.md
  2. +1 −2 rebar.config
  3. +0 −28 scripts/check_for_gen_tcp_fix.erl
  4. +1 −1 src/mochiweb.app.src
  5. +1 −1 src/mochiweb_http.erl
  6. +45 −0 test/mochiweb_http_tests.erl
View
@@ -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)
View
@@ -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,
@@ -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.
@@ -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, []},
@@ -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),
@@ -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.

0 comments on commit 92b8f5b

Please sign in to comment.