Skip to content

Commit

Permalink
lib-smtp: client: Put determining the status of the command pipeline …
Browse files Browse the repository at this point in the history
…in a separate function.
  • Loading branch information
stephanbosch committed Jan 22, 2019
1 parent 29bfd8e commit 7bec82a
Showing 1 changed file with 46 additions and 35 deletions.
81 changes: 46 additions & 35 deletions src/lib-smtp/smtp-client-command.c
Expand Up @@ -559,53 +559,64 @@ smtp_client_command_send_line(struct smtp_client_command *cmd)
return 1;
}

static bool
smtp_client_command_pipeline_is_open(struct smtp_client_connection *conn)
{
struct smtp_client_command *cmd = conn->cmd_send_queue_head;

if (cmd == NULL)
return TRUE;

if (cmd->plug) {
smtp_client_command_debug(cmd, "Pipeline is plugged");
return FALSE;
}

if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY &&
(cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRELOGIN) == 0) {
/* wait until we're fully connected */
smtp_client_command_debug(cmd,
"Connection not ready [state=%s]",
smtp_client_connection_state_names[conn->state]);
return FALSE;
}

cmd = conn->cmd_wait_list_head;
if (cmd != NULL &&
(conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0) {
/* cannot pipeline; wait for reply */
smtp_client_command_debug(cmd, "Pipeline occupied");
return FALSE;
}
while (cmd != NULL) {
if ((conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0 ||
(cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PIPELINE) == 0 ||
cmd->locked) {
/* cannot pipeline with previous command;
wait for reply */
smtp_client_command_debug(cmd, "Pipeline blocked");
return FALSE;
}
cmd = cmd->next;
}

cmd = conn->cmd_send_queue_head;
return TRUE;
}

static int smtp_client_command_do_send_more(struct smtp_client_connection *conn)
{
struct smtp_client_command *cmd;
int ret;

for (;;) {
/* check whether we can send anything */

cmd = conn->cmd_send_queue_head;
if (cmd == NULL)
return 0;

if (cmd->plug) {
smtp_client_command_debug(cmd, "Pipeline is plugged");
if (!smtp_client_command_pipeline_is_open(conn))
return 0;
}

if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY &&
(cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRELOGIN) == 0) {
/* wait until we're fully connected */
smtp_client_command_debug(cmd,
"Connection not ready [state=%s]",
smtp_client_connection_state_names[conn->state]);
return 0;
}

cmd = conn->cmd_wait_list_head;
if (cmd != NULL &&
(conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0) {
/* cannot pipeline; wait for reply */
smtp_client_command_debug(cmd, "Pipeline occupied");
return 0;
}
while (cmd != NULL) {
if ((conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0 ||
(cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PIPELINE) == 0 ||
cmd->locked) {
/* cannot pipeline with previous command;
wait for reply */
smtp_client_command_debug(cmd,
"Pipeline blocked");
return 0;
}
cmd = cmd->next;
}

cmd = conn->cmd_send_queue_head;
cmd->state = SMTP_CLIENT_COMMAND_STATE_SENDING;
conn->sending_command = TRUE;

Expand Down

0 comments on commit 7bec82a

Please sign in to comment.