/*
+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
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package main
+package tofuproxy
import (
"net"
type SingleConn struct {
conn net.Conn
ln *SingleListener
+ once sync.Once
}
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()
}
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 }