aboutsummaryrefslogtreecommitdiff
path: root/internal/imap/client.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2023-06-04 21:55:50 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2023-06-04 22:06:19 +0200
commitc2697725ead29c3c108a8e5f7a9f6ab7519ed7c3 (patch)
treec4432926812476c384ae06feb949887d5f896ed8 /internal/imap/client.go
parent565b1a1eef18372aa3e75efa47b34aec47a53571 (diff)
downloadfeed2imap-go-c2697725ead29c3c108a8e5f7a9f6ab7519ed7c3.tar.gz
feed2imap-go-c2697725ead29c3c108a8e5f7a9f6ab7519ed7c3.tar.bz2
feed2imap-go-c2697725ead29c3c108a8e5f7a9f6ab7519ed7c3.zip
Add new config option to set max number of IMAP connections.
Default is 5 (as was the hard-coded value before). Closes issue #98.
Diffstat (limited to 'internal/imap/client.go')
-rw-r--r--internal/imap/client.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/internal/imap/client.go b/internal/imap/client.go
index 83903fa..4a0a0d8 100644
--- a/internal/imap/client.go
+++ b/internal/imap/client.go
@@ -13,8 +13,6 @@ import (
"github.com/Necoro/feed2imap-go/pkg/log"
)
-const numberConns = 5
-
type connConf struct {
host string
delimiter string
@@ -23,13 +21,13 @@ type connConf struct {
type Client struct {
connConf
- mailboxes *mailboxes
- commander *commander
- connections [numberConns]*connection
- idxCounter int
- connChannel chan *connection
- connLock sync.Mutex
- disconnected bool
+ mailboxes *mailboxes
+ commander *commander
+ connections []*connection
+ maxConnections int
+ connChannel chan *connection
+ connLock sync.Mutex
+ disconnected bool
}
var dialer imapClient.Dialer
@@ -107,9 +105,7 @@ func (cl *Client) Disconnect() {
func (cl *Client) createConnection(c *imapClient.Client) *connection {
- cl.idxCounter++
-
- if cl.idxCounter >= len(cl.connections) {
+ if len(cl.connections) == cl.maxConnections {
panic("Too many connections")
}
@@ -121,13 +117,15 @@ func (cl *Client) createConnection(c *imapClient.Client) *connection {
c: client,
}
- cl.connections[cl.idxCounter] = conn
+ cl.connections = append(cl.connections, conn)
return conn
}
-func newClient() *Client {
+func newClient(maxConnections int) *Client {
return &Client{
- mailboxes: NewMailboxes(),
- connChannel: make(chan *connection, 0),
+ mailboxes: NewMailboxes(),
+ connChannel: make(chan *connection, 0),
+ connections: make([]*connection, 0, maxConnections),
+ maxConnections: maxConnections,
}
}