Exemplo n.º 1
0
func ReadAt(fd int, off int64, size int) ([]byte, error) {
	idx := <-idle_event
	retch := aio_result_map[idx]
	defer func() { idle_event <- idx }()

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

	var read_buf unsafe.Pointer
	C.posix_memalign(&read_buf, pagesize, C.size_t(size))
	defer C.free(read_buf)

	C.io_prep_pread(cb, C.int(fd), read_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 nil, errors.New("io submit failed")
	}
	aiocount++
	aio_lock.Unlock()

	select {
	case have_aio_event <- 0:
	default:
	}

	ret := <-retch

	return ret.buf, ret.err
}
Exemplo n.º 2
0
func (sch *aioScheduler) Read(fd int, buf []byte, off uint64) (int, error) {
	iocb := &C.iocb_t{}
	sh := *(*reflect.SliceHeader)(unsafe.Pointer(&buf))
	C.io_prep_pread(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
}