func prepareCompletionBuffers(h windows.Handle, count int) (iocp windows.Handle, buffers []*readbuffer, err error) {
	iocp, err = windows.CreateIoCompletionPort(h, windows.Handle(0), 0, 0)
	if err != nil {
		return windows.Handle(0), nil, errors.Wrap(err, "error creating IO completion port")
	}

	buffers = make([]*readbuffer, count)
	for i := 0; i < count; i++ {
		buf := (*readbuffer)(C.malloc(C.size_t(unsafe.Sizeof(readbuffer{}))))
		C.memset(unsafe.Pointer(buf), 0, C.size_t(unsafe.Sizeof(readbuffer{})))
		buffers[i] = buf

		err = windows.ReadFile(h, buf.data[:], nil, &(buf.ol))
		if err != nil && err != windows.ERROR_IO_PENDING {
			_ = windows.CloseHandle(iocp)
			return windows.Handle(0), nil, errors.Wrap(err, "failed to initiate readfile")
		}
	}

	return iocp, buffers, nil
}
// prepare N read buffers
// and return the IoCompletionPort that will be used to coordinate reads.
// danger: even though all reads will reference the returned iocp, buffers must be in-scope as long
// as reads are happening. Otherwise, the memory the kernel is writing to will be written to memory reclaimed
// by the GC
prepare N read buffers
and return the IoCompletionPort that will be used to coordinate reads.
danger: even though all reads will reference the returned iocp, buffers must be in-scope as long
as reads are happening. Otherwise, the memory the kernel is writing to will be written to memory reclaimed
by the GC
// prepare N read buffers // and return the IoCompletionPort that will be used to coordinate reads . // danger : even though all reads will reference the returned iocp buffers must be in - scope as long // as reads are happening . Otherwise the memory the kernel is writing to will be written to memory reclaimed // by the GC
func prepareCompletionBuffers(h windows.Handle, count int) (iocp windows.Handle, buffers []*readbuffer, err error) {
	iocp, err = windows.CreateIoCompletionPort(h, windows.Handle(0), 0, 0)
	if err != nil {
		return windows.Handle(0), nil, errors.Wrap(err, "error creating IO completion port")
	}
	buffers = make([]*readbuffer, count)
	for i := 0; i < count; i++ {
		buf := (*readbuffer)(C.malloc(C.size_t(unsafe.Sizeof(readbuffer{}))))
		C.memset(unsafe.Pointer(buf), 0, C.size_t(unsafe.Sizeof(readbuffer{})))
		buffers[i] = buf
		err = windows.ReadFile(h, buf.data[:], nil, &(buf.ol))
		if err != nil && err != windows.ERROR_IO_PENDING {
			_ = windows.CloseHandle(iocp)
			return windows.Handle(0), nil, errors.Wrap(err, "failed to initiate readfile")
		}
	}
	return iocp, buffers, nil
}
func prepareCompletionBuffers ( h windows . Handle , count int ) ( iocp windows . Handle , buffers [ ] * readbuffer , err error ) { iocp , err = windows . CreateIoCompletionPort ( h , windows . Handle ( 0 ) , 0 , 0 ) if err != nil { return windows . Handle ( 0 ) , nil , errors . Wrap ( err , " " ) } buffers = make ( [ ] * readbuffer , count ) for i := 0 ; i < count ; i ++ { buf := ( * readbuffer ) ( C . malloc ( C . size_t ( unsafe . Sizeof ( readbuffer { } ) ) ) ) C . memset ( unsafe . Pointer ( buf ) , 0 , C . size_t ( unsafe . Sizeof ( readbuffer { } ) ) ) buffers [ i ] = buf err = windows . ReadFile ( h , buf . data [ : ] , nil , & ( buf . ol ) ) if err != nil && err != windows . ERROR_IO_PENDING { _ = windows . CloseHandle ( iocp ) return windows . Handle ( 0 ) , nil , errors . Wrap ( err , " " ) } } return iocp , buffers , nil }
prepare N read buffers
and return the IoCompletionPort that will be used to coordinate reads.
prepare N read buffers and return the IoCompletionPort that will be used to coordinate reads .