From 1f9807ccfe9e0f61f0ea9f800e16c0493fa7a48c Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 1 Aug 2019 06:23:37 +0000 Subject: [PATCH 1/5] Refine type of Context.probe_network to bool --- src/context.rs | 4 ++-- src/dc_job.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/context.rs b/src/context.rs index 0a985447c..cf39e5387 100644 --- a/src/context.rs +++ b/src/context.rs @@ -28,7 +28,7 @@ pub struct Context { pub sql: Sql, pub inbox: Arc>, pub perform_inbox_jobs_needed: Arc>, - pub probe_imap_network: Arc>, + pub probe_imap_network: Arc>, pub sentbox_thread: Arc>, pub mvbox_thread: Arc>, pub smtp: Arc>, @@ -160,7 +160,7 @@ pub fn dc_context_new( cb_receive_imf, ), ))), - probe_imap_network: Arc::new(RwLock::new(0)), + probe_imap_network: Arc::new(RwLock::new(false)), perform_inbox_jobs_needed: Arc::new(RwLock::new(0)), } } diff --git a/src/dc_job.rs b/src/dc_job.rs index fe30c4873..e483c2ed5 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -54,15 +54,15 @@ pub unsafe fn dc_perform_imap_jobs(context: &Context) { info!(context, 0, "dc_perform_imap_jobs starting.",); let probe_imap_network = *context.probe_imap_network.clone().read().unwrap(); - *context.probe_imap_network.write().unwrap() = 0; + *context.probe_imap_network.write().unwrap() = false; *context.perform_inbox_jobs_needed.write().unwrap() = 0; dc_job_perform(context, DC_IMAP_THREAD, probe_imap_network); info!(context, 0, "dc_perform_imap_jobs ended.",); } -unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: libc::c_int) { - let query = if probe_network == 0 { +unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: bool) { + let query = if !probe_network { // processing for first-try and after backoff-timeouts: // process jobs in the order they were added. "SELECT id, action, foreign_id, param, added_timestamp, desired_timestamp, tries \ @@ -77,7 +77,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: let params_no_probe = params![thread as i64, time()]; let params_probe = params![thread as i64]; - let params: &[&dyn rusqlite::ToSql] = if probe_network == 0 { + let params: &[&dyn rusqlite::ToSql] = if !probe_network { params_no_probe } else { params_probe @@ -225,7 +225,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: } dc_job_delete(context, &mut job); } - if 0 == probe_network { + if !probe_network { continue; } // on dc_maybe_network() we stop trying here; @@ -1050,7 +1050,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) { return; } state.doing_jobs = 1; - probe_smtp_network + probe_smtp_network != 0 }; info!(context, 0, "SMTP-jobs started...",); @@ -1125,7 +1125,7 @@ pub unsafe fn dc_maybe_network(context: &Context) { let mut state = lock.lock().unwrap(); state.probe_network = 1; - *context.probe_imap_network.write().unwrap() = 1; + *context.probe_imap_network.write().unwrap() = true; } dc_interrupt_smtp_idle(context); From 07d7316a9f07872343828ffef397b1f85fea0da1 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 1 Aug 2019 06:31:58 +0000 Subject: [PATCH 2/5] Refine type of Context.perform_inbox_jobs_needed to bool --- src/context.rs | 4 ++-- src/dc_job.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/context.rs b/src/context.rs index cf39e5387..3124727f7 100644 --- a/src/context.rs +++ b/src/context.rs @@ -27,7 +27,7 @@ pub struct Context { pub blobdir: Arc>, pub sql: Sql, pub inbox: Arc>, - pub perform_inbox_jobs_needed: Arc>, + pub perform_inbox_jobs_needed: Arc>, pub probe_imap_network: Arc>, pub sentbox_thread: Arc>, pub mvbox_thread: Arc>, @@ -161,7 +161,7 @@ pub fn dc_context_new( ), ))), probe_imap_network: Arc::new(RwLock::new(false)), - perform_inbox_jobs_needed: Arc::new(RwLock::new(0)), + perform_inbox_jobs_needed: Arc::new(RwLock::new(false)), } } diff --git a/src/dc_job.rs b/src/dc_job.rs index e483c2ed5..66eac5d9d 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -55,7 +55,7 @@ pub unsafe fn dc_perform_imap_jobs(context: &Context) { let probe_imap_network = *context.probe_imap_network.clone().read().unwrap(); *context.probe_imap_network.write().unwrap() = false; - *context.perform_inbox_jobs_needed.write().unwrap() = 0; + *context.perform_inbox_jobs_needed.write().unwrap() = false; dc_job_perform(context, DC_IMAP_THREAD, probe_imap_network); info!(context, 0, "dc_perform_imap_jobs ended.",); @@ -859,7 +859,7 @@ pub unsafe fn dc_interrupt_smtp_idle(context: &Context) { pub unsafe fn dc_interrupt_imap_idle(context: &Context) { info!(context, 0, "Interrupting IMAP-IDLE...",); - *context.perform_inbox_jobs_needed.write().unwrap() = 1; + *context.perform_inbox_jobs_needed.write().unwrap() = true; context.inbox.read().unwrap().interrupt_idle(); } @@ -967,7 +967,7 @@ pub fn dc_perform_imap_idle(context: &Context) { connect_to_inbox(context, &inbox); - if 0 != *context.perform_inbox_jobs_needed.clone().read().unwrap() { + if *context.perform_inbox_jobs_needed.clone().read().unwrap() { info!( context, 0, "INBOX-IDLE will not be started because of waiting jobs." From b2807429cc698668cf16b0216fedf3e20394d0fa Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 1 Aug 2019 06:37:06 +0000 Subject: [PATCH 3/5] Refine type of SmtpState.probe_network to bool --- src/context.rs | 2 +- src/dc_job.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/context.rs b/src/context.rs index 3124727f7..11b344f72 100644 --- a/src/context.rs +++ b/src/context.rs @@ -109,7 +109,7 @@ pub struct SmtpState { pub suspended: i32, pub doing_jobs: i32, pub perform_jobs_needed: i32, - pub probe_network: i32, + pub probe_network: bool, } // create/open/config/information diff --git a/src/dc_job.rs b/src/dc_job.rs index 66eac5d9d..20f6edda0 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -1042,7 +1042,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) { let mut state = lock.lock().unwrap(); let probe_smtp_network = state.probe_network; - state.probe_network = 0; + state.probe_network = false; state.perform_jobs_needed = 0; if 0 != state.suspended { @@ -1050,7 +1050,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) { return; } state.doing_jobs = 1; - probe_smtp_network != 0 + probe_smtp_network }; info!(context, 0, "SMTP-jobs started...",); @@ -1123,7 +1123,7 @@ pub unsafe fn dc_maybe_network(context: &Context) { { let &(ref lock, _) = &*context.smtp_state.clone(); let mut state = lock.lock().unwrap(); - state.probe_network = 1; + state.probe_network = true; *context.probe_imap_network.write().unwrap() = true; } From 8eb5cec9ceafbb977399fca91526fa5c4d983597 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 1 Aug 2019 06:41:50 +0000 Subject: [PATCH 4/5] Refine type of SmtpState.suspended to bool --- src/context.rs | 2 +- src/dc_job.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/context.rs b/src/context.rs index 11b344f72..1a296627c 100644 --- a/src/context.rs +++ b/src/context.rs @@ -106,7 +106,7 @@ impl Default for BobStatus { #[derive(Default, Debug)] pub struct SmtpState { pub idle: bool, - pub suspended: i32, + pub suspended: bool, pub doing_jobs: i32, pub perform_jobs_needed: i32, pub probe_network: bool, diff --git a/src/dc_job.rs b/src/dc_job.rs index 20f6edda0..f1f9bfa8b 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -136,7 +136,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: dc_job_kill_action(context, job.action); dc_jobthread_suspend(context, &context.sentbox_thread.clone().read().unwrap(), 1); dc_jobthread_suspend(context, &context.mvbox_thread.clone().read().unwrap(), 1); - dc_suspend_smtp_thread(context, 1); + dc_suspend_smtp_thread(context, true); } let mut tries = 0; @@ -174,7 +174,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: &mut context.mvbox_thread.clone().read().unwrap(), 0, ); - dc_suspend_smtp_thread(context, 0); + dc_suspend_smtp_thread(context, false); break; } else if job.try_again == 2 { // just try over next loop unconditionally, the ui typically interrupts idle when the file (video) is ready @@ -279,9 +279,9 @@ fn dc_job_update(context: &Context, job: &dc_job_t) -> bool { .is_ok() } -unsafe fn dc_suspend_smtp_thread(context: &Context, suspend: libc::c_int) { +unsafe fn dc_suspend_smtp_thread(context: &Context, suspend: bool) { context.smtp_state.0.lock().unwrap().suspended = suspend; - if 0 != suspend { + if suspend { loop { if context.smtp_state.0.lock().unwrap().doing_jobs == 0 { return; @@ -1045,7 +1045,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) { state.probe_network = false; state.perform_jobs_needed = 0; - if 0 != state.suspended { + if state.suspended { info!(context, 0, "SMTP-jobs suspended.",); return; } From 7394666266b89036aefde0047136510993c0a79c Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 1 Aug 2019 06:51:52 +0000 Subject: [PATCH 5/5] Refine type of SmtpState.doing_jobs to bool --- src/context.rs | 2 +- src/dc_job.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/context.rs b/src/context.rs index 1a296627c..46613ffe9 100644 --- a/src/context.rs +++ b/src/context.rs @@ -107,7 +107,7 @@ impl Default for BobStatus { pub struct SmtpState { pub idle: bool, pub suspended: bool, - pub doing_jobs: i32, + pub doing_jobs: bool, pub perform_jobs_needed: i32, pub probe_network: bool, } diff --git a/src/dc_job.rs b/src/dc_job.rs index f1f9bfa8b..07080d2a4 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -283,7 +283,7 @@ unsafe fn dc_suspend_smtp_thread(context: &Context, suspend: bool) { context.smtp_state.0.lock().unwrap().suspended = suspend; if suspend { loop { - if context.smtp_state.0.lock().unwrap().doing_jobs == 0 { + if !context.smtp_state.0.lock().unwrap().doing_jobs { return; } std::thread::sleep(std::time::Duration::from_micros(300 * 1000)); @@ -1049,7 +1049,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) { info!(context, 0, "SMTP-jobs suspended.",); return; } - state.doing_jobs = 1; + state.doing_jobs = true; probe_smtp_network }; @@ -1061,7 +1061,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) { let &(ref lock, _) = &*context.smtp_state.clone(); let mut state = lock.lock().unwrap(); - state.doing_jobs = 0; + state.doing_jobs = false; } }