0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

modules/client/sync: Fix sync timeout behavior.

This commit is contained in:
Jason Volk 2018-12-01 17:23:42 -08:00
parent b45b25bdcd
commit f44f1cf89d
2 changed files with 27 additions and 30 deletions

View file

@ -123,10 +123,30 @@ try
linear::handle(client, sp, top) linear::handle(client, sp, top)
}; };
if(!shortpolled) // When shortpoll was successful, do nothing else.
longpoll::poll(client, args); if(shortpolled)
return {};
return {}; // When longpoll was successful, do nothing else.
if(longpoll::poll(client, args))
return {};
// A user-timeout occurred. According to the spec we return a
// 200 with empty fields rather than a 408.
const json::value next_batch
{
lex_cast(m::vm::current_sequence), json::STRING
};
return resource::response
{
client, json::members
{
{ "next_batch", next_batch },
{ "rooms", json::object{} },
{ "presence", json::object{} },
}
};
} }
catch(const bad_lex_cast &e) catch(const bad_lex_cast &e)
{ {
@ -167,10 +187,9 @@ ircd::m::sync::longpoll::handle_notify(const m::event &event,
dock.notify_all(); dock.notify_all();
} }
void bool
ircd::m::sync::longpoll::poll(client &client, ircd::m::sync::longpoll::poll(client &client,
const args &args) const args &args)
try
{ {
++polling; ++polling;
const unwind unpoll{[] const unwind unpoll{[]
@ -181,10 +200,7 @@ try
while(1) while(1)
{ {
if(!dock.wait_until(args.timesout)) if(!dock.wait_until(args.timesout))
throw m::error return false;
{
http::REQUEST_TIMEOUT, "M_TIMEOUT", "Timed out"
};
if(queue.empty()) if(queue.empty())
continue; continue;
@ -197,28 +213,9 @@ try
}}; }};
if(handle(client, args, a)) if(handle(client, args, a))
break; return true;
} }
} }
catch(const ctx::timeout &e)
{
const ctx::exception_handler eh;
const int64_t &since
{
int64_t(m::vm::current_sequence)
};
resource::response
{
client, json::members
{
{ "next_batch", json::value { lex_cast(int64_t(since)), json::STRING } },
{ "rooms", json::object{} },
{ "presence", json::object{} },
}
};
}
bool bool
ircd::m::sync::longpoll::handle(client &client, ircd::m::sync::longpoll::handle(client &client,

View file

@ -60,7 +60,7 @@ namespace ircd::m::sync::longpoll
static std::string sync_rooms(client &, const m::user::id &, const m::room &, const args &, const accepted &); static std::string sync_rooms(client &, const m::user::id &, const m::room &, const args &, const accepted &);
static bool handle(client &, const args &, const accepted &, const m::room &); static bool handle(client &, const args &, const accepted &, const m::room &);
static bool handle(client &, const args &, const accepted &); static bool handle(client &, const args &, const accepted &);
static void poll(client &, const args &); static bool poll(client &, const args &);
static void handle_notify(const m::event &, m::vm::eval &); static void handle_notify(const m::event &, m::vm::eval &);
extern m::hookfn<m::vm::eval &> notified; extern m::hookfn<m::vm::eval &> notified;