Hello everyone,
<<Unix Network Programming>> said SO_RCVBUF should be set before a
connection is established, but in Go, no TCPConn object can be get
before a call of Dial to remote server, which means I have to
SetReadBuffer after a connection is established, like:
func main() {
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:9999")
if err != nil {
panic(err)
}
tcpConn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
panic(err)
}
if err := tcpConn.SetReadBuffer(4096); err != nil {
panic(err)
}
buffer := make([]byte, 8192)
n, err := tcpConn.Read(buffer)
if err != nil {
println(err.Error())
} else {
println(n)
}
tcpConn.Close()
}
If the server sends 6000 bytes, this code should print 4096, right?
Thanks minux. what about the call order? how can go set the buffer after the connection is established? i checked the code but did not find any magic.
func FileConn(f *os.File) (c Conn, err error) {
// TODO: Implement this
return nil, os.NewSyscallError("FileConn", syscall.EWINDOWS)
}