Commit 5c7c9a76 authored by Kamil Dudka's avatar Kamil Dudka
Browse files

url: provide dead_connection flag in Curl_handler::disconnect

It helps to prevent a hangup with some FTP servers in case idle session
timeout has exceeded.  But it may be useful also for other protocols
that send any quit message on disconnect.  Currently used by FTP, POP3,
IMAP and SMTP.
parent bf1c102b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ static CURLcode ftp_do(struct connectdata *conn, bool *done);
static CURLcode ftp_done(struct connectdata *conn,
                         CURLcode, bool premature);
static CURLcode ftp_connect(struct connectdata *conn, bool *done);
static CURLcode ftp_disconnect(struct connectdata *conn);
static CURLcode ftp_disconnect(struct connectdata *conn, bool dead_connection);
static CURLcode ftp_nextconnect(struct connectdata *conn);
static CURLcode ftp_multi_statemach(struct connectdata *conn, bool *done);
static int ftp_getsock(struct connectdata *conn,
@@ -3840,7 +3840,7 @@ static CURLcode ftp_quit(struct connectdata *conn)
 * Disconnect from an FTP server. Cleanup protocol-specific per-connection
 * resources. BLOCKING.
 */
static CURLcode ftp_disconnect(struct connectdata *conn)
static CURLcode ftp_disconnect(struct connectdata *conn, bool dead_connection)
{
  struct ftp_conn *ftpc= &conn->proto.ftpc;
  struct pingpong *pp = &ftpc->pp;
@@ -3852,6 +3852,8 @@ static CURLcode ftp_disconnect(struct connectdata *conn)
     ftp_quit() will check the state of ftp->ctl_valid. If it's ok it
     will try to send the QUIT command, otherwise it will just return.
  */
  if(dead_connection)
    ftpc->ctl_valid = FALSE;

  /* The FTP session may or may not have been allocated/setup at this point! */
  (void)ftp_quit(conn); /* ignore errors on the QUIT */
+3 −3
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ static CURLcode imap_do(struct connectdata *conn, bool *done);
static CURLcode imap_done(struct connectdata *conn,
                          CURLcode, bool premature);
static CURLcode imap_connect(struct connectdata *conn, bool *done);
static CURLcode imap_disconnect(struct connectdata *conn);
static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection);
static CURLcode imap_multi_statemach(struct connectdata *conn, bool *done);
static int imap_getsock(struct connectdata *conn,
                        curl_socket_t *socks,
@@ -877,13 +877,13 @@ static CURLcode imap_logout(struct connectdata *conn)
 * Disconnect from an IMAP server. Cleanup protocol-specific per-connection
 * resources. BLOCKING.
 */
static CURLcode imap_disconnect(struct connectdata *conn)
static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection)
{
  struct imap_conn *imapc= &conn->proto.imapc;

  /* The IMAP session may or may not have been allocated/setup at this
     point! */
  if (imapc->pp.conn)
  if(!dead_connection && imapc->pp.conn)
    (void)imap_logout(conn); /* ignore errors on the LOGOUT */

  Curl_pp_disconnect(&imapc->pp);
+4 −3
Original line number Diff line number Diff line
@@ -1634,7 +1634,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
        }

        if(disconnect_conn) {
          Curl_disconnect(easy->easy_conn); /* disconnect properly */
          /* disconnect properly */
          Curl_disconnect(easy->easy_conn, /* dead_connection */ FALSE);

          /* This is where we make sure that the easy_conn pointer is reset.
             We don't have to do this in every case block above where a
@@ -1759,7 +1760,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle)
    for(i=0; i< multi->connc->num; i++) {
      if(multi->connc->connects[i] &&
         multi->connc->connects[i]->protocol & PROT_CLOSEACTION) {
        Curl_disconnect(multi->connc->connects[i]);
        Curl_disconnect(multi->connc->connects[i], /* dead_connection */ FALSE);
        multi->connc->connects[i] = NULL;
      }
    }
@@ -2665,7 +2666,7 @@ static void multi_connc_remove_handle(struct Curl_multi *multi,
          data->state.shared_conn = multi;
        else {
          /* out of memory - so much for graceful shutdown */
          Curl_disconnect(conn);
          Curl_disconnect(conn, /* dead_connection */ FALSE);
          multi->connc->connects[i] = NULL;
        }
      }
+3 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done);
static CURLcode ldap_done(struct connectdata *conn, CURLcode, bool);
static CURLcode ldap_connect(struct connectdata *conn, bool *done);
static CURLcode ldap_connecting(struct connectdata *conn, bool *done);
static CURLcode ldap_disconnect(struct connectdata *conn);
static CURLcode ldap_disconnect(struct connectdata *conn, bool dead_connection);

static Curl_recv ldap_recv;

@@ -344,9 +344,10 @@ retry:
  return CURLE_OK;
}

static CURLcode ldap_disconnect(struct connectdata *conn)
static CURLcode ldap_disconnect(struct connectdata *conn, bool dead_connection)
{
  ldapconninfo *li = conn->proto.generic;
  (void) dead_connection;

  if (li) {
    if (li->ld) {
+3 −3
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ static CURLcode pop3_do(struct connectdata *conn, bool *done);
static CURLcode pop3_done(struct connectdata *conn,
                          CURLcode, bool premature);
static CURLcode pop3_connect(struct connectdata *conn, bool *done);
static CURLcode pop3_disconnect(struct connectdata *conn);
static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection);
static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done);
static int pop3_getsock(struct connectdata *conn,
                        curl_socket_t *socks,
@@ -817,7 +817,7 @@ static CURLcode pop3_quit(struct connectdata *conn)
 * Disconnect from an POP3 server. Cleanup protocol-specific per-connection
 * resources. BLOCKING.
 */
static CURLcode pop3_disconnect(struct connectdata *conn)
static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection)
{
  struct pop3_conn *pop3c= &conn->proto.pop3c;

@@ -828,7 +828,7 @@ static CURLcode pop3_disconnect(struct connectdata *conn)

  /* The POP3 session may or may not have been allocated/setup at this
     point! */
  if(pop3c->pp.conn)
  if(!dead_connection && pop3c->pp.conn)
    (void)pop3_quit(conn); /* ignore errors on the LOGOUT */


Loading