From d6d305feeb76735ee4b4e14c6bca737a5482bc19 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 1 Aug 2018 23:02:13 +0000 Subject: Use per-instance `Mono_Time` for Messenger and onion. --- toxcore/tox.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'toxcore/tox.c') 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 @@ struct Tox { Messenger *m; + Mono_Time *mono_time; + tox_self_connection_status_cb *self_connection_status_callback; tox_friend_name_cb *friend_name_callback; 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) return nullptr; } - unix_time_update(); - Messenger_Options m_options = {0}; 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) m_options.proxy_info.ip_port.port = net_htons(tox_options_get_proxy_port(opts)); } + tox->mono_time = mono_time_new(); + + if (tox->mono_time == nullptr) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); + tox_options_free(default_options); + free(tox); + return nullptr; + } + unsigned int m_error; - Messenger *const m = new_messenger(&m_options, &m_error); + Messenger *const m = new_messenger(tox->mono_time, &m_options, &m_error); tox->m = m; // TODO(iphydf): Clarify this code, check for NULL before new_groupchats, so // new_groupchats can assume m is non-NULL. - if (!new_groupchats(m)) { + if (!new_groupchats(tox->mono_time, m)) { kill_messenger(m); if (m_error == MESSENGER_ERROR_PORT) { @@ -472,6 +481,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); } + mono_time_free(tox->mono_time); tox_options_free(default_options); free(tox); return nullptr; @@ -522,6 +532,7 @@ void tox_kill(Tox *tox) Messenger *m = tox->m; kill_groupchats(m->conferences_object); kill_messenger(m); + mono_time_free(tox->mono_time); free(tox); } @@ -656,7 +667,7 @@ uint32_t tox_iteration_interval(const Tox *tox) void tox_iterate(Tox *tox, void *user_data) { - unix_time_update(); + mono_time_update(tox->mono_time); Messenger *m = tox->m; struct Tox_Userdata tox_data = { tox, user_data }; -- cgit v1.2.3