From f74fb8ea2d96dd460a8fd66dcdaf78a65ac8caac Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Tue, 8 Jul 2008 10:19:57 +0000 Subject: improve ip fetching patch SVN Revision: 1416 --- src/web/ejabberd_http_poll.erl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/web/ejabberd_http_poll.erl b/src/web/ejabberd_http_poll.erl index d93bec79..1929b146 100644 --- a/src/web/ejabberd_http_poll.erl +++ b/src/web/ejabberd_http_poll.erl @@ -101,11 +101,9 @@ sockname(_) -> {ok, ?NULL_PEER}. peername({http_poll, FsmRef}) -> - gen_fsm:send_all_state_event(FsmRef, {peername, self()}), - %% XXX should improve that, but sync call seems not possible - receive - {peername, PeerName} -> {ok, PeerName} - after 1000 -> {ok, ?NULL_PEER} + case catch gen_fsm:sync_send_all_state_event(FsmRef, peername, 1000) of + {ok, IP} -> {ok, IP}; + _ -> {ok, ?NULL_PEER} end; peername(_) -> {ok, ?NULL_PEER}. @@ -238,10 +236,6 @@ handle_event({activate, From}, StateName, StateData) -> }} end; -handle_event({peername, From}, StateName, StateData) -> - From ! {peername, StateData#state.ip}, - {next_state, StateName, StateData}; - handle_event(_Event, StateName, StateData) -> {next_state, StateName, StateData}. @@ -309,6 +303,10 @@ handle_sync_event(http_get, _From, StateName, StateData) -> Reply = {ok, StateData#state.output}, {reply, Reply, StateName, StateData#state{output = ""}}; +handle_sync_event(peername, _From, StateName, StateData) -> + Reply = {ok, {peername, StateData#state.ip}}, + {reply, Reply, StateName, StateData}; + handle_sync_event(_Event, _From, StateName, StateData) -> Reply = ok, {reply, Reply, StateName, StateData}. -- cgit v1.2.3