Add SO_REUSEPORT support for EntryPoints
This commit is contained in:
parent
40de310927
commit
d02be003ab
19 changed files with 279 additions and 43 deletions
|
@ -1,7 +1,9 @@
|
|||
package udp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
|
@ -33,18 +35,22 @@ type Listener struct {
|
|||
}
|
||||
|
||||
// Listen creates a new listener.
|
||||
func Listen(network string, laddr *net.UDPAddr, timeout time.Duration) (*Listener, error) {
|
||||
func Listen(listenConfig net.ListenConfig, network, address string, timeout time.Duration) (*Listener, error) {
|
||||
if timeout <= 0 {
|
||||
return nil, errors.New("timeout should be greater than zero")
|
||||
}
|
||||
|
||||
conn, err := net.ListenUDP(network, laddr)
|
||||
packetConn, err := listenConfig.ListenPacket(context.Background(), network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("listen packet: %w", err)
|
||||
}
|
||||
pConn, ok := packetConn.(*net.UDPConn)
|
||||
if !ok {
|
||||
return nil, errors.New("packet conn is not an UDPConn")
|
||||
}
|
||||
|
||||
l := &Listener{
|
||||
pConn: conn,
|
||||
pConn: pConn,
|
||||
acceptCh: make(chan *Conn),
|
||||
conns: make(map[string]*Conn),
|
||||
accepting: true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue