www-tools
Bengt Kleberg
bengt.kleberg@REDACTED
Fri May 14 12:22:09 CEST 2004
bry@REDACTED wrote:
...deleted
>yeah, it is the socket module giving me
>problems. can you tell me where the gen_tcp
>module is located at.
>
>
>
>
the easiest way to find out about an erlang module (one such as gen_tcp
that is included in the distribution, that is) is to use the
automatically generated search page for the Erlang man pages. created by
matthias l and available at http://www.corelatus.com/~matthias/modules.html.
this page is one of my 4 bookmarks. i use it a lot. it is very good.
if you want the patch rejected by mr amstrong (something which should,
at the very least, make you think twice about applying it :-) i have
included it below.
bengt
*** /home/eleberg/www_tools-1.0/url.erl Fri Mar 14 10:14:50 1997
--- url.erl Fri May 14 12:06:33 2004
***************
*** 67,107 ****
get_http(IP, Port, URL, [], Timeout).
get_http(IP, Port, URL, Opts, Timeout) ->
- socket:start(),
%% io:format("ip = ~p, port = ~p, url = ~p~n", [ IP, Port, URL]),
Cmd = ["GET ", URL, " HTTP/1.0\r\n\r\n", Opts, "\r\n\r\n"],
%% io:format("Cmd=~p\n", [Cmd]),
%% io:format("url_server: fetching ~p ~p ~p~n", [IP, Port, URL]),
! case catch
socket:client('STREAM','AF_INET',{IP,Port},{binary_packet,0}) of
! {'EXIT', Why} ->
! %% io:format("Socket exit:~p~n", [Why]),
! {error, {socket_exit, Why}};
{error, Why} ->
%% io:format("Socket error:~p~n", [Why]),
{error, {socket_error, Why}};
! Socket ->
! %% io:format("Socket = ~p~n", [Socket]),
! Socket ! {self(), {deliver, Cmd}},
receive_data(Socket, Timeout, list_to_binary([]))
end.
receive_data(Socket, Timeout, Bin) ->
! receive
! {Socket, {fromsocket, B}} ->
! io:format(".", []),
! receive_data(Socket, Timeout, concat_binary([Bin,B]));
! {Socket, {socket_closed, _}} ->
! Data0 = binary_to_list(Bin),
! %% io:format("Here:~p~n", [Data0]),
! {Data1, Info} = get_header(Data0, []),
! Bin1 = list_to_binary(Data1),
! {ok, Bin1};
Other ->
! {error, {socket, Other}}
! after
! Timeout ->
! {error, timeout}
! end.
get_header([$\r,$\n | T], Info) ->
header_end(T, Info);
--- 67,103 ----
get_http(IP, Port, URL, [], Timeout).
get_http(IP, Port, URL, Opts, Timeout) ->
%% io:format("ip = ~p, port = ~p, url = ~p~n", [ IP, Port, URL]),
Cmd = ["GET ", URL, " HTTP/1.0\r\n\r\n", Opts, "\r\n\r\n"],
%% io:format("Cmd=~p\n", [Cmd]),
%% io:format("url_server: fetching ~p ~p ~p~n", [IP, Port, URL]),
! case gen_tcp:connect(IP, Port,
! [binary, {packet,0}, {active, false}]) of
{error, Why} ->
%% io:format("Socket error:~p~n", [Why]),
{error, {socket_error, Why}};
! {ok, Socket} ->
! %io:format("Cmd = ~p~n", [Cmd]),
! ok = gen_tcp:send( Socket, Cmd ),
receive_data(Socket, Timeout, list_to_binary([]))
end.
receive_data(Socket, Timeout, Bin) ->
! case gen_tcp:recv( Socket, 0, Timeout ) of
! {error, closed} ->
! gen_tcp:close( Socket ),
! Data0 = binary_to_list(Bin),
! %io:format("Here:~p~n", [Data0]),
! {Data1, Info} = get_header(Data0, []),
! %io:format("There:~p~n~p~n", [Data1, Info]),
! Bin1 = list_to_binary(Data1),
! {ok, Bin1};
! {ok, B} ->
! %io:format(".", []),
! receive_data(Socket, Timeout, concat_binary([Bin,B]));
Other ->
! {error, {receive_data, Other}}
! end.
get_header([$\r,$\n | T], Info) ->
header_end(T, Info);
More information about the erlang-questions
mailing list