Skip to content

Instantly share code, notes, and snippets.

@SLonger
Last active April 21, 2017 02:31
Show Gist options
  • Save SLonger/c8b25a9e72ccc0fa3969d6b8cf3d143d to your computer and use it in GitHub Desktop.
Save SLonger/c8b25a9e72ccc0fa3969d6b8cf3d143d to your computer and use it in GitHub Desktop.
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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment