diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ftp.c | 8 | ||||
-rw-r--r-- | lib/imap.c | 8 | ||||
-rw-r--r-- | lib/pingpong.c | 74 | ||||
-rw-r--r-- | lib/pingpong.h | 17 | ||||
-rw-r--r-- | lib/pop3.c | 8 | ||||
-rw-r--r-- | lib/smtp.c | 10 | ||||
-rw-r--r-- | lib/ssh.c | 8 |
7 files changed, 48 insertions, 85 deletions
@@ -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; diff --git a/lib/imap.c b/lib/imap.c index 77d6e1b8c..8607d0011 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -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; } diff --git a/lib/pingpong.c b/lib/pingpong.c index 330b47f76..eeeeec339 100644 --- a/lib/pingpong.c +++ b/lib/pingpong.c @@ -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; } diff --git a/lib/pingpong.h b/lib/pingpong.h index b8ed91ca4..81d0c32a3 100644 --- a/lib/pingpong.h +++ b/lib/pingpong.h @@ -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); diff --git a/lib/pop3.c b/lib/pop3.c index ffbb5156f..b94f6f7e4 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -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; } diff --git a/lib/smtp.c b/lib/smtp.c index fc080ee9b..efb365930 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -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; } @@ -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")); |