diff --git a/cos_c_sdk/cos_http_io.c b/cos_c_sdk/cos_http_io.c index 3df997d..4dc5597 100644 --- a/cos_c_sdk/cos_http_io.c +++ b/cos_c_sdk/cos_http_io.c @@ -63,6 +63,27 @@ void request_release(CURL *request) } } +void request_release2(cos_curl_http_transport_t* t) +{ + CURL* request = t->curl; + CURLcode code = t->curl_code; + apr_thread_mutex_lock(requestStackMutexG); + + // If the request stack is full, destroy this one + // else put this one at the front of the request stack; we do this because + // we want the most-recently-used curl handle to be re-used on the next + // request, to maximize our chances of re-using a TCP connection before it + // times out + if (requestStackCountG == COS_REQUEST_STACK_SIZE || code != CURLE_OK) { + apr_thread_mutex_unlock(requestStackMutexG); + curl_easy_cleanup(request); + } + else { + requestStackG[requestStackCountG++] = request; + apr_thread_mutex_unlock(requestStackMutexG); + } +} + void cos_set_default_request_options(cos_http_request_options_t *op) { cos_default_http_request_options = op; diff --git a/cos_c_sdk/cos_http_io.h b/cos_c_sdk/cos_http_io.h index 8dc0407..c4bb306 100644 --- a/cos_c_sdk/cos_http_io.h +++ b/cos_c_sdk/cos_http_io.h @@ -18,6 +18,7 @@ static APR_INLINE const char *cos_http_controller_get_reason(cos_http_controller CURL *cos_request_get(); void request_release(CURL *request); +void request_release2(cos_curl_http_transport_t* t); int cos_http_io_initialize(const char *user_agent_info, int flag); void cos_http_io_deinitialize(); diff --git a/cos_c_sdk/cos_sys_define.h b/cos_c_sdk/cos_sys_define.h index a7901bf..7184527 100644 --- a/cos_c_sdk/cos_sys_define.h +++ b/cos_c_sdk/cos_sys_define.h @@ -132,7 +132,7 @@ typedef apr_array_header_t cos_array_header_t; #define CR (char) 13 #define CRLF "\x0d\x0a" -#define COS_VERSION "5.0.17" +#define COS_VERSION "5.0.18" #define COS_VER "cos-sdk-c/" COS_VERSION #define COS_HTTP_PREFIX "http://" diff --git a/cos_c_sdk/cos_transport.c b/cos_c_sdk/cos_transport.c index 6a0a50e..283985c 100644 --- a/cos_c_sdk/cos_transport.c +++ b/cos_c_sdk/cos_transport.c @@ -152,8 +152,8 @@ cos_http_transport_t *cos_curl_http_transport_create(cos_pool_t *p) cos_fstack_push(t->cleanup, t, func, 1); t->curl = cos_request_get(); - func.func1 = (cos_func1_pt)request_release; - cos_fstack_push(t->cleanup, t->curl, func, 1); + func.func1 = (cos_func1_pt)request_release2; + cos_fstack_push(t->cleanup, t, func, 1); t->header_callback = cos_curl_default_header_callback; t->read_callback = cos_curl_default_read_callback; @@ -487,7 +487,8 @@ int cos_curl_http_transport_perform(cos_http_transport_t *t_) code = curl_easy_perform(t->curl); t->controller->finish_time = apr_time_now(); cos_move_transport_state(t, TRANS_STATE_DONE); - + + t->curl_code = code; if ((code != CURLE_OK) && (t->controller->error_code == COSE_OK)) { ecode = cos_curl_code_to_status(code); if (ecode != COSE_OK) { diff --git a/cos_c_sdk/cos_transport.h b/cos_c_sdk/cos_transport.h index e29204d..682a933 100644 --- a/cos_c_sdk/cos_transport.h +++ b/cos_c_sdk/cos_transport.h @@ -144,6 +144,7 @@ struct cos_http_transport_s { struct cos_curl_http_transport_s { COS_HTTP_BASE_TRANSPORT_DEFINE CURL *curl; + CURLcode curl_code; char *url; struct curl_slist *headers; curl_read_callback header_callback;