Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ltratt/extsmail
base: 1a4bd9b450
...
head fork: ltratt/extsmail
compare: b20e3a7667
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 29, 2012
@ltratt If nothing's needed to be sent in a cycle, reset all externals last s…
…uccessful sends.

Since we can't tell if they've come back up or not, it's sensible to reset
them, and ensure that the next time there's a message to be sent, each is
retried.
4110d4b
@ltratt If no messages have been sent, there's no need to poll every 5s.
This is unnecessarily wasteful; poll every 60s in such circumstances, which
is quite sufficient.
b20e3a7
Showing with 37 additions and 8 deletions.
  1. +37 −8 extsmaild.c
View
45 extsmaild.c
@@ -485,6 +485,22 @@ bool cycle(Conf *conf, Group *groups, Status *status)
status->spool_loc = 0;
status->any_failure = false;
status->last_success = status->last_notify_failure = time(NULL);
+ if (num_successes == 0) {
+ // Since we haven't sent anything, we don't really know if our
+ // externals are alive or not. We therefore assume they are
+ // all live or have come back to life. Update the last_success
+ // accordingly to force them to be used the next time there are
+ // messages to send.
+ Group *cur_group = groups;
+ while (cur_group != NULL) {
+ External *cur_ext = cur_group->externals;
+ while (cur_ext != NULL) {
+ cur_ext->last_success = time(NULL);
+ cur_ext = cur_ext->next;
+ }
+ cur_group = cur_group->next;
+ }
+ }
}
else
status->any_failure = true;
@@ -1113,17 +1129,30 @@ int main(int argc, char** argv)
openlog(__progname, LOG_CONS, LOG_MAIL);
- int poll_wait = INITIAL_POLL_WAIT;
+ int unsuccessful_wait = INITIAL_POLL_WAIT;
while (1) {
- bool success = cycle(conf, groups, &status);
+ bool all_sent = cycle(conf, groups, &status);
- if (!success && conf->notify_failure_interval > 0
+ if (!all_sent && conf->notify_failure_interval > 0
&& time(NULL) >
status.last_notify_failure + conf->notify_failure_interval) {
do_notify_failure_cmd(conf, &status);
status.last_notify_failure = time(NULL);
}
+ // If all messages have been sent successfully (or if there were no
+ // messages to send), we don't want to wait INITIAL_POLL_WAIT
+ // seconds - it's far too wasteful. We might as well wait a full
+ // MAX_POLL_WAIT. If anything hasn't been sent, we wait
+ // unsuccesful_wait seconds (a gradually increasing int from
+ // INITIAL_POLL_WAIT to MAX_POLL_WAIT).
+
+ int poll_wait;
+ if (all_sent)
+ poll_wait = MAX_POLL_WAIT;
+ else
+ poll_wait = unsuccessful_wait;
+
// On platforms that support an appropriate mechanism (such as kqueue
// or inotify), we try and send messages as soon as we notice changes
// to spool_dir/msgs. We also wake-up every 'poll_wait' seconds to
@@ -1156,12 +1185,12 @@ int main(int argc, char** argv)
sleep(poll_wait);
#endif
- if (success)
- poll_wait = INITIAL_POLL_WAIT;
+ if (all_sent)
+ unsuccessful_wait = INITIAL_POLL_WAIT;
else {
- poll_wait *= 2;
- if (poll_wait > MAX_POLL_WAIT)
- poll_wait = MAX_POLL_WAIT;
+ unsuccessful_wait *= 2;
+ if (unsuccessful_wait > MAX_POLL_WAIT)
+ unsuccessful_wait = MAX_POLL_WAIT;
}
}
}

No commit comments for this range

Something went wrong with that request. Please try again.