~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/sasl/doc/src/rel/sp.1.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-module(sp).
 
2
-vsn(1).
 
3
 
 
4
-export([start/0, get_data/0]).
 
5
-export([init/1, system_continue/3, system_terminate/4]).
 
6
 
 
7
-record(state, {data}).
 
8
 
 
9
start() ->
 
10
    Pid = proc_lib:spawn_link(?MODULE, init, [self()]),
 
11
    {ok, Pid}.
 
12
 
 
13
get_data() ->
 
14
    sp_server ! {self(), get_data},
 
15
    receive
 
16
        {sp_server, Data} -> Data
 
17
    end.
 
18
 
 
19
init(Parent) ->
 
20
    register(sp_server, self()),
 
21
    process_flag(trap_exit, true),
 
22
    loop(#state{}, Parent).
 
23
 
 
24
loop(State, Parent) ->
 
25
    receive
 
26
        {system, From, Request} ->
 
27
            sys:handle_system_msg(Request, From, Parent, ?MODULE, [], State);
 
28
        {'EXIT', Parent, Reason} ->
 
29
            cleanup(State),
 
30
            exit(Reason);
 
31
        {From, get_data} ->
 
32
            From ! {sp_server, State#state.data},
 
33
            loop(State, Parent);
 
34
        _Any ->
 
35
            loop(State, Parent)
 
36
    end.
 
37
 
 
38
cleanup(State) -> ok.
 
39
 
 
40
%% Here are the sys call back functions
 
41
system_continue(Parent, _, State) ->
 
42
    loop(State, Parent).
 
43
 
 
44
system_terminate(Reason, Parent, _, State) ->
 
45
    cleanup(State),
 
46
    exit(Reason).