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

Oscar Hellström <>
Sun Oct 5 19:39:42 CEST 2008


Hi,

Calling spawn_link(Module, Function, Args) will call Module:Function(Args) as a fully qualified call. Therefore this Function has to be exported.

Best regards
----- Original Message -----
From: "deepblue_other" <>
To: 
Sent: Sunday, 5 October, 2008 9:39:41 AM GMT -08:00 US/Canada Pacific
Subject: [erlang-questions] wierd "function not used" problem - code included


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-tp19826465p19826465.html
Sent from the Erlang Questions mailing list archive at Nabble.com.

_______________________________________________
erlang-questions mailing list

http://www.erlang.org/mailman/listinfo/erlang-questions

-- 
Oscar Hellström, 
Phone:  +44 (0)798 45 44 773
Mobile: +44 (0)207 65 50 337
Web:    http://www.erlang-consulting.com




More information about the erlang-questions mailing list