Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Dumb question, but you can't listen for a close socket event in Go?


A TCP half-close, with a FIN? I think that's a limitation of the socket system call API itself.


Yeah, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: