]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - conn.go
Download link for 0.6.0 release
[tofuproxy.git] / conn.go
diff --git a/conn.go b/conn.go
index 1542abda9935a85b1afdefb4b49b05861b78cd9b..9e9ce1c5c70a39a2ff2f4cef2508020e7e4538e7 100644 (file)
--- a/conn.go
+++ b/conn.go
@@ -1,20 +1,20 @@
-/*
-Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-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
+// tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+//              manager, WARC/geminispace browser
+// Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// 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 tofuproxy
 
 import (
        "net"
@@ -25,6 +25,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 +33,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 +63,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 }