inet_drv.c

Klacke klacke@REDACTED
Thu Mar 6 11:25:13 CET 2003


The patch I send with lukes code that showed an error in
inet_drv.c wasn't correct.

Martin B and I have spent a couple of days !!! trying 
to get the patch right. Hard. 
The problem is that it isn't that easy to restart the
input when a single crnl is found in http_message().

We settled on:


***************
*** 1914,1920 ****
      int c;
      /* start-line = Request-Line | Status-Line */
      if (n == 0)
!       return 0;
      h = 0;
      meth_ptr = ptr;
      while (n && !is_tspecial((unsigned char)*ptr)) {
--- 1914,1920 ----
      int c;
      /* start-line = Request-Line | Status-Line */
      if (n == 0)
!       return -1;
      h = 0;
      meth_ptr = ptr;
      while (n && !is_tspecial((unsigned char)*ptr)) {


So when http_message get crnl (only) it return -1
and {http_error, Socket "\r\n"} will be returned
all the way up to the HTPP app.




> %%%----------------------------------------------------------------------
> %%% File    : inetleak.erl
> %%% Author  : Luke Gorrie <luke@REDACTED>
> %%% Purpose : Test case for inet_driver leaking file descriptors
> %%% Created :  3 Mar 2003 by Luke Gorrie <luke@REDACTED>
> %%%----------------------------------------------------------------------
> 
> %% go/1 starts a server, and test_client/1 connects to that server and
> %% hangs it with a malformed HTTP request.
> 
> -module(inetleak).
> -author('luke@REDACTED').
> 
> -compile(export_all).
> %%-export([Function/Arity, ...]).
> 
> go(Port) ->
>     spawn_link(fun() ->
> 		       {ok, L} = gen_tcp:listen(Port, [{active, false},
> 						       binary,
> 						       {reuseaddr, true},
> 						       {packet, http}]),
> 		       accept_loop(L)
> 	       end).
> 
> accept_loop(L) ->
>     case gen_tcp:accept(L) of
> 	{ok, S} ->
> 	    worker(S);
> 	Err ->
> 	    exit({accept, Err})
>     end.
> 
> worker(S) ->
>     io:format("~p trying a read with timeout..~n", [self()]),
>     case gen_tcp:recv(S, 0, 30000) of
> 	{ok, Data} ->
> 	    io:format("~p got ~p~n", [self(), Data]),
> 	    worker(S);
> 	{error, Rsn} ->
> 	    io:format("~p error: ~p~n", [self(), Rsn])
>     end.
> 
> 
> test_client(Port) ->
>     {ok,S} = gen_tcp:connect("localhost", Port, [{active,false}, binary]),
>     ok = gen_tcp:send(S, "\r\n"),
>     ok = gen_tcp:close(S).
> 


-- 
Claes Wikstrom                        -- Caps lock is nowhere and
Alteon WebSystems                     -- everything is under control          
http://www.bluetail.com/~klacke      
cellphone: +46 70 2097763



More information about the erlang-patches mailing list