From 5ec8a5a5feef5a66cf4617f1e94097952a1e15ae Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 22 Sep 2024 20:48:09 +0200 Subject: [PATCH] Add initial connection pool interface Introduces a new `connpool.go` file implementing a connection pool interface for managing network connections. This interface includes methods to get and close connections, as well as to retrieve the current pool size. The implementation is initially based on a fork of code from the Fatih Arslan GitHub repository. --- connpool.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 connpool.go diff --git a/connpool.go b/connpool.go new file mode 100644 index 0000000..8eabbad --- /dev/null +++ b/connpool.go @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2022-2024 The go-mail Authors +// +// SPDX-License-Identifier: MIT + +package mail + +import "net" + +// Parts of the connection pool code is forked from https://github.com/fatih/pool/ +// Thanks to Fatih Arslan and the project contributors for providing this great +// concurrency template. + +// Pool interface describes a connection pool implementation. A Pool is +// thread-/go-routine safe. +type Pool interface { + // Get returns a new connection from the pool. Closing the connections returns + // it back into the Pool. Closing a connection when the Pool is destroyed or + // full will be counted as an error. + Get() (net.Conn, error) + + // Close closes the pool and all its connections. After Close() the pool is + // no longer usable. + Close() + + // Len returns the current number of connections of the pool. + Len() int +}