1. Fred T-H
  2. chut


Fred T-H  committed 7558ed3

working a few comments here and there hell yes

  • Participants
  • Parent commits 20f98c0
  • Branches default

Comments (0)

Files changed (2)

File src/client.erl

View file
 -define(SESSION_LIFE, 15000).
 -define(LISTEN_TIMEOUT, 40000).
+%% start/connect a user
 connect(Id) ->
     usr:start(Id, ?SESSION_LIFE),
+%% leaves the user
 disconnect(Id, Handler) ->
     usr:unsubscribe(Id, Handler).
+%% send a message to another user
 message(From, To, Message) ->
     usr:message(From, To, Message).
+%% picks messages belonging to Id
 listen(Id) ->
         {Id,Msg} -> [Msg | listen1(Id)]

File src/usr.erl

View file
     io:format("Killing user ~p. Reason: ~p~n",[UserId, Reason]),
     erlang:exit(Pid, kill).
-%% in a global lock. Make no mistake. Race condition-free.
+%% registers a new user process, or does nothing if it already is
+%% regustered
 init(UserId, TimeOut) ->
     case global:whereis_name(UserId) of
         undefined ->
+%% adds a listen handler to a gen_event and notifies the gen_fsm to track it
 subscribe(UserId) ->
     HandlerId = {usr_listen_handler, make_ref()},
     usr_dispatch_manager:add_sup_handler(UserId, HandlerId, {UserId, self(), HandlerId}),
     usr_monitor:add_handler(UserId, HandlerId),
     {ok, HandlerId}.
+%% returns a list of all the handlers attached to a given user
 subscribers(UserId) ->
+%% removes a client's listen handler from a user
 unsubscribe(UserId, HandlerId) ->
     usr_dispatch_manager:delete_handler(UserId, HandlerId, []),
     usr_monitor:delete_handler(UserId, HandlerId),
+%% Takes a message and routes it through the sending user
 message(From, To, Message) ->
     usr_dispatch_manager:notify(From, {send, To, Message}),
+%% Usually called by the dispatch handler. takes a sent message
+%% and routes it to the receiving user.
 relay(From, To, Message) ->
     usr_dispatch_manager:notify(To, {received, From, Message}),