Commit c25383ae authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

rename "easy" statemachines: call them block instead

... 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.
parent 6106eeba
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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;
+4 −4
Original line number Diff line number Diff line
@@ -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;
}
+22 −52
Original line number Diff line number Diff line
@@ -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.
 */
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.
 * Curl_pp_statemach()
 */
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 */
  }

  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(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) {
      return result;
  }

  if(rc == -1) {
    failf(data, "select/poll error");
    result = CURLE_OUT_OF_MEMORY;
  }
+5 −12
Original line number Diff line number Diff line
@@ -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);
+4 −4
Original line number Diff line number Diff line
@@ -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;
}
Loading