Esempio n. 1
0
func (sch *aioScheduler) Write(fd int, buf []byte, off uint64) (int, error) {
	iocb := &C.iocb_t{}
	sh := *(*reflect.SliceHeader)(unsafe.Pointer(&buf))
	C.io_prep_pwrite(iocb, C.int(fd), unsafe.Pointer(sh.Data), C.size_t(sh.Len), C.longlong(off))
	ev, err := sch.submit(iocb)
	if err != nil {
		return 0, err
	}

	return int(ev.wait()), nil
}
Esempio n. 2
0
func WriteAt(fd int, off int64, buf []byte) (int, error) {
	size := len(buf)
	if size == 0 {
		return 0, nil
	}

	idx := <-idle_event
	retch := aio_result_map[idx]
	defer func() { idle_event <- idx }()

	var cb *C.struct_iocb = &cbs[idx]

	var write_buf unsafe.Pointer
	C.posix_memalign(&write_buf, pagesize, C.size_t(size))
	defer C.free(write_buf)
	for i := 0; i < size; i++ {
		*(*byte)(unsafe.Pointer(uintptr(write_buf) + uintptr(i))) = buf[i]
	}

	C.io_prep_pwrite(cb, C.int(fd), write_buf, C.size_t(size), C.longlong(off))
	cbs[idx].data = unsafe.Pointer(&idx)

	aio_lock.Lock()
	rt := C.io_submit(ctx, 1, &cb)

	if int(rt) < 0 {
		aio_lock.Unlock()
		return 0, errors.New("io submit failed")
	}
	aiocount++
	aio_lock.Unlock()

	select {
	case have_aio_event <- 0:
	default:
	}

	ret := <-retch
	return ret.size, ret.err
}