// writeToVDI sends data packets to the vdi interface upto the // count number that is defined within the function. If there is // an error, it returns the no. of packets sent until the error // occurred. func writeToVDI(vdi *picard.VDI, vdiChan chan<- *vdiData, count int) (int, error) { defer close(vdiChan) var offset int for i := 0; i < count; i++ { buf := randPayload() if _, err := vdi.WriteAt(buf, offset); err != nil { return i, err } vdiChan <- &vdiData{buf} offset += len(buf) } return count, nil }