Esempio n. 1
0
func TestConnUnicastSocketOptions(t *testing.T) {
	switch runtime.GOOS {
	case "plan9":
		t.Skipf("not supported on %q", runtime.GOOS)
	}
	ifi := loopbackInterface()
	if ifi == nil {
		t.Skipf("not available on %q", runtime.GOOS)
	}

	ln, err := net.Listen("tcp4", "127.0.0.1:0")
	if err != nil {
		t.Fatalf("net.Listen failed: %v", err)
	}
	defer ln.Close()

	done := make(chan bool)
	go acceptor(t, ln, done)

	c, err := net.Dial("tcp4", ln.Addr().String())
	if err != nil {
		t.Fatalf("net.Dial failed: %v", err)
	}
	defer c.Close()

	testUnicastSocketOptions(t, ipv4.NewConn(c))

	<-done
}
func TestTCPUnicastSockopt(t *testing.T) {
	for _, tt := range unicastSockoptTests {
		listener := make(chan net.Listener)
		go tcpListener(t, "127.0.0.1:0", listener)
		ln := <-listener
		if ln == nil {
			return
		}
		defer ln.Close()
		c, err := net.Dial("tcp4", ln.Addr().String())
		if err != nil {
			t.Errorf("net.Dial failed: %v", err)
			return
		}
		defer c.Close()

		cc := ipv4.NewConn(c)
		if err := testUnicastSockopt(t, tt, cc); err != nil {
			break
		}
	}
}
Esempio n. 3
0
func ExampleUnicastTCPListener() {
	ln, err := net.Listen("tcp4", "0.0.0.0:1024")
	if err != nil {
		log.Fatal(err)
	}
	defer ln.Close()
	for {
		c, err := ln.Accept()
		if err != nil {
			log.Fatal(err)
		}
		go func(c net.Conn) {
			defer c.Close()
			err := ipv4.NewConn(c).SetTOS(ipv4.DSCP_AF11)
			if err != nil {
				log.Fatal(err)
			}
			_, err = c.Write([]byte("HELLO-R-U-THERE-ACK"))
			if err != nil {
				log.Fatal(err)
			}
		}(c)
	}
}