forked from cory/tildefriends
		
	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
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user