github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/internal/gateway/tcp/listener.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package tcpGateway
     5  
     6  import (
     7  	"net"
     8  
     9  	"github.com/valyala/tcplisten"
    10  )
    11  
    12  /*
    13     Creation Time: 2021 - Mar - 04
    14     Created by:  (ehsan)
    15     Maintainers:
    16        1.  Ehsan N. Moosa (E2)
    17     Auditor: Ehsan N. Moosa (E2)
    18     Copyright Ronak Software Group 2020
    19  */
    20  
    21  type wrapListener struct {
    22  	l net.Listener
    23  }
    24  
    25  func (w *wrapListener) Accept() (net.Conn, error) {
    26  	c, err := w.l.Accept()
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	return acquireWrapConn(c), nil
    32  }
    33  
    34  func (w *wrapListener) Close() error {
    35  	return w.l.Close()
    36  }
    37  
    38  func (w *wrapListener) Addr() net.Addr {
    39  	return w.l.Addr()
    40  }
    41  
    42  func newWrapListener(listenOn string) (wl *wrapListener, err error) {
    43  	tcpConfig := tcplisten.Config{
    44  		ReusePort:   true,
    45  		FastOpen:    true,
    46  		DeferAccept: true,
    47  		Backlog:     2048,
    48  	}
    49  	wl = &wrapListener{}
    50  	wl.l, err = tcpConfig.NewListener("tcp4", listenOn)
    51  
    52  	return
    53  }