mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-04 21:27:16 +02:00
* src/web/ejabberd_http_poll.erl: Completed
SVN Revision: 210
This commit is contained in:
parent
a0ae476619
commit
36f90d6a2d
|
@ -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>
|
2004-03-06 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
* src/web/: Support for HTTP Polling (JEP-0025) (almost complete)
|
* src/web/: Support for HTTP Polling (JEP-0025) (almost complete)
|
||||||
|
|
|
@ -17,7 +17,8 @@ OUTDIR = ..
|
||||||
EFLAGS = -I .. -pz ..
|
EFLAGS = -I .. -pz ..
|
||||||
OBJS = \
|
OBJS = \
|
||||||
$(OUTDIR)/ejabberd_http.beam \
|
$(OUTDIR)/ejabberd_http.beam \
|
||||||
$(OUTDIR)/ejabberd_web.beam
|
$(OUTDIR)/ejabberd_web.beam \
|
||||||
|
$(OUTDIR)/ejabberd_http_poll.beam
|
||||||
|
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
key,
|
key,
|
||||||
output = "",
|
output = "",
|
||||||
input = "",
|
input = "",
|
||||||
waiting_input = false}).
|
waiting_input = false,
|
||||||
|
timer}).
|
||||||
|
|
||||||
%-define(DBGFSM, true).
|
%-define(DBGFSM, true).
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@
|
||||||
-define(FSMOPTS, []).
|
-define(FSMOPTS, []).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
-define(HTTP_POLL_TIMEOUT, 300000).
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% API
|
%%% API
|
||||||
|
@ -63,7 +65,7 @@ recv({http_poll, FsmRef}, _Length, Timeout) ->
|
||||||
gen_fsm:sync_send_all_state_event(FsmRef, recv, Timeout).
|
gen_fsm:sync_send_all_state_event(FsmRef, recv, Timeout).
|
||||||
|
|
||||||
close({http_poll, FsmRef}) ->
|
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 = [],
|
process_request(#request{path = [],
|
||||||
|
@ -120,7 +122,10 @@ init([ID, Key]) ->
|
||||||
?INFO_MSG("started: ~p", [{ID, Key}]),
|
?INFO_MSG("started: ~p", [{ID, Key}]),
|
||||||
Opts = [], % TODO
|
Opts = [], % TODO
|
||||||
ejabberd_c2s:start({?MODULE, {http_poll, self()}}, Opts),
|
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
|
%% Func: StateName/2
|
||||||
|
@ -176,6 +181,10 @@ handle_sync_event(recv, From, StateName, StateData) ->
|
||||||
waiting_input = false}}
|
waiting_input = false}}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
handle_sync_event(stop, From, StateName, StateData) ->
|
||||||
|
Reply = ok,
|
||||||
|
{stop, normal, Reply, StateData};
|
||||||
|
|
||||||
handle_sync_event({http_put, Key, NewKey, Packet},
|
handle_sync_event({http_put, Key, NewKey, Packet},
|
||||||
From, StateName, StateData) ->
|
From, StateName, StateData) ->
|
||||||
Allow = case StateData#state.key of
|
Allow = case StateData#state.key of
|
||||||
|
@ -201,10 +210,13 @@ handle_sync_event({http_put, Key, NewKey, Packet},
|
||||||
key = NewKey}};
|
key = NewKey}};
|
||||||
Receiver ->
|
Receiver ->
|
||||||
gen_fsm:reply(Receiver, {ok, list_to_binary(Packet)}),
|
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 = ok,
|
||||||
{reply, Reply, StateName,
|
{reply, Reply, StateName,
|
||||||
StateData#state{waiting_input = false,
|
StateData#state{waiting_input = false,
|
||||||
key = NewKey}}
|
key = NewKey,
|
||||||
|
timer = Timer}}
|
||||||
end;
|
end;
|
||||||
true ->
|
true ->
|
||||||
Reply = {error, bad_key},
|
Reply = {error, bad_key},
|
||||||
|
@ -228,6 +240,10 @@ code_change(OldVsn, StateName, StateData, Extra) ->
|
||||||
%% {next_state, NextStateName, NextStateData, Timeout} |
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||||
%% {stop, Reason, NewStateData}
|
%% {stop, Reason, NewStateData}
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
|
handle_info({timeout, Timer, _}, StateName,
|
||||||
|
#state{timer = Timer} = StateData) ->
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
handle_info(_, StateName, StateData) ->
|
handle_info(_, StateName, StateData) ->
|
||||||
{next_state, StateName, StateData}.
|
{next_state, StateName, StateData}.
|
||||||
|
|
||||||
|
@ -288,3 +304,12 @@ parse_request(Data) ->
|
||||||
{ok, ID, Key, NewKey, Packet}.
|
{ok, ID, Key, NewKey, Packet}.
|
||||||
|
|
||||||
|
|
||||||
|
cancel_timer(Timer) ->
|
||||||
|
erlang:cancel_timer(Timer),
|
||||||
|
receive
|
||||||
|
{timeout, Timer, _} ->
|
||||||
|
ok
|
||||||
|
after 0 ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user