3 ms·
Dumb question, but you can't listen for a close socket event in Go?
by markdog12 6y ago
Dumb question, but you can't listen for a close socket event in Go?
- tptacek 6y agoA TCP half-close, with a FIN? I think that's a limitation of the socket system call API itself.
- markdog12 6y agoYeah, I wasn't sure. I was looking at a Dart MySQL connection pool implementation, and that's what's done. socket.listen(onData, onDone: onSocketDone); onSocketDone() { _closed = true; } write(Buffer buffer) { if (_closed) throw StateError('Cannot write to socket, it is closed'); ...write } onData(RawSocketEvent event) { if (event == RawSocketEvent.READ_CLOSED) { _closed = true; } // Other events handled as well, READ, CLOSED, WRITE } But I don't know what's going on under the hood there.