ssb: muxrpc activity status fixes.
This commit is contained in:
parent
7c36a543da
commit
c52c6b04ca
@ -103,9 +103,6 @@ BUILD_TYPES += \
|
||||
androidrelease-x86_64
|
||||
all: out/TildeFriends-arm-debug.apk out/TildeFriends-arm-release.apk out/TildeFriends-x86-debug.apk out/TildeFriends-x86-release.apk out/TildeFriends-release.fdroid.apk
|
||||
endif
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
all: appimage
|
||||
endif
|
||||
|
||||
WINDOWS_TARGETS := \
|
||||
out/windebug/tildefriends.exe \
|
||||
@ -231,6 +228,9 @@ $(IOSSIM_TARGETS): CFLAGS += -Ideps/openssl/ios/iossimulator-xcrun/usr/local/inc
|
||||
$(IOSSIM_TARGETS): LDFLAGS += -Ldeps/openssl/ios/iossimulator-xcrun/usr/local/lib
|
||||
|
||||
ifeq ($(UNAME_M),x86_64)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
all: appimage
|
||||
endif
|
||||
ifneq ($(UNAME_S),Haiku)
|
||||
out/debug/tildefriends: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common
|
||||
out/debug/tildefriends: LDFLAGS += -fsanitize=address -fsanitize=undefined
|
||||
|
33
src/ssb.c
33
src/ssb.c
@ -113,7 +113,7 @@ typedef struct _tf_ssb_request_t
|
||||
tf_ssb_callback_cleanup_t* cleanup;
|
||||
void* user_data;
|
||||
tf_ssb_connection_t* dependent_connection;
|
||||
time_t last_active;
|
||||
uint64_t last_active;
|
||||
int32_t request_number;
|
||||
} tf_ssb_request_t;
|
||||
|
||||
@ -364,7 +364,7 @@ typedef struct _tf_ssb_connection_t
|
||||
int read_back_pressure;
|
||||
int active_write_count;
|
||||
|
||||
time_t last_notified_active;
|
||||
uint64_t last_notified_active;
|
||||
} tf_ssb_connection_t;
|
||||
|
||||
static JSClassID _connection_class_id;
|
||||
@ -687,25 +687,35 @@ static bool _tf_ssb_connection_get_request_callback(tf_ssb_connection_t* connect
|
||||
static void _tf_ssb_request_activity_timer(uv_timer_t* timer)
|
||||
{
|
||||
tf_ssb_t* ssb = timer->data;
|
||||
time_t now = time(NULL);
|
||||
uint64_t now_ms = uv_now(ssb->loop);
|
||||
bool any_still_active = false;
|
||||
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next)
|
||||
{
|
||||
bool any_changed = false;
|
||||
bool last_notified_active = (now - connection->last_notified_active) * 1000 < k_rpc_active_ms;
|
||||
bool last_notified_active = (now_ms - connection->last_notified_active) < k_rpc_active_ms;
|
||||
for (int i = 0; i < connection->requests_count; i++)
|
||||
{
|
||||
bool last_active = (now - connection->requests[i].last_active) * 1000 <= k_rpc_active_ms;
|
||||
bool last_active = (now_ms - connection->requests[i].last_active) < k_rpc_active_ms;
|
||||
if (last_active != last_notified_active)
|
||||
{
|
||||
any_changed = true;
|
||||
}
|
||||
if (last_active)
|
||||
{
|
||||
any_still_active = true;
|
||||
}
|
||||
}
|
||||
if (any_changed)
|
||||
{
|
||||
_tf_ssb_notify_connections_changed(ssb, k_tf_ssb_change_update, connection);
|
||||
connection->last_notified_active = now;
|
||||
connection->last_notified_active = now_ms;
|
||||
}
|
||||
}
|
||||
|
||||
if (any_still_active)
|
||||
{
|
||||
uv_timer_start(&ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, const char* name, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup,
|
||||
@ -713,14 +723,14 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ
|
||||
{
|
||||
tf_ssb_request_t* existing =
|
||||
connection->requests_count ? bsearch(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare) : NULL;
|
||||
time_t now = time(NULL);
|
||||
uint64_t now_ms = uv_now(connection->ssb->loop);
|
||||
if (existing)
|
||||
{
|
||||
assert(!existing->callback);
|
||||
assert(!existing->cleanup);
|
||||
assert(!existing->user_data);
|
||||
assert(!existing->dependent_connection);
|
||||
existing->last_active = now;
|
||||
existing->last_active = now_ms;
|
||||
existing->callback = callback;
|
||||
existing->cleanup = cleanup;
|
||||
existing->user_data = user_data;
|
||||
@ -735,7 +745,7 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ
|
||||
.cleanup = cleanup,
|
||||
.user_data = user_data,
|
||||
.dependent_connection = dependent_connection,
|
||||
.last_active = now,
|
||||
.last_active = now_ms,
|
||||
};
|
||||
snprintf(request.name, sizeof(request.name), "%s", name);
|
||||
int index = tf_util_insert_index(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare);
|
||||
@ -753,7 +763,7 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ
|
||||
uv_timer_start(&connection->ssb->request_activity_timer, _tf_ssb_request_activity_timer, k_rpc_active_ms, 0);
|
||||
}
|
||||
_tf_ssb_notify_connections_changed(connection->ssb, k_tf_ssb_change_update, connection);
|
||||
connection->last_notified_active = now;
|
||||
connection->last_notified_active = now_ms;
|
||||
}
|
||||
|
||||
static int _message_request_compare(const void* a, const void* b)
|
||||
@ -4226,12 +4236,13 @@ JSValue tf_ssb_connection_requests_to_object(tf_ssb_connection_t* connection)
|
||||
{
|
||||
JSContext* context = connection->ssb->context;
|
||||
JSValue object = JS_NewArray(context);
|
||||
uint64_t now_ms = uv_now(connection->ssb->loop);
|
||||
for (int i = 0; i < connection->requests_count; i++)
|
||||
{
|
||||
JSValue request = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, request, "name", JS_NewString(context, connection->requests[i].name));
|
||||
JS_SetPropertyStr(context, request, "request_number", JS_NewInt32(context, connection->requests[i].request_number));
|
||||
JS_SetPropertyStr(context, request, "active", JS_NewBool(context, time(NULL) - connection->requests[i].last_active < 3));
|
||||
JS_SetPropertyStr(context, request, "active", JS_NewBool(context, (now_ms - connection->requests[i].last_active) < k_rpc_active_ms));
|
||||
JS_SetPropertyUint32(context, object, i, request);
|
||||
}
|
||||
return object;
|
||||
|
Loading…
Reference in New Issue
Block a user