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

Fredrik Svahn fredrik.svahn@REDACTED
Sun Oct 5 19:28:51 CEST 2008


Hi,

The function given as an argument to spawn/spawn_link must be exported.

See e.g. http://erlang.org/doc/getting_started/conc_prog.html#3.1

BR /Fredrik


On Sun, Oct 5, 2008 at 6:39 PM, deepblue_other <cktgatb@REDACTED> 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-tp19826465p19826465.html
> Sent from the Erlang Questions mailing list archive at Nabble.com.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081005/c19bb1b5/attachment.htm>


More information about the erlang-questions mailing list