summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 879b5c09..4f596045 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -78,6 +78,8 @@
78 78
79struct Tox { 79struct Tox {
80 Messenger *m; 80 Messenger *m;
81 Mono_Time *mono_time;
82
81 tox_self_connection_status_cb *self_connection_status_callback; 83 tox_self_connection_status_cb *self_connection_status_callback;
82 tox_friend_name_cb *friend_name_callback; 84 tox_friend_name_cb *friend_name_callback;
83 tox_friend_status_message_cb *friend_status_message_callback; 85 tox_friend_status_message_cb *friend_status_message_callback;
@@ -336,8 +338,6 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
336 return nullptr; 338 return nullptr;
337 } 339 }
338 340
339 unix_time_update();
340
341 Messenger_Options m_options = {0}; 341 Messenger_Options m_options = {0};
342 342
343 bool load_savedata_sk = false, load_savedata_tox = false; 343 bool load_savedata_sk = false, load_savedata_tox = false;
@@ -455,13 +455,22 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
455 m_options.proxy_info.ip_port.port = net_htons(tox_options_get_proxy_port(opts)); 455 m_options.proxy_info.ip_port.port = net_htons(tox_options_get_proxy_port(opts));
456 } 456 }
457 457
458 tox->mono_time = mono_time_new();
459
460 if (tox->mono_time == nullptr) {
461 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
462 tox_options_free(default_options);
463 free(tox);
464 return nullptr;
465 }
466
458 unsigned int m_error; 467 unsigned int m_error;
459 Messenger *const m = new_messenger(&m_options, &m_error); 468 Messenger *const m = new_messenger(tox->mono_time, &m_options, &m_error);
460 tox->m = m; 469 tox->m = m;
461 470
462 // TODO(iphydf): Clarify this code, check for NULL before new_groupchats, so 471 // TODO(iphydf): Clarify this code, check for NULL before new_groupchats, so
463 // new_groupchats can assume m is non-NULL. 472 // new_groupchats can assume m is non-NULL.
464 if (!new_groupchats(m)) { 473 if (!new_groupchats(tox->mono_time, m)) {
465 kill_messenger(m); 474 kill_messenger(m);
466 475
467 if (m_error == MESSENGER_ERROR_PORT) { 476 if (m_error == MESSENGER_ERROR_PORT) {
@@ -472,6 +481,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
472 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); 481 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
473 } 482 }
474 483
484 mono_time_free(tox->mono_time);
475 tox_options_free(default_options); 485 tox_options_free(default_options);
476 free(tox); 486 free(tox);
477 return nullptr; 487 return nullptr;
@@ -522,6 +532,7 @@ void tox_kill(Tox *tox)
522 Messenger *m = tox->m; 532 Messenger *m = tox->m;
523 kill_groupchats(m->conferences_object); 533 kill_groupchats(m->conferences_object);
524 kill_messenger(m); 534 kill_messenger(m);
535 mono_time_free(tox->mono_time);
525 free(tox); 536 free(tox);
526} 537}
527 538
@@ -656,7 +667,7 @@ uint32_t tox_iteration_interval(const Tox *tox)
656 667
657void tox_iterate(Tox *tox, void *user_data) 668void tox_iterate(Tox *tox, void *user_data)
658{ 669{
659 unix_time_update(); 670 mono_time_update(tox->mono_time);
660 671
661 Messenger *m = tox->m; 672 Messenger *m = tox->m;
662 struct Tox_Userdata tox_data = { tox, user_data }; 673 struct Tox_Userdata tox_data = { tox, user_data };