Thanks for taking the time to respond Ian! If I'm understanding you correctly, the client's socket is what's storing the buffer. When accept is called, it looks in the queue of pending requests and it then creates a matching socket on the server. Is that right?
The thing that's still throwing me is the following: https://play.golang.org/p/YjxTKDYwnj func TestTCP(t *testing.T) { ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { panic(err) } // mock server connected := make(chan bool) go func() { conn, err := ln.Accept() if err != nil { panic(err) } fmt.Printf("closing connection\n") if e := conn.Close(); e != nil { panic(e) } fmt.Printf("closing listener\n") if e := ln.Close(); e != nil { panic(e) } close(connected) }() client, e := net.Dial("tcp", ln.Addr().String()) if e != nil { panic(e) } <-connected fmt.Printf("writing...\n") n, e := client.Write([]byte("hi world!")) if e != nil { panic(e) } fmt.Printf("wrote %d bytes\n", n) } Results in: closing connection closing listener writing... wrote 9 bytes Playground link: https://play.golang.org/p/YjxTKDYwnj Anyone know what's going on here? I would have thought that write would return EOF after closing the connection, but at the very least, after closing the listener. Thanks! Matt On Tuesday, October 24, 2017 at 12:43:21 AM UTC+7, Ian Lance Taylor wrote: > > On Mon, Oct 23, 2017 at 10:25 AM, Matt Mueller <mattm...@gmail.com > <javascript:>> wrote: > > > > Ah thanks guys for the insights, this led me to do some more digging: > > > > http://man7.org/linux/man-pages/man2/listen.2.html > > http://man7.org/linux/man-pages/man2/accept.2.html > > > > - Looks like Listen() creates a socket and a backlog queue. > > - When you call Dial(), the connection request gets stored in that > backlog > > - When you call Accept(), the connection gets dequeued and a new socket > is > > made for that connection > > > > What I still don't quite understand is, what happens to the written > bytes > > between Listen() and Accept()? Do they get buffered in that backlog > queue as > > well? > > No, they are stored in the socket's buffer. The backlog queue is a > queue of sockets. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.