Lines Matching refs:cpool

83 static void cpool_discard_conn(struct cpool *cpool,
87 static void cpool_close_and_destroy(struct cpool *cpool,
99 static void cpool_shutdown_all(struct cpool *cpool,
101 static void cpool_close_and_destroy_all(struct cpool *cpool);
102 static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool);
147 int Curl_cpool_init(struct cpool *cpool, in Curl_cpool_init() argument
154 Curl_hash_init(&cpool->dest2bundle, size, Curl_hash_str, in Curl_cpool_init()
156 Curl_llist_init(&cpool->shutdowns, NULL); in Curl_cpool_init()
163 cpool->idata = curl_easy_init(); in Curl_cpool_init()
164 if(!cpool->idata) in Curl_cpool_init()
166 cpool->idata->state.internal = TRUE; in Curl_cpool_init()
172 cpool->idata->multi = multi; in Curl_cpool_init()
175 cpool->idata->set.verbose = TRUE; in Curl_cpool_init()
178 cpool->disconnect_cb = disconnect_cb; in Curl_cpool_init()
179 cpool->idata->multi = cpool->multi = multi; in Curl_cpool_init()
180 cpool->idata->share = cpool->share = share; in Curl_cpool_init()
185 void Curl_cpool_destroy(struct cpool *cpool) in Curl_cpool_destroy() argument
187 if(cpool) { in Curl_cpool_destroy()
188 if(cpool->idata) { in Curl_cpool_destroy()
189 cpool_close_and_destroy_all(cpool); in Curl_cpool_destroy()
192 cpool->idata->multi = NULL; in Curl_cpool_destroy()
193 cpool->idata->share = NULL; in Curl_cpool_destroy()
194 Curl_close(&cpool->idata); in Curl_cpool_destroy()
196 Curl_hash_destroy(&cpool->dest2bundle); in Curl_cpool_destroy()
197 cpool->multi = NULL; in Curl_cpool_destroy()
201 static struct cpool *cpool_get_instance(struct Curl_easy *data) in cpool_get_instance()
205 return &data->share->cpool; in cpool_get_instance()
207 return &data->multi_easy->cpool; in cpool_get_instance()
209 return &data->multi->cpool; in cpool_get_instance()
216 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_xfer_init() local
218 DEBUGASSERT(cpool); in Curl_cpool_xfer_init()
219 if(cpool) { in Curl_cpool_xfer_init()
220 CPOOL_LOCK(cpool); in Curl_cpool_xfer_init()
222 data->id = cpool->next_easy_id++; in Curl_cpool_xfer_init()
223 if(cpool->next_easy_id <= 0) in Curl_cpool_xfer_init()
224 cpool->next_easy_id = 0; in Curl_cpool_xfer_init()
231 cpool->idata->set.timeout = data->set.timeout; in Curl_cpool_xfer_init()
232 cpool->idata->set.server_response_timeout = in Curl_cpool_xfer_init()
234 cpool->idata->set.no_signal = data->set.no_signal; in Curl_cpool_xfer_init()
236 CPOOL_UNLOCK(cpool); in Curl_cpool_xfer_init()
245 static struct cpool_bundle *cpool_find_bundle(struct cpool *cpool, in cpool_find_bundle() argument
248 return Curl_hash_pick(&cpool->dest2bundle, in cpool_find_bundle()
253 cpool_add_bundle(struct cpool *cpool, struct connectdata *conn) in cpool_add_bundle() argument
261 if(!Curl_hash_add(&cpool->dest2bundle, in cpool_add_bundle()
269 static void cpool_remove_bundle(struct cpool *cpool, in cpool_remove_bundle() argument
275 if(!cpool) in cpool_remove_bundle()
278 Curl_hash_start_iterate(&cpool->dest2bundle, &iter); in cpool_remove_bundle()
285 Curl_hash_delete(&cpool->dest2bundle, he->key, he->key_len); in cpool_remove_bundle()
299 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_check_limits() local
305 if(!cpool) in Curl_cpool_check_limits()
316 CPOOL_LOCK(cpool); in Curl_cpool_check_limits()
318 bundle = cpool_find_bundle(cpool, conn); in Curl_cpool_check_limits()
340 while(cpool->num_conn >= total_limit) { in Curl_cpool_check_limits()
341 struct connectdata *oldest_idle = cpool_get_oldest_idle(cpool); in Curl_cpool_check_limits()
348 oldest_idle->connection_id, cpool->num_conn, total_limit)); in Curl_cpool_check_limits()
351 if(cpool->num_conn >= total_limit) { in Curl_cpool_check_limits()
358 CPOOL_UNLOCK(cpool); in Curl_cpool_check_limits()
367 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_add_conn() local
370 DEBUGASSERT(cpool); in Curl_cpool_add_conn()
371 if(!cpool) in Curl_cpool_add_conn()
374 CPOOL_LOCK(cpool); in Curl_cpool_add_conn()
375 bundle = cpool_find_bundle(cpool, conn); in Curl_cpool_add_conn()
377 bundle = cpool_add_bundle(cpool, conn); in Curl_cpool_add_conn()
385 conn->connection_id = cpool->next_connection_id++; in Curl_cpool_add_conn()
386 cpool->num_conn++; in Curl_cpool_add_conn()
389 conn->connection_id, cpool->num_conn)); in Curl_cpool_add_conn()
391 CPOOL_UNLOCK(cpool); in Curl_cpool_add_conn()
396 static void cpool_remove_conn(struct cpool *cpool, in cpool_remove_conn() argument
400 DEBUGASSERT(cpool); in cpool_remove_conn()
403 struct cpool_bundle *bundle = cpool_find_bundle(cpool, conn); in cpool_remove_conn()
407 cpool_remove_bundle(cpool, bundle); in cpool_remove_conn()
409 cpool->num_conn--; in cpool_remove_conn()
413 DEBUGASSERT(list == &cpool->shutdowns); in cpool_remove_conn()
431 struct cpool *cpool, in cpool_foreach() argument
439 if(!cpool) in cpool_foreach()
442 Curl_hash_start_iterate(&cpool->dest2bundle, &iter); in cpool_foreach()
466 static struct connectdata *cpool_get_live_conn(struct cpool *cpool) in cpool_get_live_conn() argument
473 Curl_hash_start_iterate(&cpool->dest2bundle, &iter); in cpool_get_live_conn()
496 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_conn_now_idle() local
500 if(cpool && maxconnects) { in Curl_cpool_conn_now_idle()
502 bool do_lock = !CPOOL_IS_LOCKED(cpool); in Curl_cpool_conn_now_idle()
504 CPOOL_LOCK(cpool); in Curl_cpool_conn_now_idle()
505 if(cpool->num_conn > maxconnects) { in Curl_cpool_conn_now_idle()
508 oldest_idle = cpool_get_oldest_idle(cpool); in Curl_cpool_conn_now_idle()
511 Curl_cpool_disconnect(cpool->idata, oldest_idle, FALSE); in Curl_cpool_conn_now_idle()
515 CPOOL_UNLOCK(cpool); in Curl_cpool_conn_now_idle()
554 static struct connectdata *cpool_get_oldest_idle(struct cpool *cpool) in cpool_get_oldest_idle() argument
566 Curl_hash_start_iterate(&cpool->dest2bundle, &iter); in cpool_get_oldest_idle()
595 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_find() local
599 DEBUGASSERT(cpool); in Curl_cpool_find()
601 if(!cpool) in Curl_cpool_find()
604 CPOOL_LOCK(cpool); in Curl_cpool_find()
605 bundle = Curl_hash_pick(&cpool->dest2bundle, (void *)destination, dest_len); in Curl_cpool_find()
623 CPOOL_UNLOCK(cpool); in Curl_cpool_find()
627 static void cpool_shutdown_discard_all(struct cpool *cpool) in cpool_shutdown_discard_all() argument
629 struct Curl_llist_node *e = Curl_llist_head(&cpool->shutdowns); in cpool_shutdown_discard_all()
635 DEBUGF(infof(cpool->idata, "cpool_shutdown_discard_all")); in cpool_shutdown_discard_all()
639 DEBUGF(infof(cpool->idata, "discard connection #%" FMT_OFF_T, in cpool_shutdown_discard_all()
641 cpool_close_and_destroy(cpool, conn, NULL, FALSE); in cpool_shutdown_discard_all()
642 e = Curl_llist_head(&cpool->shutdowns); in cpool_shutdown_discard_all()
646 static void cpool_close_and_destroy_all(struct cpool *cpool) in cpool_close_and_destroy_all() argument
652 DEBUGASSERT(cpool); in cpool_close_and_destroy_all()
655 CPOOL_LOCK(cpool); in cpool_close_and_destroy_all()
656 conn = cpool_get_live_conn(cpool); in cpool_close_and_destroy_all()
658 cpool_remove_conn(cpool, conn); in cpool_close_and_destroy_all()
659 sigpipe_apply(cpool->idata, &pipe_st); in cpool_close_and_destroy_all()
661 cpool_discard_conn(cpool, cpool->idata, conn, FALSE); in cpool_close_and_destroy_all()
663 conn = cpool_get_live_conn(cpool); in cpool_close_and_destroy_all()
665 CPOOL_UNLOCK(cpool); in cpool_close_and_destroy_all()
678 sigpipe_apply(cpool->idata, &pipe_st); in cpool_close_and_destroy_all()
679 cpool_shutdown_all(cpool, cpool->idata, timeout_ms); in cpool_close_and_destroy_all()
682 cpool_shutdown_discard_all(cpool); in cpool_close_and_destroy_all()
684 Curl_hostcache_clean(cpool->idata, cpool->idata->dns.hostcache); in cpool_close_and_destroy_all()
689 static void cpool_shutdown_destroy_oldest(struct cpool *cpool) in cpool_shutdown_destroy_oldest() argument
694 e = Curl_llist_head(&cpool->shutdowns); in cpool_shutdown_destroy_oldest()
700 sigpipe_apply(cpool->idata, &pipe_st); in cpool_shutdown_destroy_oldest()
701 cpool_close_and_destroy(cpool, conn, NULL, FALSE); in cpool_shutdown_destroy_oldest()
706 static void cpool_discard_conn(struct cpool *cpool, in cpool_discard_conn() argument
714 DEBUGASSERT(cpool); in cpool_discard_conn()
751 cpool_close_and_destroy(cpool, conn, data, FALSE); in cpool_discard_conn()
759 (long)Curl_llist_count(&cpool->shutdowns))) { in cpool_discard_conn()
763 cpool_shutdown_destroy_oldest(cpool); in cpool_discard_conn()
767 DEBUGASSERT(cpool == &data->multi->cpool); in cpool_discard_conn()
771 if(cpool_update_shutdown_ev(data->multi, cpool->idata, conn)) { in cpool_discard_conn()
775 cpool_close_and_destroy(cpool, conn, data, FALSE); in cpool_discard_conn()
780 Curl_llist_append(&cpool->shutdowns, conn, &conn->cpool_node); in cpool_discard_conn()
783 Curl_llist_count(&cpool->shutdowns))); in cpool_discard_conn()
790 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_disconnect() local
793 DEBUGASSERT(cpool); in Curl_cpool_disconnect()
795 if(!cpool) in Curl_cpool_disconnect()
808 do_lock = !CPOOL_IS_LOCKED(cpool); in Curl_cpool_disconnect()
810 CPOOL_LOCK(cpool); in Curl_cpool_disconnect()
813 cpool_remove_conn(cpool, conn); in Curl_cpool_disconnect()
818 aborted = cpool->disconnect_cb(data, conn, aborted); in Curl_cpool_disconnect()
824 cpool_discard_conn(&data->multi->cpool, data, conn, aborted); in Curl_cpool_disconnect()
833 CPOOL_UNLOCK(cpool); in Curl_cpool_disconnect()
902 static CURLcode cpool_add_pollfds(struct cpool *cpool, in cpool_add_pollfds() argument
907 if(Curl_llist_head(&cpool->shutdowns)) { in cpool_add_pollfds()
912 for(e = Curl_llist_head(&cpool->shutdowns); e; in cpool_add_pollfds()
916 Curl_attach_connection(cpool->idata, conn); in cpool_add_pollfds()
917 Curl_conn_adjust_pollset(cpool->idata, &ps); in cpool_add_pollfds()
918 Curl_detach_connection(cpool->idata); in cpool_add_pollfds()
931 CURLcode Curl_cpool_add_pollfds(struct cpool *cpool, in Curl_cpool_add_pollfds() argument
935 CPOOL_LOCK(cpool); in Curl_cpool_add_pollfds()
936 result = cpool_add_pollfds(cpool, cpfds); in Curl_cpool_add_pollfds()
937 CPOOL_UNLOCK(cpool); in Curl_cpool_add_pollfds()
941 CURLcode Curl_cpool_add_waitfds(struct cpool *cpool, in Curl_cpool_add_waitfds() argument
946 CPOOL_LOCK(cpool); in Curl_cpool_add_waitfds()
947 if(Curl_llist_head(&cpool->shutdowns)) { in Curl_cpool_add_waitfds()
952 for(e = Curl_llist_head(&cpool->shutdowns); e; in Curl_cpool_add_waitfds()
956 Curl_attach_connection(cpool->idata, conn); in Curl_cpool_add_waitfds()
957 Curl_conn_adjust_pollset(cpool->idata, &ps); in Curl_cpool_add_waitfds()
958 Curl_detach_connection(cpool->idata); in Curl_cpool_add_waitfds()
966 CPOOL_UNLOCK(cpool); in Curl_cpool_add_waitfds()
970 static void cpool_perform(struct cpool *cpool) in cpool_perform() argument
972 struct Curl_easy *data = cpool->idata; in cpool_perform()
973 struct Curl_llist_node *e = Curl_llist_head(&cpool->shutdowns); in cpool_perform()
986 Curl_llist_count(&cpool->shutdowns))); in cpool_perform()
997 cpool_close_and_destroy(cpool, conn, NULL, FALSE); in cpool_perform()
1018 CPOOL_LOCK(&multi->cpool); in Curl_cpool_multi_perform()
1019 cpool_perform(&multi->cpool); in Curl_cpool_multi_perform()
1020 CPOOL_UNLOCK(&multi->cpool); in Curl_cpool_multi_perform()
1028 static void cpool_close_and_destroy(struct cpool *cpool, in cpool_close_and_destroy() argument
1040 DEBUGASSERT(data || cpool); in cpool_close_and_destroy()
1042 data = cpool->idata; in cpool_close_and_destroy()
1056 if(cpool) in cpool_close_and_destroy()
1096 struct cpool *cpool = &multi->cpool; in Curl_cpool_multi_socket() local
1097 struct Curl_easy *data = cpool->idata; in Curl_cpool_multi_socket()
1104 CPOOL_LOCK(cpool); in Curl_cpool_multi_socket()
1105 e = Curl_llist_head(&cpool->shutdowns); in Curl_cpool_multi_socket()
1116 cpool_close_and_destroy(cpool, conn, NULL, FALSE); in Curl_cpool_multi_socket()
1122 CPOOL_UNLOCK(cpool); in Curl_cpool_multi_socket()
1127 static CURLcode cpool_shutdown_wait(struct cpool *cpool, int timeout_ms) in cpool_shutdown_wait() argument
1135 result = cpool_add_pollfds(cpool, &cpfds); in cpool_shutdown_wait()
1146 static void cpool_shutdown_all(struct cpool *cpool, in cpool_shutdown_all() argument
1159 for(conn = cpool_get_live_conn(cpool); conn; in cpool_shutdown_all()
1160 conn = cpool_get_live_conn(cpool)) { in cpool_shutdown_all()
1164 cpool_remove_conn(cpool, conn); in cpool_shutdown_all()
1165 cpool_discard_conn(cpool, data, conn, FALSE); in cpool_shutdown_all()
1168 while(Curl_llist_head(&cpool->shutdowns)) { in cpool_shutdown_all()
1172 cpool_perform(cpool); in cpool_shutdown_all()
1174 if(!Curl_llist_head(&cpool->shutdowns)) { in cpool_shutdown_all()
1188 if(cpool_shutdown_wait(cpool, remain_ms)) { in cpool_shutdown_all()
1195 cpool_shutdown_discard_all(cpool); in cpool_shutdown_all()
1223 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_prune_dead() local
1227 if(!cpool) in Curl_cpool_prune_dead()
1231 CPOOL_LOCK(cpool); in Curl_cpool_prune_dead()
1232 elapsed = Curl_timediff(rctx.now, cpool->last_cleanup); in Curl_cpool_prune_dead()
1235 while(cpool_foreach(data, cpool, &rctx, cpool_reap_dead_cb)) in Curl_cpool_prune_dead()
1237 cpool->last_cleanup = rctx.now; in Curl_cpool_prune_dead()
1239 CPOOL_UNLOCK(cpool); in Curl_cpool_prune_dead()
1254 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_upkeep() local
1257 if(!cpool) in Curl_cpool_upkeep()
1260 CPOOL_LOCK(cpool); in Curl_cpool_upkeep()
1261 cpool_foreach(data, cpool, &now, conn_upkeep); in Curl_cpool_upkeep()
1262 CPOOL_UNLOCK(cpool); in Curl_cpool_upkeep()
1286 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_get_conn() local
1289 if(!cpool) in Curl_cpool_get_conn()
1293 CPOOL_LOCK(cpool); in Curl_cpool_get_conn()
1294 cpool_foreach(cpool->idata, cpool, &fctx, cpool_find_conn); in Curl_cpool_get_conn()
1295 CPOOL_UNLOCK(cpool); in Curl_cpool_get_conn()
1320 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_do_by_id() local
1323 if(!cpool) in Curl_cpool_do_by_id()
1328 CPOOL_LOCK(cpool); in Curl_cpool_do_by_id()
1329 cpool_foreach(data, cpool, &dctx, cpool_do_conn); in Curl_cpool_do_by_id()
1330 CPOOL_UNLOCK(cpool); in Curl_cpool_do_by_id()
1337 struct cpool *cpool = cpool_get_instance(data); in Curl_cpool_do_locked() local
1338 if(cpool) { in Curl_cpool_do_locked()
1339 CPOOL_LOCK(cpool); in Curl_cpool_do_locked()
1341 CPOOL_UNLOCK(cpool); in Curl_cpool_do_locked()
1349 void Curl_cpool_print(struct cpool *cpool)
1355 if(!cpool)
1360 Curl_hash_start_iterate(cpool->dest2bundle, &iter);