mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
format import package name (#3455)
This commit is contained in:
@@ -22,20 +22,21 @@ import (
|
||||
"github.com/fatedier/golib/errors"
|
||||
)
|
||||
|
||||
// Custom listener
|
||||
type CustomListener struct {
|
||||
// InternalListener is a listener that can be used to accept connections from
|
||||
// other goroutines.
|
||||
type InternalListener struct {
|
||||
acceptCh chan net.Conn
|
||||
closed bool
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewCustomListener() *CustomListener {
|
||||
return &CustomListener{
|
||||
acceptCh: make(chan net.Conn, 64),
|
||||
func NewInternalListener() *InternalListener {
|
||||
return &InternalListener{
|
||||
acceptCh: make(chan net.Conn, 128),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CustomListener) Accept() (net.Conn, error) {
|
||||
func (l *InternalListener) Accept() (net.Conn, error) {
|
||||
conn, ok := <-l.acceptCh
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("listener closed")
|
||||
@@ -43,7 +44,7 @@ func (l *CustomListener) Accept() (net.Conn, error) {
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (l *CustomListener) PutConn(conn net.Conn) error {
|
||||
func (l *InternalListener) PutConn(conn net.Conn) error {
|
||||
err := errors.PanicToError(func() {
|
||||
select {
|
||||
case l.acceptCh <- conn:
|
||||
@@ -54,7 +55,7 @@ func (l *CustomListener) PutConn(conn net.Conn) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (l *CustomListener) Close() error {
|
||||
func (l *InternalListener) Close() error {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if !l.closed {
|
||||
@@ -64,6 +65,16 @@ func (l *CustomListener) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *CustomListener) Addr() net.Addr {
|
||||
return (*net.TCPAddr)(nil)
|
||||
func (l *InternalListener) Addr() net.Addr {
|
||||
return &InternalAddr{}
|
||||
}
|
||||
|
||||
type InternalAddr struct{}
|
||||
|
||||
func (ia *InternalAddr) Network() string {
|
||||
return "internal"
|
||||
}
|
||||
|
||||
func (ia *InternalAddr) String() string {
|
||||
return "internal"
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
gnet "github.com/fatedier/golib/net"
|
||||
libnet "github.com/fatedier/golib/net"
|
||||
)
|
||||
|
||||
var FRPTLSHeadByte = 0x17
|
||||
@@ -28,7 +28,7 @@ var FRPTLSHeadByte = 0x17
|
||||
func CheckAndEnableTLSServerConnWithTimeout(
|
||||
c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration,
|
||||
) (out net.Conn, isTLS bool, custom bool, err error) {
|
||||
sc, r := gnet.NewSharedConnSize(c, 2)
|
||||
sc, r := libnet.NewSharedConnSize(c, 2)
|
||||
buf := make([]byte, 1)
|
||||
var n int
|
||||
_ = c.SetReadDeadline(time.Now().Add(timeout))
|
||||
|
||||
Reference in New Issue
Block a user