Skip to content

Commit

Permalink
lib-smtp: client: Properly manage command timeout during transaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch authored and cmouse committed Oct 10, 2018
1 parent 887b209 commit e6c9e36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/lib-smtp/smtp-client-command.c
Expand Up @@ -522,7 +522,7 @@ smtp_client_command_send_stream(struct smtp_client_command *cmd)
i_unreached();
}

int smtp_client_command_send_more(struct smtp_client_connection *conn)
static int smtp_client_command_do_send_more(struct smtp_client_connection *conn)
{
struct smtp_client_command *cmd;
const char *data;
Expand Down Expand Up @@ -621,6 +621,17 @@ int smtp_client_command_send_more(struct smtp_client_connection *conn)
return 0;
}

int smtp_client_command_send_more(struct smtp_client_connection *conn)
{
int ret;

if ((ret=smtp_client_command_do_send_more(conn)) < 0)
return -1;

smtp_client_connection_update_cmd_timeout(conn);
return ret;
}

static void
smtp_client_command_disconnected(struct smtp_client_connection *conn)
{
Expand Down
10 changes: 4 additions & 6 deletions src/lib-smtp/smtp-client-connection.c
Expand Up @@ -228,7 +228,7 @@ void smtp_client_connection_start_cmd_timeout(
{
unsigned int msecs = conn->set.command_timeout_msecs;

if (conn->state != SMTP_CLIENT_CONNECTION_STATE_READY) {
if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY) {
/* pre-login uses connect timeout */
return;
}
Expand All @@ -237,8 +237,7 @@ void smtp_client_connection_start_cmd_timeout(
timeout_remove(&conn->to_commands);
return;
}
if (conn->cmd_wait_list_head == NULL &&
conn->cmd_send_queue_head == NULL) {
if (conn->cmd_wait_list_head == NULL && !conn->sending_command) {
/* no commands pending */
timeout_remove(&conn->to_commands);
return;
Expand All @@ -256,7 +255,7 @@ void smtp_client_connection_update_cmd_timeout(
{
unsigned int msecs = conn->set.command_timeout_msecs;

if (conn->state != SMTP_CLIENT_CONNECTION_STATE_READY) {
if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY) {
/* pre-login uses connect timeout */
return;
}
Expand All @@ -266,8 +265,7 @@ void smtp_client_connection_update_cmd_timeout(
return;
}

if (conn->cmd_wait_list_head == NULL &&
conn->cmd_send_queue_head == NULL) {
if (conn->cmd_wait_list_head == NULL && !conn->sending_command) {
if (conn->to_commands != NULL) {
smtp_client_connection_debug(conn,
"No commands pending; stop timeout");
Expand Down

0 comments on commit e6c9e36

Please sign in to comment.