aboutsummaryrefslogtreecommitdiff
path: root/src/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine.c')
-rw-r--r--src/engine.c79
1 files changed, 46 insertions, 33 deletions
diff --git a/src/engine.c b/src/engine.c
index 1801fdec..bb3fa18c 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -307,8 +307,22 @@ smtp_io_data_destroy(struct smtp_io_data *dat)
-#define UPDATE_TTW(t,start) do { \
- time_t delta = time(NULL) - start; \
- if (t > delta) \
- t -= delta; \
+struct timeout_ctl {
+ time_t start;
+ time_t timeout;
+};
+
+static void
+init_timeout_ctl(struct timeout_ctl *tctl, time_t timeout)
+{
+ tctl->start = time(NULL);
+ tctl->timeout = timeout;
+}
+
+#define UPDATE_TTW(t) do { \
+ time_t now = time(NULL); \
+ time_t delta = now - (t).start; \
+ if ((t).timeout > delta) \
+ (t).timeout -= delta; \
else \
- t = 0; \
+ (t).timeout = 0; \
+ (t).start = now; \
} while (0)
@@ -316,3 +330,3 @@ smtp_io_data_destroy(struct smtp_io_data *dat)
int
-smtp_stream_wait(mu_stream_t stream, int flags, time_t *timeout)
+smtp_stream_wait(mu_stream_t stream, int flags, struct timeout_ctl *tctl)
{
@@ -321,6 +335,5 @@ smtp_stream_wait(mu_stream_t stream, int flags, time_t *timeout)
struct timeval tv;
- time_t start = time(NULL);
- while (*timeout) {
- tv.tv_sec = *timeout;
+ while (tctl->timeout) {
+ tv.tv_sec = tctl->timeout;
tv.tv_usec = 0;
@@ -329,3 +342,3 @@ smtp_stream_wait(mu_stream_t stream, int flags, time_t *timeout)
/* Correct the timeout */
- UPDATE_TTW(*timeout, start);
+ UPDATE_TTW(*tctl);
@@ -349,5 +362,5 @@ smtp_stream_wait(mu_stream_t stream, int flags, time_t *timeout)
int
-smtp_wait(struct smtp_io_data *dat, int flags, time_t *timeout)
+smtp_wait(struct smtp_io_data *dat, int flags, struct timeout_ctl *tctl)
{
- return smtp_stream_wait(dat->stream, flags, timeout);
+ return smtp_stream_wait(dat->stream, flags, tctl);
}
@@ -358,4 +371,5 @@ smtp_send(struct smtp_io_data *dat, char *command)
size_t len = strlen(command);
- time_t timeout = io_timeout;
- time_t start = time(NULL);
+ struct timeout_ctl tctl;
+
+ init_timeout_ctl (&tctl, io_timeout);
@@ -367,3 +381,3 @@ smtp_send(struct smtp_io_data *dat, char *command)
- UPDATE_TTW(timeout, start);
+ UPDATE_TTW(tctl);
@@ -380,4 +394,3 @@ smtp_send(struct smtp_io_data *dat, char *command)
} else if (rc == EAGAIN) {
- rc = smtp_wait(dat, MU_STREAM_READY_WR,
- &timeout);
+ rc = smtp_wait(dat, MU_STREAM_READY_WR, &tctl);
if (rc) {
@@ -426,4 +439,4 @@ smtp_recvline(struct smtp_io_data *dat, time_t timeout)
{
- time_t start = time(NULL);
-
+ struct timeout_ctl tctl;
+ init_timeout_ctl(&tctl, timeout);
for (;;) {
@@ -431,4 +444,4 @@ smtp_recvline(struct smtp_io_data *dat, time_t timeout)
- UPDATE_TTW(timeout, start);
-
+ UPDATE_TTW(tctl);
+
if (dat->level == 0) {
@@ -445,4 +458,3 @@ smtp_recvline(struct smtp_io_data *dat, time_t timeout)
rc = smtp_wait(dat,
- MU_STREAM_READY_RD,
- &timeout);
+ MU_STREAM_READY_RD, &tctl);
if (rc) {
@@ -565,3 +577,3 @@ check_on_host(eval_environ_t env, char *email, char *client_addr,
SMFICTX *ctx = env_get_context(env);
- time_t timeout, start = time(NULL);
+ struct timeout_ctl tctl;
@@ -580,11 +592,11 @@ check_on_host(eval_environ_t env, char *email, char *client_addr,
}
-
- timeout = connect_timeout;
+
+ init_timeout_ctl(&tctl, connect_timeout);
while ((rc = mu_stream_open(stream))) {
if ((rc == EAGAIN || rc == EINPROGRESS)
- && timeout) {
+ && tctl.timeout) {
rc = smtp_stream_wait(stream, MU_STREAM_READY_WR,
- &timeout);
+ &tctl);
if (rc == 0) {
- UPDATE_TTW(timeout, start);
+ UPDATE_TTW(tctl);
continue;
@@ -829,3 +841,3 @@ listens_on (const char *client_addr, int port)
int rc;
- time_t timeout = connect_timeout, start = time(NULL);
+ struct timeout_ctl tctl;
@@ -844,8 +856,9 @@ listens_on (const char *client_addr, int port)
+ init_timeout_ctl(&tctl, connect_timeout);
while ((rc = mu_stream_open(stream))) {
- if ((rc == EAGAIN || rc == EINPROGRESS) && timeout) {
+ if ((rc == EAGAIN || rc == EINPROGRESS) && tctl.timeout) {
rc = smtp_stream_wait(stream, MU_STREAM_READY_WR,
- &timeout);
+ &tctl);
if (rc == 0) {
- UPDATE_TTW(timeout, start);
+ UPDATE_TTW(tctl);
continue;

Return to:

Send suggestions and report system problems to the System administrator.