X-Git-Url: http://www.git.stargrave.org/?p=tofuproxy.git;a=blobdiff_plain;f=conn.go;h=e18282e8833ff19c0534b5fb7d82259fd61ab40a;hp=1542abda9935a85b1afdefb4b49b05861b78cd9b;hb=HEAD;hpb=b103a48ba4f6dd5ecad2ece2529c0aadf9680658 diff --git a/conn.go b/conn.go index 1542abd..9e9ce1c 100644 --- a/conn.go +++ b/conn.go @@ -1,20 +1,20 @@ -/* -Copyright (C) 2021 Sergey Matveev - -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 . -*/ - -package main +// tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU +// manager, WARC/geminispace browser +// Copyright (C) 2021-2024 Sergey Matveev +// +// 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 . + +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 }