forked from cory/tildefriends
Attempt to clean up requests for tunnel connections that are going away.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4018 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
b12f8f9da8
commit
3a5ae4c228
14
src/ssb.c
14
src/ssb.c
@ -73,6 +73,7 @@ typedef struct _tf_ssb_request_t
|
||||
tf_ssb_rpc_callback_t* callback;
|
||||
tf_ssb_callback_cleanup_t* cleanup;
|
||||
void* user_data;
|
||||
tf_ssb_connection_t* dependent_connection;
|
||||
} tf_ssb_request_t;
|
||||
|
||||
typedef struct _tf_ssb_broadcast_t
|
||||
@ -466,7 +467,7 @@ static bool _tf_ssb_connection_get_request_callback(tf_ssb_connection_t* connect
|
||||
return false;
|
||||
}
|
||||
|
||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data)
|
||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data, tf_ssb_connection_t* dependent_connection)
|
||||
{
|
||||
_tf_ssb_connection_remove_request(connection, request_number);
|
||||
tf_ssb_request_t request =
|
||||
@ -475,6 +476,7 @@ void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t requ
|
||||
.callback = callback,
|
||||
.cleanup = cleanup,
|
||||
.user_data = user_data,
|
||||
.dependent_connection = dependent_connection,
|
||||
};
|
||||
int index = tf_util_insert_index(&request_number, connection->requests, connection->requests_count, sizeof(tf_ssb_request_t), _request_compare);
|
||||
connection->requests = tf_resize_vec(connection->requests, sizeof(tf_ssb_request_t) * (connection->requests_count + 1));
|
||||
@ -513,7 +515,7 @@ void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags,
|
||||
}
|
||||
if (request_number > 0 && callback)
|
||||
{
|
||||
tf_ssb_connection_add_request(connection, request_number, callback, cleanup, user_data);
|
||||
tf_ssb_connection_add_request(connection, request_number, callback, cleanup, user_data, NULL);
|
||||
}
|
||||
uint8_t* combined = tf_malloc(9 + size);
|
||||
*combined = flags;
|
||||
@ -1398,6 +1400,13 @@ void _tf_ssb_connection_destroy(tf_ssb_connection_t* connection, const char* rea
|
||||
}
|
||||
for (tf_ssb_connection_t** it = &connection->ssb->connections; *it; it = &(*it)->next)
|
||||
{
|
||||
for (int i = 0; i < (*it)->requests_count; i++)
|
||||
{
|
||||
if ((*it)->requests[i].dependent_connection == connection)
|
||||
{
|
||||
_tf_ssb_connection_remove_request(*it, (*it)->requests[i].request_number);
|
||||
}
|
||||
}
|
||||
if (*it == connection)
|
||||
{
|
||||
*it = connection->next;
|
||||
@ -2118,6 +2127,7 @@ tf_ssb_connection_t* tf_ssb_connection_tunnel_create(tf_ssb_connection_t* connec
|
||||
request_number,
|
||||
_tf_ssb_connection_tunnel_callback,
|
||||
NULL,
|
||||
tunnel,
|
||||
tunnel);
|
||||
if (request_number < 0)
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ void tf_ssb_add_rpc_callback(tf_ssb_t* ssb, const char** name, tf_ssb_rpc_callba
|
||||
void tf_ssb_remove_rpc_callback(tf_ssb_t* ssb, const char** name, tf_ssb_rpc_callback_t* callback, void* user_data);
|
||||
|
||||
void tf_ssb_connection_rpc_send(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, const uint8_t* message, size_t size, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);
|
||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);
|
||||
void tf_ssb_connection_add_request(tf_ssb_connection_t* connection, int32_t request_number, tf_ssb_rpc_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data, tf_ssb_connection_t* dependent_connection);
|
||||
|
||||
void tf_ssb_connection_add_room_attendant(tf_ssb_connection_t* connection, const char* id);
|
||||
void tf_ssb_connection_remove_room_attendant(tf_ssb_connection_t* connection, const char* id);
|
||||
|
10
src/ssb.js.c
10
src/ssb.js.c
@ -483,7 +483,7 @@ static JSValue _tf_ssb_rpc_more(JSContext* context, JSValueConst this_val, int a
|
||||
JS_ToInt32(context, &request_number, request_val);
|
||||
JS_FreeValue(context, request_val);
|
||||
|
||||
tf_ssb_connection_add_request(connection, -request_number, _tf_ssb_on_rpc, _tf_ssb_cleanup_value, JS_VALUE_GET_PTR(JS_DupValue(context, argv[0])));
|
||||
tf_ssb_connection_add_request(connection, -request_number, _tf_ssb_on_rpc, _tf_ssb_cleanup_value, JS_VALUE_GET_PTR(JS_DupValue(context, argv[0])), NULL);
|
||||
|
||||
JS_FreeValue(context, connection_val);
|
||||
return JS_UNDEFINED;
|
||||
@ -970,8 +970,6 @@ static JSValue _tf_ssb_tunnel(JSContext* context, JSValueConst this_val, int arg
|
||||
int32_t request_number1 = 0;
|
||||
JS_ToInt32(context, &request_number1, argv[3]);
|
||||
|
||||
printf("TUNNEL %p %d <=> %p %d\n", connection0, request_number0, connection1, request_number1);
|
||||
|
||||
tunnel_t* data0 = tf_malloc(sizeof(tunnel_t));
|
||||
*data0 = (tunnel_t)
|
||||
{
|
||||
@ -985,10 +983,8 @@ static JSValue _tf_ssb_tunnel(JSContext* context, JSValueConst this_val, int arg
|
||||
.request_number = request_number0,
|
||||
};
|
||||
|
||||
printf("ADD REQUEST %p %d\n", connection0, request_number0);
|
||||
printf("ADD REQUEST %p %d\n", connection1, request_number1);
|
||||
tf_ssb_connection_add_request(connection0, request_number0, _tf_ssb_tunnel_rpc_callback, _tf_ssb_tunnel_cleanup, data0);
|
||||
tf_ssb_connection_add_request(connection1, request_number1, _tf_ssb_tunnel_rpc_callback, _tf_ssb_tunnel_cleanup, data1);
|
||||
tf_ssb_connection_add_request(connection0, request_number0, _tf_ssb_tunnel_rpc_callback, _tf_ssb_tunnel_cleanup, data0, connection1);
|
||||
tf_ssb_connection_add_request(connection1, request_number1, _tf_ssb_tunnel_rpc_callback, _tf_ssb_tunnel_cleanup, data1, connection0);
|
||||
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
@ -369,6 +369,7 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
|
||||
|
||||
tf_ssb_connection_t* connections[4];
|
||||
int count = tf_ssb_get_connections(ssb1, connections, 4);
|
||||
(void)count;
|
||||
assert(count == 1);
|
||||
|
||||
int32_t tunnel_request_number = tf_ssb_connection_next_request_number(connections[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user