From d25bd8c1c6a8652fc0ccb69a6b64de8b4e689424 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 16 Jun 2009 18:26:36 +0000 Subject: [PATCH] Improve ip fetching patch (thanks to Christohpe Romain) SVN Revision: 2304 --- src/web/ejabberd_http_bind.erl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/web/ejabberd_http_bind.erl b/src/web/ejabberd_http_bind.erl index 17e52783a..0e2f5fe82 100644 --- a/src/web/ejabberd_http_bind.erl +++ b/src/web/ejabberd_http_bind.erl @@ -4,7 +4,7 @@ %%% Purpose : Implements XMPP over BOSH (XEP-0205) (formerly known as %%% HTTP Binding) %%% Created : 21 Sep 2005 by Stefan Strigler -%%% Id : $Id: ejabberd_http_bind.erl 674 2008-07-03 15:58:15Z cromain $ +%%% Id : $Id: ejabberd_http_bind.erl 683 2008-07-08 10:30:45Z cromain $ %%%---------------------------------------------------------------------- -module(ejabberd_http_bind). @@ -119,11 +119,9 @@ sockname(_Socket) -> {ok, ?NULL_PEER}. peername({http_bind, 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}. @@ -281,10 +279,6 @@ handle_event({activate, From}, StateName, StateData) -> last_receiver = Receiver}} 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}. @@ -622,6 +616,10 @@ handle_sync_event({http_get, Rid, Wait, Hold}, From, StateName, StateData) -> req_list = ReqList}} end; +handle_sync_event(peername, _From, StateName, StateData) -> + Reply = {ok, StateData#state.ip}, + {reply, Reply, StateName, StateData}; + handle_sync_event(_Event, _From, StateName, StateData) -> Reply = ok, {reply, Reply, StateName, StateData}.