File: send_conn.go

package info (click to toggle)
golang-github-lucas-clemente-quic-go 0.19.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,716 kB
  • sloc: sh: 36; makefile: 9
file content (34 lines) | stat: -rw-r--r-- 598 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package quic

import (
	"net"
)

// A sendConn allows sending using a simple Write() on a non-connected packet conn.
type sendConn interface {
	Write([]byte) error
	Close() error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
}

type sconn struct {
	net.PacketConn

	remoteAddr net.Addr
}

var _ sendConn = &sconn{}

func newSendConn(c net.PacketConn, remote net.Addr) sendConn {
	return &sconn{PacketConn: c, remoteAddr: remote}
}

func (c *sconn) Write(p []byte) error {
	_, err := c.PacketConn.WriteTo(p, c.remoteAddr)
	return err
}

func (c *sconn) RemoteAddr() net.Addr {
	return c.remoteAddr
}