From 40e20146f6cf49318581e4fd29172f35905acfa5 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 11 Jan 2024 00:39:52 +0100 Subject: [PATCH] Also use the queue in SMTPClient when not threading. --- modules/smtp/smtp_client.cpp | 32 +++++++++++++++++++++++++++++--- modules/smtp/smtp_client.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/modules/smtp/smtp_client.cpp b/modules/smtp/smtp_client.cpp index 97223a4dd..e29361b33 100644 --- a/modules/smtp/smtp_client.cpp +++ b/modules/smtp/smtp_client.cpp @@ -163,6 +163,11 @@ void SMTPClient::send_email(const Ref &p_email) { _worker_semaphore.post(); } else { + if (_current_session_email.is_valid()) { + _mail_queue.push_back(p_email); + return; + } + _send_email(p_email); } } @@ -200,7 +205,7 @@ void SMTPClient::_send_email(const Ref &p_email) { emit_signal("result", result); if (!should_use_threading()) { - set_process(false); + _no_thread_next_email(); } } @@ -224,7 +229,7 @@ void SMTPClient::_send_email(const Ref &p_email) { emit_signal("result", result); if (!should_use_threading()) { - set_process(false); + _no_thread_next_email(); } return; @@ -342,7 +347,7 @@ void SMTPClient::close_connection() { _current_tls_established = false; if (!should_use_threading()) { - set_process(false); + _no_thread_next_email(); } } @@ -548,6 +553,27 @@ void SMTPClient::_process_email() { } } +void SMTPClient::_no_thread_next_email() { + if (should_use_threading()) { + return; + } + + Ref mail; + + int size = _mail_queue.size(); + if (size > 0) { + mail = _mail_queue[0]; + _mail_queue.remove(0); + } else { + set_process(false); + return; + } + + if (mail.is_valid()) { + _send_email(mail); + } +} + void SMTPClient::_worker_thread_func(void *user_data) { SMTPClient *self = (SMTPClient *)user_data; diff --git a/modules/smtp/smtp_client.h b/modules/smtp/smtp_client.h index 1d1e08551..12161a6c6 100644 --- a/modules/smtp/smtp_client.h +++ b/modules/smtp/smtp_client.h @@ -142,6 +142,7 @@ protected: String encode_password(); void _process_email(); + void _no_thread_next_email(); static void _worker_thread_func(void *user_data);