[erlang-questions] making http client close connections

Chandru <>
Sun Jun 14 08:52:41 CEST 2009


Hi Joel,

If you want to achieve this using ibrowse, use the following functions:

ibrowse:spawn_worker_process/2

and then the

ibrowse:send_req_direct/4,5,6,7 functions

and then the

ibrowse:stop_worker_process/1 when you want to close the connection.

cheers
Chandru

2009/6/9 Joel Reymont <>

> I've been banging my head against this all day today, to no avail.
>
> I have a keep-alive connection that must be closed from the client side but
> I cannot for the life of me figure out how to do it!!!
>
> I start the client with a profile name
>
>    inets:start(),
>    Profile = list_to_atom(pid_to_list(self())),
>    {ok, Pid} = inets:start(httpc, [{profile, Profile}]),
>
> I supply the profile name to http:request/5
>
>    {ok, Ref} = http:request(get, {URI2, []}, [], [{sync, false}], Profile),
>
> When the time comes to shut down the connection, I use the profile name and
> cancel the request, just in case. I tried shutting down using the pid
> returned by inets:start/2 but it didn't do the trick.
>
>    http:cancel_request(State#state.ref),
>    ok = inets:stop(httpc, State#state.profile),
>
> Assuming that my profile name is 'httpc_manager_<0.83.0>', I see the
> profile being shut down (my debugging output)
>
>    Stopping <0.96.0>, ref: #Ref<0.0.0.203>
>
> Still, I see the following at the shell prompt, telling me that there's
> still a connection to the server. Note that the profile name is correct!
>
> How in the world do I make http client close all sessions belonging to the
> profile!?
>
>        Thanks, Joel
>
> ---
>
> =ERROR REPORT==== 9-Jun-2009::18:02:58 ===
> ** Generic server <0.98.0> terminating
> ** Last message in was {tcp,#Port<0.3069>,
>                            <<"HTTP/1.1 200 OK\r\nContent-Length:
> 62\r\n\r\nXXXXX.instance.script_tag_connection().data_received(\"ping\");">>}
> ** When Server state == {state,undefined,
>                            {tcp_session,
>                                {{"localhost",8081},<0.98.0>},
>                                false,http,#Port<0.3069>,1,keep_alive},
>                            undefined,undefined,undefined,undefined,
>                            {[],[]},
>                            {[],[]},
>                            keep_alive,[],nolimit,nolimit,
>                            {options,
>                                {undefined,[]},
>                                0,2,5,120000,2,disabled,enabled,false},
>                            {timers,[],#Ref<0.0.0.227>},
>                            'httpc_manager_<0.83.0>',undefined}
> ** Reason for termination ==
> ** {function_clause,
>       [{httpc_handler,handle_info,
>            [{tcp,#Port<0.3069>,
>                 <<"HTTP/1.1 200 OK\r\nContent-Length:
> 62\r\n\r\nXXXX.instance.script_tag_connection().data_received(\"ping\");">>},
>             {state,undefined,
>                 {tcp_session,
>                     {{"localhost",8081},<0.98.0>},
>                     false,http,#Port<0.3069>,1,keep_alive},
>                 undefined,undefined,undefined,undefined,
>                 {[],[]},
>                 {[],[]},
>                 keep_alive,[],nolimit,nolimit,
>                 {options,
>                     {undefined,[]},
>                     0,2,5,120000,2,disabled,enabled,false},
>                 {timers,[],#Ref<0.0.0.227>},
>                 'httpc_manager_<0.83.0>',undefined}]},
>        {gen_server,handle_msg,5},
>        {proc_lib,init_p_do_apply,3}]}
>
> ---
> Mac hacker with a performance bent
> http://www.linkedin.com/in/joelreymont
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list