Lines Matching refs:peer

18 http_client_peer_connect_backoff(struct http_client_peer *peer);
28 http_client_peer_connection_failed_any(struct http_client_peer *peer,
36 (const struct http_client_peer_addr *peer)
38 unsigned int hash = (unsigned int)peer->type;
40 switch (peer->type) {
43 if (peer->a.tcp.https_name != NULL)
44 hash += str_hash(peer->a.tcp.https_name);
48 if (peer->a.tcp.ip.family != 0)
49 hash += net_ip_hash(&peer->a.tcp.ip);
50 hash += peer->a.tcp.port;
53 hash += str_hash(peer->a.un.path);
73 /* Queues are created with peer addresses that have an uninitialized
106 ppool->peer = pshared;
109 "peer %s: ", http_client_peer_shared_label(pshared)));
157 struct http_client_peer_shared *pshared = ppool->peer;
222 http_client_peer_shared_connection_success(ppool->peer);
240 http_client_peer_shared_connection_failure(ppool->peer,
279 "peer %s (shared): ", http_client_peer_shared_label(pshared)));
379 struct http_client_peer *peer;
387 peer = pshared->peers_list;
388 while (peer != NULL) {
389 http_client_peer_connect_backoff(peer);
390 peer = peer->shared_next;
471 struct http_client_peer *peer;
475 peer = pshared->peers_list;
476 while (peer != NULL) {
477 struct http_client_peer *peer_next = peer->shared_next;
478 http_client_peer_connection_failed_any(peer, reason);
479 peer = peer_next;
512 struct http_client_peer *peer;
515 peer = pshared->peers_list;
516 while (peer != NULL) {
517 max_conns += peer->client->set.max_parallel_connections;
518 peer = peer->shared_next;
535 struct http_client_peer *peer;
537 peer = i_new(struct http_client_peer, 1);
538 peer->refcount = 1;
539 peer->client = client;
540 peer->shared = pshared;
542 peer->event = event_create(client->event);
543 event_set_append_log_prefix(peer->event, t_strdup_printf(
544 "peer %s: ", http_client_peer_shared_label(pshared)));
546 i_array_init(&peer->queues, 16);
547 i_array_init(&peer->conns, 16);
550 (&client->peers_list, peer, client_prev, client_next);
552 (&pshared->peers_list, peer, shared_prev, shared_next);
556 peer->ppool = http_client_peer_pool_get(pshared, client);
572 e_debug(peer->event, "Peer created");
573 return peer;
576 void http_client_peer_ref(struct http_client_peer *peer)
578 peer->refcount++;
582 http_client_peer_disconnect(struct http_client_peer *peer)
585 struct http_client *client = peer->client;
586 struct http_client_peer_shared *pshared = peer->shared;
590 if (peer->disconnected)
592 peer->disconnected = TRUE;
594 e_debug(peer->event, "Peer disconnect");
597 t_array_init(&conns, array_count(&peer->conns));
598 array_copy(&conns.arr, 0, &peer->conns.arr,
599 0, array_count(&peer->conns));
602 i_assert(array_count(&peer->conns) == 0);
604 timeout_remove(&peer->to_req_handling);
608 (&client->peers_list, peer, client_prev, client_next);
609 /* unlist in peer */
611 (&pshared->peers_list, peer, shared_prev, shared_next);
615 array_foreach(&peer->queues, queue)
616 http_client_queue_peer_disconnected(*queue, peer);
617 array_clear(&peer->queues);
622 struct http_client_peer *peer = *_peer;
623 struct http_client_peer_pool *ppool = peer->ppool;
624 struct http_client_peer_shared *pshared = peer->shared;
628 i_assert(peer->refcount > 0);
629 if (--peer->refcount > 0)
632 e_debug(peer->event, "Peer destroy");
634 http_client_peer_disconnect(peer);
636 i_assert(array_count(&peer->queues) == 0);
638 event_unref(&peer->event);
639 array_free(&peer->conns);
640 array_free(&peer->queues);
641 i_free(peer);
644 peer = pshared->peers_list;
645 while (peer != NULL) {
646 struct http_client *client = peer->client;
658 peer = peer->shared_next;
668 struct http_client_peer *peer = *_peer;
670 e_debug(peer->event, "Peer close");
672 http_client_peer_disconnect(peer);
680 struct http_client_peer *peer = *_peer;
681 struct http_client_peer_shared *pshared = peer->shared;
683 http_client_peer_active_connections(peer);
686 e_debug(peer->event,
687 "Not dropping peer (%d connections active)",
696 e_debug(peer->event,
697 "Dropping peer (waiting for backof timeout)");
700 http_client_peer_trigger_request_handler(peer);
702 e_debug(peer->event, "Dropping peer now");
703 /* drop peer immediately */
712 struct http_client_peer *peer;
717 peer = pshared->peers_list;
718 while (peer != NULL) {
719 if (peer->client == client)
721 peer = peer->shared_next;
724 if (peer == NULL)
725 peer = http_client_peer_create(client, pshared);
728 return peer;
732 http_client_peer_do_connect(struct http_client_peer *peer,
735 struct http_client_peer_pool *ppool = peer->ppool;
745 http_client_connection_claim_idle(idle_conns[i], peer);
748 e_debug(peer->event,
750 array_count(&peer->conns));
754 e_debug(peer->event,
756 (void)http_client_connection_create(peer);
760 http_client_peer_connection_success(peer);
764 http_client_peer_connect_backoff(struct http_client_peer *peer)
766 if (peer->connect_backoff &&
767 array_count(&peer->queues) == 0) {
768 http_client_peer_close(&peer);
772 http_client_peer_do_connect(peer, 1);
773 peer->connect_backoff = FALSE;
777 http_client_peer_connect(struct http_client_peer *peer, unsigned int count)
779 peer->connecting = TRUE;
781 if (http_client_peer_shared_start_backoff_timer(peer->shared)) {
782 peer->connect_backoff = TRUE;
786 http_client_peer_do_connect(peer, count);
789 bool http_client_peer_is_connected(struct http_client_peer *peer)
793 if (array_count(&peer->ppool->idle_conns) > 0)
796 array_foreach(&peer->conns, conn_idx) {
805 http_client_peer_cancel(struct http_client_peer *peer)
810 e_debug(peer->event, "Peer cancel");
812 peer->connecting = FALSE;
815 t_array_init(&conns, array_count(&peer->conns));
816 array_copy(&conns.arr, 0, &peer->conns.arr, 0, array_count(&peer->conns));
824 http_client_peer_requests_pending(struct http_client_peer *peer,
830 array_foreach(&peer->queues, queue) {
840 static void http_client_peer_check_idle(struct http_client_peer *peer)
845 if (array_count(&peer->conns) == 0 &&
846 http_client_peer_requests_pending(peer, &num_urgent) == 0) {
848 http_client_peer_drop(&peer);
853 array_foreach(&peer->conns, conn_idx) {
859 http_client_peer_handle_requests_real(struct http_client_peer *peer)
868 struct http_client_peer_shared *pshared = peer->shared;
879 if (array_count(&peer->queues) == 0) {
880 if (array_count(&peer->conns) == 0 && pshared->to_backoff == NULL) {
881 /* peer is completely unused and inactive; drop it immediately */
882 http_client_peer_drop(&peer);
885 e_debug(peer->event,
887 "(%u connections exist)", array_count(&peer->conns));
888 http_client_peer_cancel(peer);
893 num_pending = http_client_peer_requests_pending(peer, &num_urgent);
895 e_debug(peer->event,
896 "No requests to service for this peer "
897 "(%u connections exist)", array_count(&peer->conns));
898 http_client_peer_check_idle(peer);
902 http_client_peer_ref(peer);
903 peer->handling_requests = TRUE;
904 t_array_init(&conns_avail, array_count(&peer->conns));
912 array_foreach(&peer->conns, conn_idx) {
954 working_conn_count = array_count(&peer->conns) - closing;
959 e_debug(peer->event,
984 num_pending = http_client_peer_requests_pending(peer, &num_urgent);
986 e_debug(peer->event,
987 "No more requests to service for this peer "
988 "(%u connections exist)", array_count(&peer->conns));
989 http_client_peer_check_idle(peer);
994 tmp_peer = peer;
997 peer->handling_requests = FALSE;
1012 peer->client->set.max_parallel_connections) {
1028 peer->client->set.max_parallel_connections - working_conn_count) {
1031 peer->client->set.max_parallel_connections - working_conn_count;
1040 e_debug(peer->event,
1045 http_client_peer_connect(peer, new_connections);
1051 peer->client->set.max_parallel_connections) {
1055 e_debug(peer->event,
1056 "Will not pipeline until peer has shown support");
1089 e_debug(peer->event,
1096 e_debug(peer->event, "No request handled; waiting for new connections");
1100 static void http_client_peer_handle_requests(struct http_client_peer *peer)
1102 timeout_remove(&peer->to_req_handling);
1105 http_client_peer_handle_requests_real(peer);
1109 void http_client_peer_trigger_request_handler(struct http_client_peer *peer)
1112 if (peer->to_req_handling == NULL) {
1113 peer->to_req_handling = timeout_add_short_to(
1114 peer->client->ioloop, 0,
1115 http_client_peer_handle_requests, peer);
1119 bool http_client_peer_have_queue(struct http_client_peer *peer,
1124 array_foreach(&peer->queues, queue_idx) {
1131 void http_client_peer_link_queue(struct http_client_peer *peer,
1134 if (!http_client_peer_have_queue(peer, queue)) {
1135 array_append(&peer->queues, &queue, 1);
1137 e_debug(peer->event, "Linked queue %s (%d queues linked)",
1138 queue->name, array_count(&peer->queues));
1142 void http_client_peer_unlink_queue(struct http_client_peer *peer,
1147 array_foreach(&peer->queues, queue_idx) {
1149 array_delete(&peer->queues,
1150 array_foreach_idx(&peer->queues, queue_idx), 1);
1152 e_debug(peer->event,
1154 queue->name, array_count(&peer->queues));
1156 if (array_count(&peer->queues) == 0)
1157 http_client_peer_check_idle(peer);
1164 http_client_peer_claim_request(struct http_client_peer *peer, bool no_urgent)
1169 array_foreach(&peer->queues, queue_idx) {
1171 (*queue_idx, &peer->shared->addr, no_urgent)) != NULL) {
1172 req->peer = peer;
1180 void http_client_peer_connection_success(struct http_client_peer *peer)
1182 struct http_client_peer_pool *ppool = peer->ppool;
1185 peer->connecting = FALSE;
1189 e_debug(peer->event, "Successfully connected (connections=%u)",
1190 array_count(&peer->conns));
1192 array_foreach(&peer->queues, queue)
1193 http_client_queue_connection_success(*queue, peer);
1195 http_client_peer_trigger_request_handler(peer);
1199 http_client_peer_connection_failed_any(struct http_client_peer *peer,
1204 if (!peer->connecting)
1206 peer->connecting = FALSE;
1208 e_debug(peer->event, "Connection failed: %s", reason);
1213 array_foreach(&peer->queues, queue)
1214 http_client_queue_connection_failure(*queue, peer, reason);
1217 void http_client_peer_connection_failure(struct http_client_peer *peer,
1220 struct http_client_peer_pool *ppool = peer->ppool;
1225 void http_client_peer_connection_lost(struct http_client_peer *peer,
1234 if (peer->disconnected)
1237 http_client_peer_shared_connection_lost(peer->shared, premature);
1239 num_pending = http_client_peer_requests_pending(peer, &num_urgent);
1241 e_debug(peer->event,
1245 array_count(&peer->queues), array_count(&peer->conns),
1248 if (peer->handling_requests) {
1250 e_debug(peer->event,
1255 /* if there are pending requests for this peer, create a new connection
1256 for them. if not, this peer will wind itself down. */
1257 http_client_peer_trigger_request_handler(peer);
1261 http_client_peer_active_connections(struct http_client_peer *peer)
1267 array_foreach(&peer->conns, conn_idx) {
1276 http_client_peer_pending_connections(struct http_client_peer *peer)
1282 array_foreach(&peer->conns, conn_idx) {
1290 void http_client_peer_switch_ioloop(struct http_client_peer *peer)
1292 if (peer->to_req_handling != NULL) {
1293 peer->to_req_handling =
1294 io_loop_move_timeout(&peer->to_req_handling);