diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-06-18 18:18:20 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-06-18 18:18:20 +0400 |
commit | 7ac1c6efb3361614aa68aa31494346903cd27fcc (patch) | |
tree | e687be443263b75895f3ccd38c89d0375abb0fef /src/smtp.c | |
parent | da8c2bff3fb4b959ceb4ce5c8b72d6e83ec81f03 (diff) | |
download | rspamd-7ac1c6efb3361614aa68aa31494346903cd27fcc.tar.gz rspamd-7ac1c6efb3361614aa68aa31494346903cd27fcc.zip |
* Some performance improvements to IO dispatcher (do not drain the whole buffer after a single line readed)
* Fix smtp data input
Diffstat (limited to 'src/smtp.c')
-rw-r--r-- | src/smtp.c | 63 |
1 files changed, 10 insertions, 53 deletions
diff --git a/src/smtp.c b/src/smtp.c index c7e9dc428..7860f1ac5 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -405,8 +405,6 @@ static gboolean smtp_read_socket (f_str_t * in, void *arg) { struct smtp_session *session = arg; - char *p; - gboolean do_write; switch (session->state) { case SMTP_STATE_RESOLVE_REVERSE: @@ -429,58 +427,17 @@ smtp_read_socket (f_str_t * in, void *arg) if (in->len == 0) { return TRUE; } - p = in->begin + in->len; - do_write = TRUE; - if (in->len > sizeof (session->data_end)) { - /* New data is more than trailer buffer */ - if (session->data_idx != 0 && write (session->temp_fd, session->data_end, session->data_idx) != session->data_idx) { - msg_err ("cannot write to temp file: %s", strerror (errno)); - session->error = SMTP_ERROR_FILE; - session->state = SMTP_STATE_CRITICAL_ERROR; - rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE); - destroy_session (session->s); - return FALSE; - } - memcpy (session->data_end, p - sizeof (session->data_end), sizeof (session->data_end)); - session->data_idx = 5; - } - else if (session->data_idx + in->len < sizeof (session->data_end)){ - /* New data is less than trailer buffer plus index */ - memcpy (session->data_end + session->data_idx, in->begin, in->len); - session->data_idx += in->len; - do_write = FALSE; + if (in->len == 3 && memcmp (in->begin, DATA_END_TRAILER, in->len) == 0) { + return process_smtp_data (session); } - else { - /* Save remaining bytes */ - if (session->data_idx != 0 && write (session->temp_fd, session->data_end, session->data_idx) != session->data_idx) { - msg_err ("cannot write to temp file: %s", strerror (errno)); - session->error = SMTP_ERROR_FILE; - session->state = SMTP_STATE_CRITICAL_ERROR; - rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE); - destroy_session (session->s); - return FALSE; - } - /* Move bytes */ - session->data_idx = sizeof (session->data_end) - in->len; - memmove (session->data_end, session->data_end + (sizeof (session->data_end) - in->len) + 1, sizeof (session->data_end) - in->len); - memcpy (session->data_end + session->data_idx, in->begin, in->len); - session->data_idx = 5; - } - if (do_write) { - if (session->data_idx < in->len) { - if (in->len - session->data_idx != 0 && - write (session->temp_fd, in->begin, in->len - session->data_idx) != in->len - session->data_idx) { - msg_err ("cannot write to temp file: %s", strerror (errno)); - session->error = SMTP_ERROR_FILE; - session->state = SMTP_STATE_CRITICAL_ERROR; - rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE); - destroy_session (session->s); - return FALSE; - } - } - if (memcmp (session->data_end, DATA_END_TRAILER, sizeof (session->data_end)) == 0) { - return process_smtp_data (session); - } + + if (write (session->temp_fd, in->begin, in->len) != in->len) { + msg_err ("cannot write to temp file: %s", strerror (errno)); + session->error = SMTP_ERROR_FILE; + session->state = SMTP_STATE_CRITICAL_ERROR; + rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE); + destroy_session (session->s); + return FALSE; } break; case SMTP_STATE_WAIT_UPSTREAM: |