From 6b5d73ed5c6dd00e5a332ffc4079920a037909ac Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 15 Feb 2023 02:34:46 +0000 Subject: [PATCH] Vague attempt at some more cleanup, and stick pthread_self() in the traces. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4176 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 16 ++++++++++++---- src/trace.c | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ssb.c b/src/ssb.c index 0fd6ff7e..51bed2b2 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -685,12 +685,12 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, { if (!connection) { + if (cleanup) + { + cleanup(NULL, user_data); + } return; } - if (request_number > 0 && callback) - { - tf_ssb_connection_add_request(connection, request_number, callback, cleanup, user_data, NULL); - } uint8_t* combined = tf_malloc(9 + size); *combined = flags; uint32_t u32size = htonl((uint32_t)size); @@ -706,6 +706,14 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, _tf_ssb_connection_box_stream_send(connection, combined, 1 + 2 * sizeof(uint32_t) + size); tf_free(combined); connection->ssb->rpc_out++; + if (request_number > 0 && callback) + { + tf_ssb_connection_add_request(connection, request_number, callback, cleanup, user_data, NULL); + } + else if (cleanup) + { + cleanup(connection->ssb, user_data); + } } void tf_ssb_connection_rpc_send_json(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue message, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data) diff --git a/src/trace.c b/src/trace.c index 4024edc9..34bd83f0 100644 --- a/src/trace.c +++ b/src/trace.c @@ -3,6 +3,7 @@ #include "mem.h" #include +#include #include #include #include @@ -173,7 +174,7 @@ void tf_trace_begin(tf_trace_t* trace, const char* name) stack->names[stack->count++] = name; char line[1024]; - int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": 0, \"ts\": %" PRId64 ", \"name\": \"", getpid(), _trace_ts()); + int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": %" PRId64 ", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts()); p += _tf_trace_escape_name(line + p, sizeof(line) - p, name); p += snprintf(line + p, sizeof(line) - p, "\"},"); trace->callback(trace, line, p, trace->user_data); @@ -203,7 +204,7 @@ void tf_trace_end(tf_trace_t* trace) } char line[1024]; - int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": 0, \"ts\": %" PRId64 ", \"name\": \"", getpid(), _trace_ts()); + int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": %" PRId64 ", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts()); p += _tf_trace_escape_name(line + p, sizeof(line) - p, name); p += snprintf(line + p, sizeof(line) - p, "\"},"); trace->callback(trace, line, p, trace->user_data);