int AsyncSSLSocket::eorAwareSSLWrite(
    const ssl::SSLUniquePtr& ssl,
    const void* buf,
    int n,
    bool eor) {
  if (eor && isEorTrackingEnabled()) {
    if (appEorByteNo_) {
      // cannot track for more than one app byte EOR
      CHECK(appEorByteNo_ == appBytesWritten_ + n);
    } else {
      appEorByteNo_ = appBytesWritten_ + n;
    }

    // 1. It is fine to keep updating minEorRawByteNo_.
    // 2. It is _min_ in the sense that SSL record will add some overhead.
    minEorRawByteNo_ = getRawBytesWritten() + n;
  }

  n = sslWriteImpl(ssl.get(), buf, n);
  if (n > 0) {
    appBytesWritten_ += n;
    if (appEorByteNo_) {
      if (getRawBytesWritten() >= minEorRawByteNo_) {
        minEorRawByteNo_ = 0;
      }
      if (appBytesWritten_ == appEorByteNo_) {
        appEorByteNo_ = 0;
        appEorByteWriteFlags_ = {};
      } else {
        CHECK(appBytesWritten_ < appEorByteNo_);
      }
    }
  }
  return n;
}
int AsyncSSLSocket::eorAwareSSLWrite(
    const ssl::SSLUniquePtr& ssl,
    const void* buf,
    int n,
    bool eor) {
  if (eor && isEorTrackingEnabled()) {
    if (appEorByteNo_) {
       
      CHECK(appEorByteNo_ == appBytesWritten_ + n);
    } else {
      appEorByteNo_ = appBytesWritten_ + n;
    }

     
     
    minEorRawByteNo_ = getRawBytesWritten() + n;
  }

  n = sslWriteImpl(ssl.get(), buf, n);
  if (n > 0) {
    appBytesWritten_ += n;
    if (appEorByteNo_) {
      if (getRawBytesWritten() >= minEorRawByteNo_) {
        minEorRawByteNo_ = 0;
      }
      if (appBytesWritten_ == appEorByteNo_) {
        appEorByteNo_ = 0;
        appEorByteWriteFlags_ = {};
      } else {
        CHECK(appBytesWritten_ < appEorByteNo_);
      }
    }
  }
  return n;
}