25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Fixed conversion to ezlib

This commit is contained in:
Alexey Shchepin 2013-06-17 16:33:25 +03:00
parent a616123200
commit 862a08e9eb
3 changed files with 9 additions and 28 deletions

View File

@ -1739,8 +1739,8 @@ get_conn_type(StateData) ->
case (StateData#state.sockmod):get_sockmod(StateData#state.socket) of
gen_tcp -> c2s;
tls -> c2s_tls;
ejabberd_zlib ->
case ejabberd_zlib:get_sockmod((StateData#state.socket)#socket_state.socket) of
ezlib ->
case ezlib:get_sockmod((StateData#state.socket)#socket_state.socket) of
gen_tcp -> c2s_compressed;
tls -> c2s_compressed_tls
end;

View File

@ -104,9 +104,7 @@ starttls(FsmRef, TLSOpts, Data) ->
gen_server:call(FsmRef, {starttls, TLSOpts, Data}),
FsmRef.
compress(FsmRef) ->
gen_server:call(FsmRef, compress),
FsmRef.
compress(FsmRef) -> compress(FsmRef, undefined).
compress(FsmRef, Data) ->
gen_server:call(FsmRef, {compress, Data}), FsmRef.
@ -188,22 +186,9 @@ handle_call({starttls, TLSOpts, Data}, _From, State) ->
State#state{socket = TLSSocket, sockmod = tls},
?HIBERNATE_TIMEOUT};
handle_call(compress, _From, State) ->
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
State#state.sockmod,
State#state.socket),
ejabberd_receiver:compress(State#state.receiver, ZlibSocket),
Reply = ok,
{reply, Reply, State#state{socket = ZlibSocket, sockmod = ejabberd_zlib},
?HIBERNATE_TIMEOUT};
handle_call({compress, Data}, _From, State) ->
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
State#state.sockmod,
State#state.socket),
ejabberd_receiver:compress(State#state.receiver, ZlibSocket),
catch (State#state.sockmod):send(
State#state.socket, Data),
{ok, ZlibSocket} =
ejabberd_receiver:compress(State#state.receiver, Data),
Reply = ok,
{reply, Reply,
State#state{socket = ZlibSocket, sockmod = ezlib},

View File

@ -53,7 +53,7 @@
-type sockmod() :: ejabberd_http_poll |
ejabberd_http_bind |
gen_tcp | tls | ejabberd_zlib.
gen_tcp | tls | ezlib.
-type receiver() :: pid () | atom().
-type socket() :: pid() | inet:socket() |
tls:tls_socket() |
@ -160,12 +160,7 @@ starttls(SocketData, TLSOpts, Data) ->
send(SocketData, Data),
SocketData#socket_state{socket = TLSSocket, sockmod = tls}.
compress(SocketData) ->
{ok, ZlibSocket} = ejabberd_zlib:enable_zlib(
SocketData#socket_state.sockmod,
SocketData#socket_state.socket),
ejabberd_receiver:compress(SocketData#socket_state.receiver, ZlibSocket),
SocketData#socket_state{socket = ZlibSocket, sockmod = ejabberd_zlib}.
compress(SocketData) -> compress(SocketData, undefined).
compress(SocketData, Data) ->
{ok, ZlibSocket} =
@ -181,7 +176,8 @@ reset_stream(SocketData)
when is_atom(SocketData#socket_state.receiver) ->
(SocketData#socket_state.receiver):reset_stream(SocketData#socket_state.socket).
%% sockmod=gen_tcp|tls|ejabberd_zlib
-spec send(socket_state(), iodata()) -> ok.
send(SocketData, Data) ->
case catch (SocketData#socket_state.sockmod):send(
SocketData#socket_state.socket, Data) of