Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: haitaoyao/elogserver
base: 0285a33b32
...
head fork: haitaoyao/elogserver
compare: 41b9978857
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -6,3 +6,4 @@ priv
*.plt
.settings
.project
+ebin
View
5 apps/elogserver/src/elogserver.app.src
@@ -1,6 +1,6 @@
{application, elogserver,
[
- {description, ""},
+ {description, "a simple log server"},
{vsn, "1"},
{registered, []},
{applications, [
@@ -8,5 +8,6 @@
stdlib
]},
{mod, { elogserver_app, []}},
- {env, []}
+ {env, []},
+ {start_phases, []}
]}.
View
3  apps/elogserver/src/els_config.erl
@@ -25,7 +25,8 @@ get_config(Key) when is_list(Key) ->
%% Value.
get_data_path() ->
- get_config("data_path").
+ "/tmp/elogserver".
+%% get_config("data_path").
%%
%% Local Functions
View
4 apps/elogserver/src/els_handler.erl
@@ -144,7 +144,7 @@ handle_packet(1, Data, State = #state{client_address = ClientAddress}) when is_b
Folder = "/tmp/elogserver/" ++ ClientAddress ++ "/" ++ TopicName,
FilePath = Folder ++ "/" ++ FileName,
FileId = ClientAddress ++ "##" ++ DataString,
- els_logs_repo:register_connection(FileId),
+ els_logs_repo:register_connection(FileId, self()),
{ok, IoDevice} = open_file(FilePath),
State1 = State#state{file_handle = IoDevice, file_path = FilePath, file_id = FileId},
State1;
@@ -192,7 +192,7 @@ handle_info({'DOWN', MonitorRef, process, Pid, Reason}, State = #state{recv_proc
%% Returns: any (ignored by gen_server)
%% --------------------------------------------------------------------
terminate(_Reason, _State = #state{file_id = FileId}) ->
- els_logs_repo:delete_connection(FileId),
+ els_logs_repo:delete_connection(FileId, self()),
ok.
%% --------------------------------------------------------------------
View
31 apps/elogserver/src/els_logs_repo.erl
@@ -15,7 +15,7 @@
%% --------------------------------------------------------------------
%% External exports
--export([start_link/0, register_connection/1, delete_connection/1]).
+-export([start_link/0, register_connection/2, delete_connection/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
@@ -28,11 +28,11 @@
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
-register_connection(FileId) ->
- gen_server:call(?SERVER, {register_connection, FileId}).
+register_connection(FileId, Pid) ->
+ gen_server:call(?SERVER, {register_connection, FileId, Pid}).
-delete_connection(FileId) ->
- gen_server:call(?SERVER, {delete_connection, FileId}).
+delete_connection(FileId, Pid) ->
+ gen_server:call(?SERVER, {delete_connection, FileId, Pid}).
%% ====================================================================
%% Server functions
@@ -60,23 +60,30 @@ init([]) ->
%% {stop, Reason, Reply, State} | (terminate/2 is called)
%% {stop, Reason, State} (terminate/2 is called)
%% --------------------------------------------------------------------
-handle_call({register_connection, FileId}, From, State = #state{handlers = Handlers}) ->
+handle_call({register_connection, FileId, Pid}, _From, State = #state{handlers = Handlers}) ->
case dict:find(FileId, Handlers) of
error ->
Pids = sets:new(),
- {reply, ok, State#state{handlers = dict:append(FileId, sets:add_element(From, Pids), Handlers)}};
+ {reply, ok, State#state{handlers = dict:store(FileId, sets:add_element(Pid, Pids), Handlers)}};
{ok, Val} ->
- {reply, ok, State#state{handlers = dict:append(FileId, sets:add_element(From, Val), Handlers)}}
+ {reply, ok, State#state{handlers = dict:store(FileId, sets:add_element(Pid, Val), Handlers)}}
end;
-handle_call({delete_connection, FileId}, From, State = #state{handlers = Handlers}) ->
+handle_call({delete_connection, FileId, Pid}, _From, State = #state{handlers = Handlers}) ->
case dict:find(FileId, Handlers) of
error ->
- State;
+ {noreply, State};
{ok, Val} ->
- case sets:is_element(From, Val) of
+ case sets:is_set(Val) of
true ->
- State#state{handlers = dict:store(FileId, sets:del_element(From, Val), Handlers)}
+ Value1 = sets:del_element(Pid, Val),
+ {noreply, State#state{handlers = dict:store(FileId, Value1, Handlers)}};
+ false ->
+ {noreply, State}
end
+%% case sets:is_element(From, Val) of
+%% true ->
+%% State#state{handlers = dict:store(FileId, sets:del_element(From, Val), Handlers)}
+%% end
end;
handle_call(_Request, _From, State) ->
Reply = ok,

No commit comments for this range

Something went wrong with that request. Please try again.