summaryrefslogtreecommitdiff
path: root/auto_tests/toxav_many_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-10 13:46:04 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-08-17 14:57:20 +0100
commitdd8a568141b43546521ca438d861e00c26051f6c (patch)
tree98f3f9a871f164b20693eca89eb0c8bf2ae826ed /auto_tests/toxav_many_test.c
parentcebf64a588039c202880659a85d070126bcc68da (diff)
Make self_connection_status callback stateless.
**What are we doing?** We are moving towards stateless callbacks. This means that when registering a callback, you no longer pass a user data pointer. Instead, you pass a user data pointer to tox_iterate. This pointer is threaded through the code, passed to each callback. The callback can modify the data pointed at. An extra indirection will be needed if the pointer itself can change. **Why?** Currently, callbacks are registered with a user data pointer. This means the library has N pointers for N different callbacks. These pointers need to be managed by the client code. Managing the lifetime of the pointee can be difficult. In C++, it takes special effort to ensure that the lifetime of user data extends at least beyond the lifetime of the Tox instance. For other languages, the situation is much worse. Java and other garbage collected languages may move objects in memory, so the pointers are not stable. Tox4j goes through a lot of effort to make the Java/Scala user experience a pleasant one by keeping a global array of Tox+userdata on the C++ side, and communicating via protobufs. A Haskell FFI would have to do similarly complex tricks. Stateless callbacks ensure that a user data pointer only needs to live during a single function call. This means that the user code (or language runtime) can move the data around at will, as long as it sets the new location in the callback. **How?** We are doing this change one callback at a time. After each callback, we ensure that everything still works as expected. This means the toxcore change will require 15 Pull Requests.
Diffstat (limited to 'auto_tests/toxav_many_test.c')
-rw-r--r--auto_tests/toxav_many_test.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index ab496024..d626067c 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -248,11 +248,11 @@ START_TEST(test_AV_three_calls)
248 uint8_t off = 1; 248 uint8_t off = 1;
249 249
250 while (1) { 250 while (1) {
251 tox_iterate(bootstrap); 251 tox_iterate(bootstrap, NULL);
252 tox_iterate(Alice); 252 tox_iterate(Alice, NULL);
253 tox_iterate(Bobs[0]); 253 tox_iterate(Bobs[0], NULL);
254 tox_iterate(Bobs[1]); 254 tox_iterate(Bobs[1], NULL);
255 tox_iterate(Bobs[2]); 255 tox_iterate(Bobs[2], NULL);
256 256
257 if (tox_self_get_connection_status(bootstrap) && 257 if (tox_self_get_connection_status(bootstrap) &&
258 tox_self_get_connection_status(Alice) && 258 tox_self_get_connection_status(Alice) &&
@@ -313,10 +313,10 @@ START_TEST(test_AV_three_calls)
313 time_t start_time = time(NULL); 313 time_t start_time = time(NULL);
314 314
315 while (time(NULL) - start_time < 5) { 315 while (time(NULL) - start_time < 5) {
316 tox_iterate(Alice); 316 tox_iterate(Alice, NULL);
317 tox_iterate(Bobs[0]); 317 tox_iterate(Bobs[0], NULL);
318 tox_iterate(Bobs[1]); 318 tox_iterate(Bobs[1], NULL);
319 tox_iterate(Bobs[2]); 319 tox_iterate(Bobs[2], NULL);
320 c_sleep(20); 320 c_sleep(20);
321 } 321 }
322 322