aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2004-03-07 21:15:12 +0000
committerAlexey Shchepin <alexey@process-one.net>2004-03-07 21:15:12 +0000
commit36f90d6a2db68ab682b750ae9f83509f1db0468f (patch)
treee024fd3d4b12fc166d85f7c36aa361abe5826c7c
parent* src/web/: Support for HTTP Polling (JEP-0025) (almost complete) (diff)
* src/web/ejabberd_http_poll.erl: Completed
SVN Revision: 210
-rw-r--r--ChangeLog4
-rw-r--r--src/web/Makefile.in3
-rw-r--r--src/web/ejabberd_http_poll.erl33
3 files changed, 35 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index c3cb53e7d..7f89328bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-03-07 Alexey Shchepin <alexey@sevcom.net>
+
+ * src/web/ejabberd_http_poll.erl: Completed
+
2004-03-06 Alexey Shchepin <alexey@sevcom.net>
* src/web/: Support for HTTP Polling (JEP-0025) (almost complete)
diff --git a/src/web/Makefile.in b/src/web/Makefile.in
index 806bbed1a..fd8ec5deb 100644
--- a/src/web/Makefile.in
+++ b/src/web/Makefile.in
@@ -17,7 +17,8 @@ OUTDIR = ..
EFLAGS = -I .. -pz ..
OBJS = \
$(OUTDIR)/ejabberd_http.beam \
- $(OUTDIR)/ejabberd_web.beam
+ $(OUTDIR)/ejabberd_web.beam \
+ $(OUTDIR)/ejabberd_http_poll.beam
all: $(OBJS)
diff --git a/src/web/ejabberd_http_poll.erl b/src/web/ejabberd_http_poll.erl
index 78cd4078d..41b17fef5 100644
--- a/src/web/ejabberd_http_poll.erl
+++ b/src/web/ejabberd_http_poll.erl
@@ -33,7 +33,8 @@
key,
output = "",
input = "",
- waiting_input = false}).
+ waiting_input = false,
+ timer}).
%-define(DBGFSM, true).
@@ -43,6 +44,7 @@
-define(FSMOPTS, []).
-endif.
+-define(HTTP_POLL_TIMEOUT, 300000).
%%%----------------------------------------------------------------------
%%% API
@@ -63,7 +65,7 @@ recv({http_poll, FsmRef}, _Length, Timeout) ->
gen_fsm:sync_send_all_state_event(FsmRef, recv, Timeout).
close({http_poll, FsmRef}) ->
- gen_fsm:sync_send_all_state_event(FsmRef, close).
+ catch gen_fsm:sync_send_all_state_event(FsmRef, close).
process_request(#request{path = [],
@@ -120,7 +122,10 @@ init([ID, Key]) ->
?INFO_MSG("started: ~p", [{ID, Key}]),
Opts = [], % TODO
ejabberd_c2s:start({?MODULE, {http_poll, self()}}, Opts),
- {ok, loop, #state{id = ID, key = Key}}.
+ Timer = erlang:start_timer(?HTTP_POLL_TIMEOUT, self(), []),
+ {ok, loop, #state{id = ID,
+ key = Key,
+ timer = Timer}}.
%%----------------------------------------------------------------------
%% Func: StateName/2
@@ -176,6 +181,10 @@ handle_sync_event(recv, From, StateName, StateData) ->
waiting_input = false}}
end;
+handle_sync_event(stop, From, StateName, StateData) ->
+ Reply = ok,
+ {stop, normal, Reply, StateData};
+
handle_sync_event({http_put, Key, NewKey, Packet},
From, StateName, StateData) ->
Allow = case StateData#state.key of
@@ -201,10 +210,13 @@ handle_sync_event({http_put, Key, NewKey, Packet},
key = NewKey}};
Receiver ->
gen_fsm:reply(Receiver, {ok, list_to_binary(Packet)}),
+ cancel_timer(StateData#state.timer),
+ Timer = erlang:start_timer(?HTTP_POLL_TIMEOUT, self(), []),
Reply = ok,
{reply, Reply, StateName,
StateData#state{waiting_input = false,
- key = NewKey}}
+ key = NewKey,
+ timer = Timer}}
end;
true ->
Reply = {error, bad_key},
@@ -228,6 +240,10 @@ code_change(OldVsn, StateName, StateData, Extra) ->
%% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
+handle_info({timeout, Timer, _}, StateName,
+ #state{timer = Timer} = StateData) ->
+ {stop, normal, StateData};
+
handle_info(_, StateName, StateData) ->
{next_state, StateName, StateData}.
@@ -288,3 +304,12 @@ parse_request(Data) ->
{ok, ID, Key, NewKey, Packet}.
+cancel_timer(Timer) ->
+ erlang:cancel_timer(Timer),
+ receive
+ {timeout, Timer, _} ->
+ ok
+ after 0 ->
+ ok
+ end.
+