mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-16 17:15:55 +01:00
Remove useless loop and clean prepare_response (thanks to Christopher tofu Zorn)
1. Remove the silly loop that isnt needed, this speeds up all requests by 100 milliseconds. 2. Clean up prepare response function and add two new functions to handle out going payloads based of whether its a new session or not.
This commit is contained in:
parent
3b963c4f18
commit
bd69e3ad6c
@ -783,7 +783,7 @@ handle_http_put(Sid, Rid, Attrs, Payload, PayloadSize, StreamStart, IP) ->
|
|||||||
{buffered, _Sess} ->
|
{buffered, _Sess} ->
|
||||||
{200, ?HEADER, "<body xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
{200, ?HEADER, "<body xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
||||||
{ok, Sess} ->
|
{ok, Sess} ->
|
||||||
prepare_response(Sess, Rid, Attrs, StreamStart)
|
prepare_response(Sess, Rid, [], StreamStart)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
http_put(Sid, Rid, Attrs, Payload, PayloadSize, StreamStart, IP) ->
|
http_put(Sid, Rid, Attrs, Payload, PayloadSize, StreamStart, IP) ->
|
||||||
@ -912,9 +912,7 @@ update_shaper(ShaperState, PayloadSize) ->
|
|||||||
{NewShaperState, undefined}
|
{NewShaperState, undefined}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
prepare_response(Sess, Rid, OutputEls, StreamStart) ->
|
||||||
Rid, _, StreamStart) ->
|
|
||||||
receive after 100 -> ok end, %% TODO: Why is this needed. Argh. Bad programming practice.
|
|
||||||
case catch http_get(Sess, Rid) of
|
case catch http_get(Sess, Rid) of
|
||||||
{ok, cancel} ->
|
{ok, cancel} ->
|
||||||
%% actually it would be better if we could completely
|
%% actually it would be better if we could completely
|
||||||
@ -927,9 +925,16 @@ prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
|||||||
{200, ?HEADER, "<body type='terminate' xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
{200, ?HEADER, "<body type='terminate' xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
||||||
{ok, ROutPacket} ->
|
{ok, ROutPacket} ->
|
||||||
OutPacket = lists:reverse(ROutPacket),
|
OutPacket = lists:reverse(ROutPacket),
|
||||||
?DEBUG("OutPacket: ~p", [OutPacket]),
|
?DEBUG("OutPacket: ~p", [OutputEls++OutPacket]),
|
||||||
case StreamStart of
|
prepare_outpacket_response(Sess, Rid, OutputEls++OutPacket, StreamStart);
|
||||||
false ->
|
{'EXIT', {shutdown, _}} ->
|
||||||
|
{200, ?HEADER, "<body type='terminate' condition='system-shutdown' xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
||||||
|
{'EXIT', _Reason} ->
|
||||||
|
{200, ?HEADER, "<body type='terminate' xmlns='"++?NS_HTTP_BIND_s++"'/>"}
|
||||||
|
end.
|
||||||
|
|
||||||
|
%% Send output payloads on establised sessions
|
||||||
|
prepare_outpacket_response(Sess, _Rid, OutPacket, false) ->
|
||||||
case catch send_outpacket(Sess, OutPacket) of
|
case catch send_outpacket(Sess, OutPacket) of
|
||||||
{'EXIT', _Reason} ->
|
{'EXIT', _Reason} ->
|
||||||
{200, ?HEADER,
|
{200, ?HEADER,
|
||||||
@ -938,7 +943,10 @@ prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
|||||||
SendRes ->
|
SendRes ->
|
||||||
SendRes
|
SendRes
|
||||||
end;
|
end;
|
||||||
true ->
|
%% Handle a new session along with its output payload
|
||||||
|
prepare_outpacket_response(#http_bind{id=Sid, wait=Wait,
|
||||||
|
hold=Hold, to=To}=Sess,
|
||||||
|
Rid, OutPacket, true) ->
|
||||||
case OutPacket of
|
case OutPacket of
|
||||||
[{xmlstreamstart, _, OutAttrs} | Els] ->
|
[{xmlstreamstart, _, OutAttrs} | Els] ->
|
||||||
AuthID = exmpp_xml:get_attribute_from_list_as_list(OutAttrs, "id", ""),
|
AuthID = exmpp_xml:get_attribute_from_list_as_list(OutAttrs, "id", ""),
|
||||||
@ -954,9 +962,9 @@ prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
|||||||
attrs = StreamAttribs,
|
attrs = StreamAttribs,
|
||||||
children = StreamEls}}
|
children = StreamEls}}
|
||||||
| StreamTail] ->
|
| StreamTail] ->
|
||||||
% {xmlelement, "stream:features",
|
%% {xmlelement, "stream:features",
|
||||||
% StreamAttribs, StreamEls}}
|
%% StreamAttribs, StreamEls}}
|
||||||
% | StreamTail] ->
|
%% | StreamTail] ->
|
||||||
TypedTail =
|
TypedTail =
|
||||||
[check_default_xmlns(OEl) ||
|
[check_default_xmlns(OEl) ||
|
||||||
{xmlstreamelement, OEl} <-
|
{xmlstreamelement, OEl} <-
|
||||||
@ -965,22 +973,30 @@ prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
|||||||
declared_ns = [{?NS_XMPP_s, ?NS_XMPP_pfx}],
|
declared_ns = [{?NS_XMPP_s, ?NS_XMPP_pfx}],
|
||||||
attrs = StreamAttribs,
|
attrs = StreamAttribs,
|
||||||
children = StreamEls}] ++
|
children = StreamEls}] ++
|
||||||
% [{xmlelement, "stream:features",
|
%% [{xmlelement, "stream:features",
|
||||||
% [{"xmlns:stream",
|
%% [{"xmlns:stream",
|
||||||
% ?NS_XMPP_s}] ++
|
%% ?NS_XMPP_s}] ++
|
||||||
% StreamAttribs, StreamEls}] ++
|
%% StreamAttribs, StreamEls}] ++
|
||||||
TypedTail;
|
TypedTail;
|
||||||
StreamTail ->
|
StreamTail ->
|
||||||
[check_default_xmlns(OEl) ||
|
[check_default_xmlns(OEl) ||
|
||||||
{xmlstreamelement, OEl} <-
|
{xmlstreamelement, OEl} <-
|
||||||
StreamTail]
|
StreamTail]
|
||||||
end,
|
end,
|
||||||
|
case OutEls of
|
||||||
|
[] ->
|
||||||
|
prepare_response(Sess, Rid, OutPacket, true);
|
||||||
|
[#xmlel{name = 'stream:error'}] ->
|
||||||
|
{200, ?HEADER, "<body type='terminate' "
|
||||||
|
"condition='host-unknown' "
|
||||||
|
"xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
||||||
|
_ ->
|
||||||
BOSH_attribs =
|
BOSH_attribs =
|
||||||
[#xmlattr{name = 'authid', value = list_to_binary(AuthID)},
|
[#xmlattr{name = 'authid', value = list_to_binary(AuthID)},
|
||||||
#xmlattr{name = 'xmlns:stream', value = ?NS_XMPP_b}] ++
|
#xmlattr{name = 'xmlns:stream', value = ?NS_XMPP_b}] ++
|
||||||
case OutEls of
|
case OutEls of
|
||||||
[] ->
|
[] ->
|
||||||
[];
|
prepare_response(Sess, Rid, OutPacket, true);
|
||||||
_ ->
|
_ ->
|
||||||
[#xmlattr{name = 'version', ns = ?NS_BOSH_s, value = list_to_binary(Version)}]
|
[#xmlattr{name = 'version', ns = ?NS_BOSH_s, value = list_to_binary(Version)}]
|
||||||
end,
|
end,
|
||||||
@ -1020,7 +1036,7 @@ prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
|||||||
value = <<"true">>
|
value = <<"true">>
|
||||||
}
|
}
|
||||||
] ++ BOSH_attribs,
|
] ++ BOSH_attribs,
|
||||||
children = OutEls})};
|
children = OutEls})}
|
||||||
% {xmlelement,"body",
|
% {xmlelement,"body",
|
||||||
% [{"xmlns",
|
% [{"xmlns",
|
||||||
% ?NS_HTTP_BIND_s},
|
% ?NS_HTTP_BIND_s},
|
||||||
@ -1039,18 +1055,14 @@ prepare_response(#http_bind{id=Sid, wait=Wait, hold=Hold, to=To}=Sess,
|
|||||||
% {"from", From},
|
% {"from", From},
|
||||||
% {"secure", "true"} %% we're always being secure
|
% {"secure", "true"} %% we're always being secure
|
||||||
% ] ++ BOSH_attribs,OutEls})};
|
% ] ++ BOSH_attribs,OutEls})};
|
||||||
{error, _} ->
|
|
||||||
{200, ?HEADER, "<body type='terminate' "
|
|
||||||
"condition='host-unknown' "
|
|
||||||
"xmlns='"++?NS_HTTP_BIND_s++"'/>"}
|
|
||||||
end
|
|
||||||
end;
|
end;
|
||||||
{'EXIT', {shutdown, _}} ->
|
_ ->
|
||||||
{200, ?HEADER, "<body type='terminate' condition='system-shutdown' xmlns='"++?NS_HTTP_BIND_s++"'/>"};
|
{200, ?HEADER, "<body type='terminate' "
|
||||||
{'EXIT', _Reason} ->
|
"condition='internal-server-error' "
|
||||||
{200, ?HEADER, "<body type='terminate' xmlns='"++?NS_HTTP_BIND_s++"'/>"}
|
"xmlns='"++?NS_HTTP_BIND_s++"'/>"}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
http_get(#http_bind{pid = FsmRef, wait = Wait, hold = Hold}, Rid) ->
|
http_get(#http_bind{pid = FsmRef, wait = Wait, hold = Hold}, Rid) ->
|
||||||
gen_fsm:sync_send_all_state_event(
|
gen_fsm:sync_send_all_state_event(
|
||||||
FsmRef, {http_get, Rid, Wait, Hold}, 2 * ?MAX_WAIT * 1000).
|
FsmRef, {http_get, Rid, Wait, Hold}, 2 * ?MAX_WAIT * 1000).
|
||||||
|
Loading…
Reference in New Issue
Block a user