From 30a127ed43213ff65cded9e3cbaf6c365a71d4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20BRY?= Date: Mon, 25 Mar 2024 17:21:31 +0100 Subject: [PATCH] TCP Proxy: use struct{} instead of bool --- backends_processor/mysql.go | 6 +++--- proxy/tcp.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backends_processor/mysql.go b/backends_processor/mysql.go index 68037fa..c8586dd 100644 --- a/backends_processor/mysql.go +++ b/backends_processor/mysql.go @@ -279,7 +279,7 @@ type MySQLCheck struct { backoff_factor float64 status_chan chan *backend.Backend ticker *misc.ExponentialBackoffTicker - stop_chan chan bool + stop_chan chan struct{} running bool db *sql.DB check_replica bool @@ -294,7 +294,7 @@ func NewMySQLCheck(backend *backend.Backend, dsn string, default_period time.Dur max_period: max_period, backoff_factor: backoff_factor, status_chan: status_chan, - stop_chan: make(chan bool), + stop_chan: make(chan struct{}), running: false, check_replica: check_replica, } @@ -514,5 +514,5 @@ func (c *MySQLCheck) StopPolling() { c.db.Close() c.ticker.Stop() - c.stop_chan <- true + close(c.stop_chan) } diff --git a/proxy/tcp.go b/proxy/tcp.go index d224253..bdf688b 100644 --- a/proxy/tcp.go +++ b/proxy/tcp.go @@ -174,7 +174,7 @@ func (p *ProxyTCP) listen(address string, wg *sync.WaitGroup, ctx context.Contex }() } -func (p *ProxyTCP) pipe(input net.Conn, output net.Conn, done chan bool, input_timeout time.Duration, output_timeout time.Duration, counter *atomic.Uint64) { +func (p *ProxyTCP) pipe(input net.Conn, output net.Conn, done chan struct{}, input_timeout time.Duration, output_timeout time.Duration, counter *atomic.Uint64) { // Error handler defer func() { if r := recover(); r != nil { @@ -291,8 +291,8 @@ func (p *ProxyTCP) handle_connection(conn_front net.Conn) { } // Pipe the connections both ways - done_front_back := make(chan bool) - done_back_front := make(chan bool) + done_front_back := make(chan struct{}) + done_back_front := make(chan struct{}) var bytes_in, bytes_out atomic.Uint64 go p.pipe(conn_front, conn_back, done_front_back, p.client_timeout, p.server_timeout, &bytes_in)