]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - conn.go
WARC
[tofuproxy.git] / conn.go
diff --git a/conn.go b/conn.go
index 1542abda9935a85b1afdefb4b49b05861b78cd9b..4b88f13740c915c7d4a906462934377dbf5925f1 100644 (file)
--- a/conn.go
+++ b/conn.go
@@ -1,4 +1,5 @@
 /*
+tofuproxy -- flexible HTTP/WARC proxy with TLS certificates management
 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
@@ -14,7 +15,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-package main
+package tofuproxy
 
 import (
        "net"
@@ -25,6 +26,7 @@ import (
 type SingleConn struct {
        conn net.Conn
        ln   *SingleListener
+       once sync.Once
 }
 
 func (conn *SingleConn) Read(b []byte) (int, error) { return conn.conn.Read(b) }
@@ -32,7 +34,7 @@ func (conn *SingleConn) Read(b []byte) (int, error) { return conn.conn.Read(b) }
 func (conn *SingleConn) Write(b []byte) (int, error) { return conn.conn.Write(b) }
 
 func (conn *SingleConn) Close() error {
-       conn.ln.Unlock()
+       conn.once.Do(conn.ln.Unlock)
        return conn.conn.Close()
 }
 
@@ -62,7 +64,7 @@ func (ln *SingleListener) Accept() (net.Conn, error) {
                return nil, AlreadyAccepted{}
        }
        ln.accepted = true
-       return &SingleConn{ln.conn, ln}, nil
+       return &SingleConn{conn: ln.conn, ln: ln}, nil
 }
 
 func (ln *SingleListener) Close() error { return nil }