Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * SPDX-License-Identifier: EUPL-1.2 |
| 5 | * |
| 6 | * This file is part of icap-flow. |
| 7 | * |
| 8 | * Licensed under the EUPL, Version 1.2 only (the "Licence"); |
| 9 | * you may not use this work except in compliance with the Licence. |
| 10 | * You may obtain a copy of the Licence at: |
| 11 | * |
| 12 | * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the Licence is distributed on an "AS IS" basis, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | */ |
| 18 | |
| 19 | declare(strict_types=1); |
| 20 | |
| 21 | namespace Ndrstmr\Icap\Transport; |
| 22 | |
| 23 | use Amp\Cancellation; |
| 24 | use Amp\Socket\Socket; |
| 25 | use Ndrstmr\Icap\Config; |
| 26 | |
| 27 | /** |
| 28 | * Process-local cache of TCP/TLS connections to ICAP servers. |
| 29 | * |
| 30 | * The transport calls {@see acquire()} before sending the request |
| 31 | * and {@see release()} after the response has been framed. The pool |
| 32 | * decides whether to hand out an existing idle socket or open a new |
| 33 | * one, and whether to keep a returned socket idle or close it. |
| 34 | * |
| 35 | * The default implementation is {@see AmpConnectionPool}; the no-op |
| 36 | * variant {@see NullConnectionPool} opens a fresh connection on every |
| 37 | * acquire and closes it on release. |
| 38 | * |
| 39 | * Implementations MUST be safe to use across concurrent |
| 40 | * acquire/release cycles within a single fiber-driven event loop; |
| 41 | * cross-process safety is the implementer's choice. |
| 42 | */ |
| 43 | interface ConnectionPoolInterface |
| 44 | { |
| 45 | /** |
| 46 | * Hand back a socket connected to the host described by $config. |
| 47 | * Returns either a previously released, still-alive socket or a |
| 48 | * freshly opened one. May suspend the current fiber while |
| 49 | * connecting; honours $cancellation if supplied. |
| 50 | */ |
| 51 | public function acquire(Config $config, ?Cancellation $cancellation = null): Socket; |
| 52 | |
| 53 | /** |
| 54 | * Hand a socket back to the pool. The caller MUST NOT continue |
| 55 | * using the socket after this call. Implementations may close |
| 56 | * the socket if it isn't reusable (already closed, pool full, |
| 57 | * server signalled `Connection: close`). |
| 58 | */ |
| 59 | public function release(Config $config, Socket $socket): void; |
| 60 | |
| 61 | /** |
| 62 | * Close every pooled idle socket. Idempotent. Sockets currently |
| 63 | * in use by callers are unaffected — they will be closed when |
| 64 | * released against this pool, since the pool won't accept new |
| 65 | * idle entries after close(). |
| 66 | */ |
| 67 | public function close(): void; |
| 68 | } |