Exemple #1
0
func (s *Session) ServerSend(keys *DnetRawIDKeys, flags uint64, groups []uint32) (<-chan IteratorResult, error) {
	if len(groups) == 0 {
		return nil, fmt.Errorf("server-send: invalid empty group set, must contain at least one group")
	}

	responseCh := make(chan IteratorResult, defaultVOLUME)

	onResultContext := NextContext()
	onFinishContext := NextContext()

	onResult := func(iterres *iteratorResult) {
		responseCh <- iterres
	}

	onFinish := func(err error) {
		if err != nil {
			responseCh <- &iteratorResult{err: err}
		}
		close(responseCh)

		Pool.Delete(onResultContext)
		Pool.Delete(onFinishContext)
	}

	Pool.Store(onResultContext, onResult)
	Pool.Store(onFinishContext, onFinish)

	C.session_server_send(s.session, C.context_t(onResultContext), C.context_t(onFinishContext),
		keys.keys,
		C.uint64_t(flags),
		(*C.uint32_t)(&groups[0]), (C.size_t)(len(groups)))

	return responseCh, nil
}
Exemple #2
0
func (s *Session) ServerSend(keys []DnetRawID, flags uint64, groups []uint32) (*DChannel, error) {
	if len(groups) == 0 {
		return nil, fmt.Errorf("server-send: invalid empty group set, must contain at least one group")
	}
	if len(keys) == 0 {
		return nil, fmt.Errorf("server-send: invalid empty key set, must contain at least one key")
	}

	id_keys, err := NewDnetRawIDKeys(keys)
	if err != nil {
		return nil, fmt.Errorf("server-send: could not allocate vector of dnet_raw_id structures: %v", err)
	}
	defer id_keys.Free()

	responseCh := NewDChannel()

	onResultContext := NextContext()
	onFinishContext := NextContext()

	onResult := func(iterres *iteratorResult) {
		responseCh.In <- iterres
	}

	onFinish := func(err error) {
		if err != nil {
			responseCh.In <- &iteratorResult{err: err}
		}
		close(responseCh.In)

		Pool.Delete(onResultContext)
		Pool.Delete(onFinishContext)
	}

	Pool.Store(onResultContext, onResult)
	Pool.Store(onFinishContext, onFinish)

	C.session_server_send(s.session, C.context_t(onResultContext), C.context_t(onFinishContext),
		id_keys.keys,
		C.uint64_t(flags),
		(*C.uint32_t)(&groups[0]), (C.size_t)(len(groups)))

	return responseCh, nil
}