From 06642f58c551f72a4dd70de91d6a3f77590c201d Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 12 Apr 2023 23:22:33 +0000 Subject: [PATCH] One less blocking thing on the main thread: _tf_ssb_connection_send_history_stream. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4256 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.rpc.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/ssb.rpc.c b/src/ssb.rpc.c index 497a02b7..4945d40d 100644 --- a/src/ssb.rpc.c +++ b/src/ssb.rpc.c @@ -16,6 +16,7 @@ #endif static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live); +static void _tf_ssb_connection_send_history_stream_internal(tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live); static void _tf_ssb_rpc_gossip_ping_callback(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data) { @@ -688,12 +689,12 @@ static void _tf_ssb_connection_send_history_stream_callback(tf_ssb_connection_t* tf_ssb_connection_send_history_stream_t* request = user_data; if (tf_ssb_connection_is_connected(connection)) { - _tf_ssb_connection_send_history_stream(connection, request->request_number, request->author, request->sequence, request->keys, request->live); + _tf_ssb_connection_send_history_stream_internal(connection, request->request_number, request->author, request->sequence, request->keys, request->live); } tf_free(request); } -static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live) +static void _tf_ssb_connection_send_history_stream_internal(tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live) { tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection); JSContext* context = tf_ssb_get_context(ssb); @@ -742,16 +743,7 @@ static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connecti if (max_sequence_seen == sequence + k_max - 1) { - tf_ssb_connection_send_history_stream_t* async = tf_malloc(sizeof(tf_ssb_connection_send_history_stream_t)); - *async = (tf_ssb_connection_send_history_stream_t) - { - .request_number = request_number, - .sequence = max_sequence_seen + 1, - .keys = keys, - .live = live, - }; - snprintf(async->author, sizeof(async->author), "%s", author); - tf_ssb_connection_schedule_idle(connection, _tf_ssb_connection_send_history_stream_callback, async); + _tf_ssb_connection_send_history_stream(connection, request_number, author, max_sequence_seen + 1, keys, live); } else if (!live) { @@ -767,6 +759,20 @@ static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connecti } } +static void _tf_ssb_connection_send_history_stream(tf_ssb_connection_t* connection, int32_t request_number, const char* author, int64_t sequence, bool keys, bool live) +{ + tf_ssb_connection_send_history_stream_t* async = tf_malloc(sizeof(tf_ssb_connection_send_history_stream_t)); + *async = (tf_ssb_connection_send_history_stream_t) + { + .request_number = request_number, + .sequence = sequence, + .keys = keys, + .live = live, + }; + snprintf(async->author, sizeof(async->author), "%s", author); + tf_ssb_connection_schedule_idle(connection, _tf_ssb_connection_send_history_stream_callback, async); +} + static void _tf_ssb_rpc_createHistoryStream(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data) { tf_ssb_t* ssb = tf_ssb_connection_get_ssb(connection);