code: func (w *PktlineWriter) flush() (int, error) {
  	var n int
  
  	for len(w.buf) > 0 {
  		if err := w.pl.writePacket(w.buf); err != nil {
  			return 0, err
  		}
  
  		m := tools.MinInt(len(w.buf), MaxPacketLength)
  
  		w.buf = w.buf[m:]
  
  		n = n + m
  	}
  
  	return n, nil
  }
docs: // flush writes any data in the internal buffer out to the underlying protocol
  // stream. If the amount of data in the internal buffer exceeds the
  // MaxPacketLength, the data will be written in multiple packets to accommodate.
  //
  // flush returns the number of bytes written to the underlying packet stream,
  // and any error that it encountered along the way.