mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
6fde3632ef
The vendor/ folder was created with the help of @FiloSottile's gvt and vendorcheck. Any dependencies of Caddy plugins outside this repo are not vendored. We do not remove any unused, vendored packages because vendorcheck -u only checks using the current build configuration; i.e. packages that may be imported by files toggled by build tags of other systems. CI tests have been updated to ignore the vendor/ folder. When Go 1.9 is released, a few of the go commands should be revised to again use ./... as it will ignore the vendor folder by default.
54 lines
880 B
Go
54 lines
880 B
Go
package quic
|
|
|
|
import (
|
|
"net"
|
|
"sync"
|
|
)
|
|
|
|
type connection interface {
|
|
Write([]byte) error
|
|
Read([]byte) (int, net.Addr, error)
|
|
Close() error
|
|
LocalAddr() net.Addr
|
|
RemoteAddr() net.Addr
|
|
SetCurrentRemoteAddr(net.Addr)
|
|
}
|
|
|
|
type conn struct {
|
|
mutex sync.RWMutex
|
|
|
|
pconn net.PacketConn
|
|
currentAddr net.Addr
|
|
}
|
|
|
|
var _ connection = &conn{}
|
|
|
|
func (c *conn) Write(p []byte) error {
|
|
_, err := c.pconn.WriteTo(p, c.currentAddr)
|
|
return err
|
|
}
|
|
|
|
func (c *conn) Read(p []byte) (int, net.Addr, error) {
|
|
return c.pconn.ReadFrom(p)
|
|
}
|
|
|
|
func (c *conn) SetCurrentRemoteAddr(addr net.Addr) {
|
|
c.mutex.Lock()
|
|
c.currentAddr = addr
|
|
c.mutex.Unlock()
|
|
}
|
|
|
|
func (c *conn) LocalAddr() net.Addr {
|
|
return c.pconn.LocalAddr()
|
|
}
|
|
|
|
func (c *conn) RemoteAddr() net.Addr {
|
|
c.mutex.RLock()
|
|
addr := c.currentAddr
|
|
c.mutex.RUnlock()
|
|
return addr
|
|
}
|
|
|
|
func (c *conn) Close() error {
|
|
return c.pconn.Close()
|
|
}
|