[erlang-questions] wierd "function not used" problem - code included

deepblue_other cktgatb@REDACTED
Sun Oct 5 18:54:32 CEST 2008


this version that I pasted here is data_process/2 and in spawn_link() Im
using data_process/1, but thats just an error that i made when pasting the
code... Im compiling with:
spawn_link(?MODULE, data_process,[Socket,[]]), so the aritiy is correct


deepblue_other wrote:
> 
> Hello, its me again...
> so I've been having this problem for days, with the bellow code. Most of
> it is straight out of the "Programming Erlang" book from Joe Armstrong...
> however when Im compiling it its telling me that the function
> data_process/1 is not being used, gives me a warning, but then still
> compiles. however when Im sending data from a client side via TCP ofcourse
> it exits on me because there's nothing to process the message... 
> 
> I HAVE NO IDEA WHAT'S WRONG WITH IT. 
> I've read up on all the spawn_link() definitions and as far as I can tell
> Im using it correctly... the PiD that spawn_link() returns is being
> returned so it executes successfully. 
> please help out, its stalling my project progress. 
> thanks
> 
> 
> -module(tcp_manager).
> %API--------------------------------------------
> -export([start/1]).
> %-----------------------------------------------
> start(Port) ->
>     {ok, ListeningSocket} = 
>         gen_tcp:listen( Port, [ binary, %receive data in binary form
>                                       {packet   , 0},
>                                       {reuseaddr, true},
>                                       %hybrid - active for only one
> message
>                                       %it auto-receives one message after
> which it blocks
>                                       %has to be set to active-once again
> to receive the next message
>                                       {active   , once} ] ),
>     accept_connection(ListeningSocket).
> %-----------------------------------------------  
> accept_connection(ListeningSocket) ->
>     
>     io:format("waiting to accept~n"),
>     {ok, Socket} = gen_tcp:accept(ListeningSocket),
>     io:format("Socket is:~p~n", [Socket]),
> 
>     %-----------------------------------------------
>     Listen_for_errors = 
>         fun() ->
>             io:format("listening started~n"),
>             receive
>     	    {'EXIT', Pid, Why} -> 
>                io:format("~p exited because:~p", [Pid,Why]);
>     	    Other                 ->
>                io:format("Other:~p~n", [Other])
>             end
>         end,
> 	Listen_for_errors(),
> 	%-----------------------------------------------
>     
>     Handler_process = spawn_link(?MODULE, data_process, [Socket]), %,[]]),
>     io:format("handlers process ID:~p", [Handler_process]).
> 
>     accept_connection(ListeningSocket).
> %-----------------------------------------------
> data_process( Socket, DataSoFar) ->
>     io:format("responder_loop() entered~n"),
>     
>     receive
>         {tcp, Socket, Data}  ->
>             %Source_ip = inet:peername(Socket),
>             %io:format("*~p - data coming in:~p~n",[Source_ip,Data]),
> 	     io:format("works - Data:~p~n", [Data]),
>             %has to be done, since its an active-once socket
>             inet:setopts( Socket, [{active,once}] ),
>             data_process( Socket, 
>                                 %append the new binary fragment to what
> has been received so far
>                                 [Data | DataSoFar] );
> 
>         {tcp_closed, Socket} ->
>             io:format("*client socket closed~n");
>             %reverse because data has been appended to the head of the
> list as it was coming in
>             list_to_binary(lists:reverse(SoFar));
>     	Other                ->
> 	    io:format("undefined message came in:~p", [Other])
>     end.
> %-----------------------------------------------   
> 

-- 
View this message in context: http://www.nabble.com/wierd-%22function-not-used%22-problem---code-included-tp19826465p19826635.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list