Q:

golang get udp socket buffer size

I'm writing a udp client and set udp socket send buffer by SetWriteBuffer. 
   addr, _ := net.ResolveUDPAddr("udp", ":8089")
   conn, err :=net.DialUDP("udp", nil, addr)  
   err =conn.SetWriteBuffer(64*1024*1024)

as above, how can I test set the value is effective or get the send buffer value after  call SetWriteBuffer function.
Thank you all.

A:

After looking at the net package code, it looks like SetWriteBuffer makes a syscall to setsockopt (for posix). There is no similar function for GetWriteBuffer. The only way i can think to do this is by making another syscall to getsockopt like so.
addr, _ := net.ResolveUDPAddr("udp", ":8089")
conn, _ := net.DialUDP("udp", nil, addr)
conn.SetWriteBuffer(10 * 1024)
fd, _ := conn.File()
value, _ := syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_SNDBUF)
log.Println(value)
fd.Close()
conn.Close()

