that's entirely consistent with UDP.
ron
I can appreciate your point, but is it consistent with the rest of the
net package?
Regards
Albert
On Fri, Jul 29, 2011 at 7:30 PM, Kyle Lemons <kev...@google.com> wrote:
> Yeah, I believe that's consistent with the tcp parts net package, and the
> underlying behavior on linux. There have been some discussion about changing
> it, but I don't think the decision was made to do so. If I find I actually
> need to terminate a listening/reading socket, I make an ephemeral connection
> so that the last accept/read fires and use some signal to indicate that it
> should stop.
> ~K
As far as I can tell from the following test code, closing a TCP
socket causes read to return EOF:
func TestTCP(t* testing.T) {
l, err := net.Listen("tcp", "localhost:12345")
if err != nil {
panic(err)
}
go func() {
c, err := l.Accept()
if err != nil {
panic(err)
}
println("server reading")
c.Read(make([]byte, 1024))
println("server read")
}()
c, err := net.Dial("tcp", "localhost:12345")
if err != nil {
panic(err)
}
go func() {
println("client reading")
_, err := c.Read(make([]byte, 1024))
fmt.Printf("err=%v\n", err)
println("client read")
}()
time.Sleep(3e9)
if err := c.Close(); err != nil {
panic(err)
}
select {}
}
Making an ephemeral connection to shut down the server seems a bit
ugly. I can't think of another language/library where I've had to
resort to that.
Regards
Albert
Russ