forked from quic-go/quic-go
rename the connection to rawConn
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
@@ -48,6 +49,14 @@ func (h *zeroRTTQueue) Clear() {
|
||||
}
|
||||
}
|
||||
|
||||
// rawConn is a connection that allow reading of a receivedPacket.
|
||||
type rawConn interface {
|
||||
ReadPacket() (*receivedPacket, error)
|
||||
WritePacket(b []byte, addr net.Addr, oob []byte) (int, error)
|
||||
LocalAddr() net.Addr
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type packetHandlerMapEntry struct {
|
||||
packetHandler packetHandler
|
||||
is0RTTQueue bool
|
||||
@@ -60,7 +69,7 @@ type packetHandlerMapEntry struct {
|
||||
type packetHandlerMap struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
conn connection
|
||||
conn rawConn
|
||||
connIDLen int
|
||||
|
||||
handlers map[string] /* string(ConnectionID)*/ packetHandlerMapEntry
|
||||
|
||||
@@ -13,7 +13,7 @@ type sendConn interface {
|
||||
}
|
||||
|
||||
type sconn struct {
|
||||
connection
|
||||
rawConn
|
||||
|
||||
remoteAddr net.Addr
|
||||
info *packetInfo
|
||||
@@ -22,9 +22,9 @@ type sconn struct {
|
||||
|
||||
var _ sendConn = &sconn{}
|
||||
|
||||
func newSendConn(c connection, remote net.Addr, info *packetInfo) sendConn {
|
||||
func newSendConn(c rawConn, remote net.Addr, info *packetInfo) sendConn {
|
||||
return &sconn{
|
||||
connection: c,
|
||||
rawConn: c,
|
||||
remoteAddr: remote,
|
||||
info: info,
|
||||
oob: info.OOB(),
|
||||
@@ -41,7 +41,7 @@ func (c *sconn) RemoteAddr() net.Addr {
|
||||
}
|
||||
|
||||
func (c *sconn) LocalAddr() net.Addr {
|
||||
addr := c.connection.LocalAddr()
|
||||
addr := c.rawConn.LocalAddr()
|
||||
if c.info != nil {
|
||||
if udpAddr, ok := addr.(*net.UDPAddr); ok {
|
||||
addrCopy := *udpAddr
|
||||
|
||||
@@ -61,7 +61,7 @@ type baseServer struct {
|
||||
tlsConf *tls.Config
|
||||
config *Config
|
||||
|
||||
conn connection
|
||||
conn rawConn
|
||||
// If the server is started with ListenAddr, we create a packet conn.
|
||||
// If it is started with Listen, we take a packet conn as a parameter.
|
||||
createdPacketConn bool
|
||||
|
||||
13
sys_conn.go
13
sys_conn.go
@@ -1,7 +1,6 @@
|
||||
package quic
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -10,14 +9,6 @@ import (
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
)
|
||||
|
||||
// connection is a connection that allow reading of a receivedPacket.
|
||||
type connection interface {
|
||||
ReadPacket() (*receivedPacket, error)
|
||||
WritePacket(b []byte, addr net.Addr, oob []byte) (int, error)
|
||||
LocalAddr() net.Addr
|
||||
io.Closer
|
||||
}
|
||||
|
||||
// OOBCapablePacketConn is a connection that allows the reading of ECN bits from the IP header.
|
||||
// If the PacketConn passed to Dial or Listen satisfies this interface, quic-go will use it.
|
||||
// In this case, ReadMsgUDP() will be used instead of ReadFrom() to read packets.
|
||||
@@ -30,7 +21,7 @@ type OOBCapablePacketConn interface {
|
||||
|
||||
var _ OOBCapablePacketConn = &net.UDPConn{}
|
||||
|
||||
func wrapConn(pc net.PacketConn) (connection, error) {
|
||||
func wrapConn(pc net.PacketConn) (rawConn, error) {
|
||||
conn, ok := pc.(interface {
|
||||
SyscallConn() (syscall.RawConn, error)
|
||||
})
|
||||
@@ -61,7 +52,7 @@ type basicConn struct {
|
||||
net.PacketConn
|
||||
}
|
||||
|
||||
var _ connection = &basicConn{}
|
||||
var _ rawConn = &basicConn{}
|
||||
|
||||
func (c *basicConn) ReadPacket() (*receivedPacket, error) {
|
||||
buffer := getPacketBuffer()
|
||||
|
||||
@@ -5,7 +5,7 @@ package quic
|
||||
|
||||
import "net"
|
||||
|
||||
func newConn(c net.PacketConn) (connection, error) {
|
||||
func newConn(c net.PacketConn) (rawConn, error) {
|
||||
return &basicConn{PacketConn: c}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ type oobConn struct {
|
||||
buffers [batchSize]*packetBuffer
|
||||
}
|
||||
|
||||
var _ connection = &oobConn{}
|
||||
var _ rawConn = &oobConn{}
|
||||
|
||||
func newConn(c OOBCapablePacketConn) (*oobConn, error) {
|
||||
rawConn, err := c.SyscallConn()
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func newConn(c OOBCapablePacketConn) (connection, error) {
|
||||
func newConn(c OOBCapablePacketConn) (rawConn, error) {
|
||||
return &basicConn{PacketConn: c}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user