]> granicus.if.org Git - curl/commitdiff
rename "easy" statemachines: call them block instead
authorDaniel Stenberg <daniel@haxx.se>
Fri, 15 Feb 2013 10:03:42 +0000 (11:03 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 15 Feb 2013 10:10:18 +0000 (11:10 +0100)
... since they're not used by the easy interface really, I wanted to
remove the association. Also, I unified the pingpong statemachine driver
into a single function with a 'wait' argument: Curl_pp_statemach.

lib/ftp.c
lib/imap.c
lib/pingpong.c
lib/pingpong.h
lib/pop3.c
lib/smtp.c
lib/ssh.c

index 228d834a23b9ae670046a3adaa1ede3a3c059303..dc9fc4816a075ba2432d768ab777a6e4135c3698 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -3124,7 +3124,7 @@ static CURLcode ftp_multi_statemach(struct connectdata *conn,
                                     bool *done)
 {
   struct ftp_conn *ftpc = &conn->proto.ftpc;
-  CURLcode result = Curl_pp_multi_statemach(&ftpc->pp);
+  CURLcode result = Curl_pp_statemach(&ftpc->pp, FALSE);
 
   /* Check for the state outside of the Curl_socket_ready() return code checks
      since at times we are in fact already in this state when this function
@@ -3134,14 +3134,14 @@ static CURLcode ftp_multi_statemach(struct connectdata *conn,
   return result;
 }
 
-static CURLcode ftp_easy_statemach(struct connectdata *conn)
+static CURLcode ftp_block_statemach(struct connectdata *conn)
 {
   struct ftp_conn *ftpc = &conn->proto.ftpc;
   struct pingpong *pp = &ftpc->pp;
   CURLcode result = CURLE_OK;
 
   while(ftpc->state != FTP_STOP) {
-    result = Curl_pp_easy_statemach(pp);
+    result = Curl_pp_statemach(pp, TRUE);
     if(result)
       break;
   }
@@ -4193,7 +4193,7 @@ static CURLcode ftp_quit(struct connectdata *conn)
 
     state(conn, FTP_QUIT);
 
-    result = ftp_easy_statemach(conn);
+    result = ftp_block_statemach(conn);
   }
 
   return result;
index 77d6e1b8c58d8f92dea833cf3b21afd699be1e9b..8607d001198eac251a2c7c6371ed78e187bfcf18 100644 (file)
@@ -1340,21 +1340,21 @@ static CURLcode imap_multi_statemach(struct connectdata *conn, bool *done)
   if((conn->handler->flags & PROTOPT_SSL) && !imapc->ssldone)
     result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &imapc->ssldone);
   else
-    result = Curl_pp_multi_statemach(&imapc->pp);
+    result = Curl_pp_statemach(&imapc->pp, FALSE);
 
   *done = (imapc->state == IMAP_STOP) ? TRUE : FALSE;
 
   return result;
 }
 
-static CURLcode imap_easy_statemach(struct connectdata *conn)
+static CURLcode imap_block_statemach(struct connectdata *conn)
 {
   struct imap_conn *imapc = &conn->proto.imapc;
   struct pingpong *pp = &imapc->pp;
   CURLcode result = CURLE_OK;
 
   while(imapc->state != IMAP_STOP) {
-    result = Curl_pp_easy_statemach(pp);
+    result = Curl_pp_statemach(pp, TRUE);
     if(result)
       break;
   }
@@ -1575,7 +1575,7 @@ static CURLcode imap_logout(struct connectdata *conn)
 
   state(conn, IMAP_LOGOUT);
 
-  result = imap_easy_statemach(conn);
+  result = imap_block_statemach(conn);
 
   return result;
 }
index 330b47f76cdff3020efa3da14db5ed257a459ad7..eeeeec33919eb75e785a280388cc9845a9151ed8 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -76,48 +76,10 @@ long Curl_pp_state_timeout(struct pingpong *pp)
   return timeout_ms;
 }
 
-
 /*
- * Curl_pp_multi_statemach()
- *
- * called repeatedly until done when the multi interface is used.
+ * Curl_pp_statemach()
  */
-CURLcode Curl_pp_multi_statemach(struct pingpong *pp)
-{
-  struct connectdata *conn = pp->conn;
-  curl_socket_t sock = conn->sock[FIRSTSOCKET];
-  int rc;
-  struct SessionHandle *data=conn->data;
-  CURLcode result = CURLE_OK;
-  long timeout_ms = Curl_pp_state_timeout(pp);
-
-  if(timeout_ms <= 0) {
-    failf(data, "server response timeout");
-    return CURLE_OPERATION_TIMEDOUT;
-  }
-
-  rc = Curl_socket_ready(pp->sendleft?CURL_SOCKET_BAD:sock, /* reading */
-                         pp->sendleft?sock:CURL_SOCKET_BAD, /* writing */
-                         0);
-
-  if(rc == -1) {
-    failf(data, "select/poll error");
-    return CURLE_OUT_OF_MEMORY;
-  }
-  else if(rc != 0)
-    result = pp->statemach_act(conn);
-
-  /* if rc == 0, then select() timed out */
-
-  return result;
-}
-
-/*
- * Curl_pp_easy_statemach()
- *
- * called repeatedly until done when the easy interface is used.
- */
-CURLcode Curl_pp_easy_statemach(struct pingpong *pp)
+CURLcode Curl_pp_statemach(struct pingpong *pp, bool wait)
 {
   struct connectdata *conn = pp->conn;
   curl_socket_t sock = conn->sock[FIRSTSOCKET];
@@ -125,29 +87,37 @@ CURLcode Curl_pp_easy_statemach(struct pingpong *pp)
   long interval_ms;
   long timeout_ms = Curl_pp_state_timeout(pp);
   struct SessionHandle *data=conn->data;
-  CURLcode result;
+  CURLcode result = CURLE_OK;
 
   if(timeout_ms <=0 ) {
     failf(data, "server response timeout");
     return CURLE_OPERATION_TIMEDOUT; /* already too little time */
   }
 
-  interval_ms = 1000;  /* use 1 second timeout intervals */
-  if(timeout_ms < interval_ms)
-    interval_ms = timeout_ms;
+  if(wait) {
+    interval_ms = 1000;  /* use 1 second timeout intervals */
+    if(timeout_ms < interval_ms)
+      interval_ms = timeout_ms;
+  }
+  else
+    interval_ms = 0; /* immediate */
 
   rc = Curl_socket_ready(pp->sendleft?CURL_SOCKET_BAD:sock, /* reading */
                          pp->sendleft?sock:CURL_SOCKET_BAD, /* writing */
                          interval_ms);
 
-  if(Curl_pgrsUpdate(conn))
-    result = CURLE_ABORTED_BY_CALLBACK;
-  else
-    result = Curl_speedcheck(data, Curl_tvnow());
+  if(wait) {
+    /* if we didn't wait, we don't have to spend time on this now */
+    if(Curl_pgrsUpdate(conn))
+      result = CURLE_ABORTED_BY_CALLBACK;
+    else
+      result = Curl_speedcheck(data, Curl_tvnow());
 
-  if(result)
-    ;
-  else if(rc == -1) {
+    if(result)
+      return result;
+  }
+
+  if(rc == -1) {
     failf(data, "select/poll error");
     result = CURLE_OUT_OF_MEMORY;
   }
index b8ed91ca4e69acc8549bfa3ae91750d585e0c2a3..81d0c32a35318a8c7204f735f45cf7f9147e1582 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -69,19 +69,12 @@ struct pingpong {
 };
 
 /*
- * Curl_pp_multi_statemach()
+ * Curl_pp_statemach()
  *
- * called repeatedly until done when the multi interface is used.
+ * called repeatedly until done. Set 'wait' to make it wait a while on the
+ * socket if there's no traffic.
  */
-CURLcode Curl_pp_multi_statemach(struct pingpong *pp);
-
-/*
- * Curl_pp_easy_statemach()
- *
- * called repeatedly until done when the easy interface is used.
- */
-CURLcode Curl_pp_easy_statemach(struct pingpong *pp);
-
+CURLcode Curl_pp_statemach(struct pingpong *pp, bool wait);
 
 /* initialize stuff to prepare for reading a fresh new response */
 void Curl_pp_init(struct pingpong *pp);
index ffbb5156f601da49f40bf70d8c9bbda004f4bfa5..b94f6f7e433813d00e68431ededd79e4d98857f1 100644 (file)
@@ -1263,21 +1263,21 @@ static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done)
   if((conn->handler->flags & PROTOPT_SSL) && !pop3c->ssldone)
     result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &pop3c->ssldone);
   else
-    result = Curl_pp_multi_statemach(&pop3c->pp);
+    result = Curl_pp_statemach(&pop3c->pp, FALSE);
 
   *done = (pop3c->state == POP3_STOP) ? TRUE : FALSE;
 
   return result;
 }
 
-static CURLcode pop3_easy_statemach(struct connectdata *conn)
+static CURLcode pop3_block_statemach(struct connectdata *conn)
 {
   struct pop3_conn *pop3c = &conn->proto.pop3c;
   struct pingpong *pp = &pop3c->pp;
   CURLcode result = CURLE_OK;
 
   while(pop3c->state != POP3_STOP) {
-    result = Curl_pp_easy_statemach(pp);
+    result = Curl_pp_statemach(pp, TRUE);
     if(result)
       break;
   }
@@ -1506,7 +1506,7 @@ static CURLcode pop3_quit(struct connectdata *conn)
 
   state(conn, POP3_QUIT);
 
-  result = pop3_easy_statemach(conn);
+  result = pop3_block_statemach(conn);
 
   return result;
 }
index fc080ee9bef7f0dfa388283a39633228365d23f5..efb3659300ffac857e7ed789a280e569b7be18b1 100644 (file)
@@ -1254,21 +1254,21 @@ static CURLcode smtp_multi_statemach(struct connectdata *conn, bool *done)
   if((conn->handler->flags & PROTOPT_SSL) && !smtpc->ssldone)
     result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &smtpc->ssldone);
   else
-    result = Curl_pp_multi_statemach(&smtpc->pp);
+    result = Curl_pp_statemach(&smtpc->pp, FALSE);
 
   *done = (smtpc->state == SMTP_STOP) ? TRUE : FALSE;
 
   return result;
 }
 
-static CURLcode smtp_easy_statemach(struct connectdata *conn)
+static CURLcode smtp_block_statemach(struct connectdata *conn)
 {
   struct smtp_conn *smtpc = &conn->proto.smtpc;
   struct pingpong *pp = &smtpc->pp;
   CURLcode result = CURLE_OK;
 
   while(smtpc->state != SMTP_STOP) {
-    result = Curl_pp_easy_statemach(pp);
+    result = Curl_pp_statemach(pp, TRUE);
     if(result)
       break;
   }
@@ -1437,7 +1437,7 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
        non-blocking DONE operations, not in the multi state machine and with
        Curl_done() invokes on several places in the code!
     */
-    result = smtp_easy_statemach(conn);
+    result = smtp_block_statemach(conn);
   }
 
   /* Clear the transfer mode for the next connection */
@@ -1534,7 +1534,7 @@ static CURLcode smtp_quit(struct connectdata *conn)
 
   state(conn, SMTP_QUIT);
 
-  result = smtp_easy_statemach(conn);
+  result = smtp_block_statemach(conn);
 
   return result;
 }
index 0c7d36ecc94c55038e3ac5ad21116e2251e0f790..9b37ad69e2fa66c68b0e59f707135d12149ff1f0 100644 (file)
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -2635,7 +2635,7 @@ static CURLcode ssh_multi_statemach(struct connectdata *conn, bool *done)
   return result;
 }
 
-static CURLcode ssh_easy_statemach(struct connectdata *conn,
+static CURLcode ssh_block_statemach(struct connectdata *conn,
                                    bool duringconnect)
 {
   struct ssh_conn *sshc = &conn->proto.sshc;
@@ -2902,7 +2902,7 @@ static CURLcode scp_disconnect(struct connectdata *conn, bool dead_connection)
 
     state(conn, SSH_SESSION_DISCONNECT);
 
-    result = ssh_easy_statemach(conn, FALSE);
+    result = ssh_block_statemach(conn, FALSE);
   }
 
   return result;
@@ -2923,7 +2923,7 @@ static CURLcode ssh_done(struct connectdata *conn, CURLcode status)
        non-blocking DONE operations, not in the multi state machine and with
        Curl_done() invokes on several places in the code!
     */
-    result = ssh_easy_statemach(conn, FALSE);
+    result = ssh_block_statemach(conn, FALSE);
   }
   else
     result = status;
@@ -3065,7 +3065,7 @@ static CURLcode sftp_disconnect(struct connectdata *conn, bool dead_connection)
   if(conn->proto.sshc.ssh_session) {
     /* only if there's a session still around to use! */
     state(conn, SSH_SFTP_SHUTDOWN);
-    result = ssh_easy_statemach(conn, FALSE);
+    result = ssh_block_statemach(conn, FALSE);
   }
 
   DEBUGF(infof(conn->data, "SSH DISCONNECT is done\n"));