MCPcopy
hub / github.com/golang/net / ExampleConn_markingTCP

Function ExampleConn_markingTCP

ipv6/example_test.go:18–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func ExampleConn_markingTCP() {
19 ln, err := net.Listen("tcp", "[::]:1024")
20 if err != nil {
21 log.Fatal(err)
22 }
23 defer ln.Close()
24
25 for {
26 c, err := ln.Accept()
27 if err != nil {
28 log.Fatal(err)
29 }
30 go func(c net.Conn) {
31 defer c.Close()
32 if c.RemoteAddr().(*net.TCPAddr).IP.To16() != nil && c.RemoteAddr().(*net.TCPAddr).IP.To4() == nil {
33 p := ipv6.NewConn(c)
34 if err := p.SetTrafficClass(0x28); err != nil { // DSCP AF11
35 log.Fatal(err)
36 }
37 if err := p.SetHopLimit(128); err != nil {
38 log.Fatal(err)
39 }
40 }
41 if _, err := c.Write([]byte("HELLO-R-U-THERE-ACK")); err != nil {
42 log.Fatal(err)
43 }
44 }(c)
45 }
46}
47
48func ExamplePacketConn_servingOneShotMulticastDNS() {
49 c, err := net.ListenPacket("udp6", "[::]:5353") // mDNS over UDP

Callers

nothing calls this directly

Calls 7

NewConnFunction · 0.92
CloseMethod · 0.65
SetTrafficClassMethod · 0.65
SetHopLimitMethod · 0.65
WriteMethod · 0.65
AcceptMethod · 0.45
RemoteAddrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…