Skip to content

Commit 60d0064

Browse files
author
Scott Powell
committed
* room server: new posts now delayed by 6 seconds before syncing to clients
1 parent 478a57a commit 60d0064

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

examples/simple_room_server/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ struct PostInfo {
123123
#define PUSH_TIMEOUT_BASE 4000
124124
#define PUSH_ACK_TIMEOUT_FACTOR 2000
125125

126+
#define POST_SYNC_DELAY_SECS 6
127+
126128
#define CLIENT_KEEP_ALIVE_SECS 0 // Now Disabled (was 128)
127129

128130
#define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS
@@ -861,13 +863,15 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
861863
bool did_push = false;
862864
if (client->pending_ack == 0 && client->last_activity != 0 && client->push_failures < 3) { // not already waiting for ACK, AND not evicted, AND retries not max
863865
MESH_DEBUG_PRINTLN("loop - checking for client %02X", (uint32_t) client->id.pub_key[0]);
866+
uint32_t now = getRTCClock()->getCurrentTime();
864867
for (int k = 0, idx = next_post_idx; k < MAX_UNSYNCED_POSTS; k++) {
865-
if (posts[idx].post_timestamp > client->sync_since // is new post for this Client?
866-
&& !posts[idx].author.matches(client->id)) { // don't push posts to the author
868+
auto p = &posts[idx];
869+
if (now >= p->post_timestamp + POST_SYNC_DELAY_SECS && p->post_timestamp > client->sync_since // is new post for this Client?
870+
&& !p->author.matches(client->id)) { // don't push posts to the author
867871
// push this post to Client, then wait for ACK
868-
pushPostToClient(client, posts[idx]);
872+
pushPostToClient(client, *p);
869873
did_push = true;
870-
MESH_DEBUG_PRINTLN("loop - pushed to client %02X: %s", (uint32_t) client->id.pub_key[0], posts[idx].text);
874+
MESH_DEBUG_PRINTLN("loop - pushed to client %02X: %s", (uint32_t) client->id.pub_key[0], p->text);
871875
break;
872876
}
873877
idx = (idx + 1) % MAX_UNSYNCED_POSTS; // wrap to start of cyclic queue

0 commit comments

Comments
 (0)