SLonger
4/21/2017 - 2:29 AM

golang test udp socket buffer after set it value.

golang test udp socket buffer after set it value.

package main

import (
	"fmt"
	"net"
	//	"os"
	"syscall"
)

const (
	WriteBuffer = 8192
)

func main() {
	addr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8089")
	conn, err := net.DialUDP("udp", nil, addr)
	if err != nil {
		fmt.Printf("Some error %v", err)
		return
	}
	defer conn.Close()

	err = conn.SetWriteBuffer(WriteBuffer)
	if err != nil {
		fmt.Println("set error", err)
	}
	fd, _ := conn.File()
	value, _ := syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_SNDBUF)
	fmt.Println(value)
	fd.Close()
}