Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net: Setting a deadline to a net.TCPConn has no effect if there was a "File()" method call. #7605
What does 'go version' print? go version go1.2 linux/amd64 What steps reproduce the problem? Code: http://play.golang.org/p/TasQabnlRu 1. Create a new *net.TCPConn (using net.Accept) 2. Call File() 3. Close new file 4. Set Read Deadline to 5 seconds 5. Start reading What happened? The reading is never finishes. As the result i see the following output: > New Connection: 127.0.0.1:33079 > Fd: 7 > What should have happened instead? > New Connection: 127.0.0.1:33079 > Fd: 7 > Error: read tcp 127.0.0.1:33079: i/o timeout Please provide any additional information below. I'm trying to understand why this code sample doesn't work. As i understand, File() creates a copy of the underlying fd. And the new fd has no effect to the original. One more thing... If i use only the SetReadDeadline function - timeout doesn't work. But if i use it in couple with the syscall.SetsockoptTimeval function - it works.
See dup and/or fcntl online manual. The duplicated file descritor will point the original file entry, and some attributes/flags bound to the original file entry will be shared. In this case, you need to do the following: 1) f2, err := c1.(*net.TCPConn).File() 2) c1.Close() 3) tweak attrs/flags via f2 4) c2, err := net.FileConn(f2) 5) f2.Close() 6) use c2 for network IO
Status changed to WorkingAsIntended.
This issue was closed.