-
Notifications
You must be signed in to change notification settings - Fork 5
/
conn_tcp.go
43 lines (37 loc) · 846 Bytes
/
conn_tcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package net
import (
"net"
"time"
"github.com/pbergman/logger"
)
type TcpConnPool struct {
address *net.TCPAddr
connPool
}
func (c *TcpConnPool) bind(conn *net.Conn) (err error) {
*conn, err = net.DialTCP("tcp", nil, c.address)
return
}
func (c *TcpConnPool) Start(workers int) {
c.lock.Lock()
defer c.lock.Unlock()
c.start(workers, c.bind)
}
func NewTcpConnPool(tries int, host *GraylogHost, logger *logger.Logger) (ConnPoolInterface, error) {
if address, err := net.ResolveTCPAddr(host.GetNetwork(), host.GetHost()); err != nil {
return nil, err
} else {
return &TcpConnPool{
address: address,
connPool: connPool{
KeepAlive: 3 * time.Minute,
Timeout: 1 * time.Minute,
logger: logger,
connQueue: connQueue{
tries: tries,
queue: make(chan *ConnQueueItem, 10),
},
},
}, nil
}
}