text stringlengths 0 357 |
|---|
pthread_mutex_lock(&context->smtpidle_condmutex); |
context->smtp_doing_jobs = 0; |
pthread_mutex_unlock(&context->smtpidle_condmutex); |
} |
/** |
* Wait for smtp-jobs. |
* This function and dc_perform_smtp_jobs() must be called from the same thread, |
* typically in a loop. |
* |
* See dc_interrupt_smtp_idle() for an example. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @return None. |
*/ |
void dc_perform_smtp_idle(dc_context_t* context) |
{ |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
dc_log_warning(context, 0, "Cannot perform SMTP-idle: Bad parameters."); |
return; |
} |
dc_log_info(context, 0, "SMTP-idle started..."); |
pthread_mutex_lock(&context->smtpidle_condmutex); |
if (context->perform_smtp_jobs_needed==DC_JOBS_NEEDED_AT_ONCE) |
{ |
dc_log_info(context, 0, "SMTP-idle will not be started because of waiting jobs."); |
} |
else |
{ |
int r = 0; |
struct timespec wakeup_at; |
memset(&wakeup_at, 0, sizeof(wakeup_at)); |
wakeup_at.tv_sec = get_next_wakeup_time(context, DC_SMTP_THREAD)+1; |
while (context->smtpidle_condflag==0 && r==0) { |
r = pthread_cond_timedwait(&context->smtpidle_cond, &context->smtpidle_condmutex, &wakeup_at); // unlock mutex -> wait -> lock mutex |
} |
context->smtpidle_condflag = 0; |
} |
pthread_mutex_unlock(&context->smtpidle_condmutex); |
dc_log_info(context, 0, "SMTP-idle ended."); |
} |
/** |
* Interrupt waiting for smtp-jobs. |
* If dc_perform_smtp_jobs() and dc_perform_smtp_idle() are called in a loop, |
* calling this function causes jobs to be executed. |
* |
* dc_interrupt_smtp_idle() does _not_ interrupt dc_perform_smtp_jobs(). |
* If the smtp-thread is inside this function when dc_interrupt_smtp_idle() is called, however, |
* the next call of the smtp-thread to dc_perform_smtp_idle() is interrupted immediately. |
* |
* Internally, this function is called whenever a message is to be sent. |
* |
* When you need to call this function just because to get jobs done after network changes, |
* use dc_maybe_network() instead. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @return None. |
*/ |
void dc_interrupt_smtp_idle(dc_context_t* context) |
{ |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
dc_log_warning(context, 0, "Interrupt SMTP-idle: Bad parameters."); |
return; |
} |
dc_log_info(context, 0, "Interrupting SMTP-idle..."); |
pthread_mutex_lock(&context->smtpidle_condmutex); |
// when this function is called, it might be that the smtp-thread is in |
// perform_smtp_jobs(). if so, added jobs will be performed after the _next_ idle-jobs loop. |
// setting the flag perform_smtp_jobs_needed makes sure, idle() returns immediately in this case. |
context->perform_smtp_jobs_needed = DC_JOBS_NEEDED_AT_ONCE; |
context->smtpidle_condflag = 1; |
pthread_cond_signal(&context->smtpidle_cond); |
pthread_mutex_unlock(&context->smtpidle_condmutex); |
} |
/** |
* This function can be called whenever there is a hint |
* that the network is available again. |
* The library will try to send pending messages out. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.