diff options
author | Daniel Stenberg <daniel@haxx.se> | 2006-06-22 21:36:53 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2006-06-22 21:36:53 +0000 |
commit | dfe1884c2529d728750d0824f73055627673cd72 (patch) | |
tree | 4f6d30648e54d10f10401408f0f819ff344ce318 /lib/multi.c | |
parent | 3e5dcc8bcd4aaa7b6d7f8432327cbdd5487113e4 (diff) |
Peter Silva introduced CURLOPT_MAX_SEND_SPEED_LARGE and
CURLOPT_MAX_RECV_SPEED_LARGE that limit tha maximum rate libcurl is allowed
to send or receive data. This kind of adds the the command line tool's
option --limit-rate to the library.
The rate limiting logic in the curl app is now removed and is instead
provided by libcurl itself. Transfer rate limiting will now also work for -d
and -F, which it didn't before.
Diffstat (limited to 'lib/multi.c')
-rw-r--r-- | lib/multi.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/multi.c b/lib/multi.c index bafadd446..9201402a2 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -68,6 +68,7 @@ typedef enum { CURLM_STATE_DOING, /* sending off the request (part 1) */ CURLM_STATE_DO_MORE, /* send off the request (part 2) */ CURLM_STATE_PERFORM, /* transfer data */ + CURLM_STATE_TOOFAST, /* wait because limit-rate exceeded */ CURLM_STATE_DONE, /* post data transfer operation */ CURLM_STATE_COMPLETED, /* operation complete */ @@ -156,6 +157,7 @@ static void multistate(struct Curl_one_easy *easy, CURLMstate state) "DOING", "DO_MORE", "PERFORM", + "TOOFAST", "DONE", "COMPLETED", }; @@ -440,6 +442,7 @@ static int multi_getsock(struct Curl_one_easy *easy, int numsocks) { switch(easy->state) { + case CURLM_STATE_TOOFAST: /* returns 0, so will not select. */ default: return 0; @@ -771,7 +774,37 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, } break; + case CURLM_STATE_TOOFAST: /* limit-rate exceeded in either direction */ + /* if both rates are within spec, resume transfer */ + Curl_pgrsUpdate(easy->easy_conn); + if ( ( ( easy->easy_handle->set.max_send_speed == 0 ) || + ( easy->easy_handle->progress.ulspeed < + easy->easy_handle->set.max_send_speed ) ) && + ( ( easy->easy_handle->set.max_recv_speed == 0 ) || + ( easy->easy_handle->progress.dlspeed < + easy->easy_handle->set.max_recv_speed ) ) + ) + multistate(easy, CURLM_STATE_PERFORM); + + break; + case CURLM_STATE_PERFORM: + + /* check if over speed */ + if ( ( ( easy->easy_handle->set.max_send_speed > 0 ) && + ( easy->easy_handle->progress.ulspeed > + easy->easy_handle->set.max_send_speed ) ) || + ( ( easy->easy_handle->set.max_recv_speed > 0 ) && + ( easy->easy_handle->progress.dlspeed > + easy->easy_handle->set.max_recv_speed ) ) + ) { + /* Transfer is over the speed limit. Change state. TODO: Call + * Curl_expire() with the time left until we're targeted to be below + * the speed limit again. */ + multistate(easy, CURLM_STATE_TOOFAST ); + break; + } + /* read/write data if it is ready to do so */ easy->result = Curl_readwrite(easy->easy_conn, &done); @@ -825,6 +858,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi, } } break; + case CURLM_STATE_DONE: /* post-transfer command */ easy->result = Curl_done(&easy->easy_conn, CURLE_OK); |