X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=conn.go;h=f5f4ef842f2a901d1f429d40db031cd54e5fae9e;hb=decb4bfb406665dde1233e9936fee3edfe3e81da;hp=1542abda9935a85b1afdefb4b49b05861b78cd9b;hpb=b103a48ba4f6dd5ecad2ece2529c0aadf9680658;p=tofuproxy.git diff --git a/conn.go b/conn.go index 1542abd..f5f4ef8 100644 --- a/conn.go +++ b/conn.go @@ -1,5 +1,7 @@ /* -Copyright (C) 2021 Sergey Matveev +tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU + manager, WARC/geminispace browser +Copyright (C) 2021-2022 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 @@ -14,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -package main +package tofuproxy import ( "net" @@ -25,6 +27,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 +35,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 +65,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 }