X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=conn.go;h=4b88f13740c915c7d4a906462934377dbf5925f1;hb=0c0a261a6ef4fddfc34a9150005f7964cc69c420;hp=1542abda9935a85b1afdefb4b49b05861b78cd9b;hpb=b103a48ba4f6dd5ecad2ece2529c0aadf9680658;p=tofuproxy.git diff --git a/conn.go b/conn.go index 1542abd..4b88f13 100644 --- a/conn.go +++ b/conn.go @@ -1,4 +1,5 @@ /* +tofuproxy -- flexible HTTP/WARC proxy with TLS certificates management Copyright (C) 2021 Sergey Matveev 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 . */ -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 }