예제 #1
0
void ch_remove(clientHash *hashmap, int id) {
	client *client = ch_get(hashmap, id);

	if (client != NULL) {
		cl_remove(client);
		hashmap->curr_size--;
	}
}
예제 #2
0
int ch_find(cpool_t *cpool, off_t offset, size_t size, chunk_t **ch) {
	if (!cpool || !ch || !cpool->ht || cpool->fd < 0 ||
		   cpool->nr_pages > cpool->threshold) return EINVAL;

	if (size == 0) {
		*ch = NULL;
		return 0;
	}

	off_t idx = (off_t) (offset / get_ch_size(1));
	off_t len = (off_t) (size / get_ch_size(1) + 1);

	int err = ch_get(cpool, idx, len, ch);
	if (err) return err;
	(*ch)->ref_cnt++;
	return 0;

}
예제 #3
0
int ch_acquire(cpool_t *cpool, off_t offset, size_t size, chunk_t **ch_ptr) {
	if (!cpool || !ch_ptr || !cpool->ht || cpool->fd < 0) return EINVAL;

	if (size == 0) {
		*ch_ptr = NULL;
		return 0;
	}

	off_t idx = (off_t) (offset / get_ch_size(1));
	off_t len = (off_t) (size / get_ch_size(1) + 1);

	int err = ch_get(cpool, idx, len, ch_ptr);

	chunk_t *ch = *ch_ptr;

	switch(err) {
		case 0:
			ch->ref_cnt++;
			return 0;
		case ENODATA:
			if (ch == NULL || !(err = cpool_del(ch)))
				return ch_construct(cpool, idx, len, ch_ptr);
			if (err != EBUSY) return err;
			void *newpl = mremap(ch->payload, get_ch_size(ch->len), get_ch_size(idx + len - ch->idx), 0);
			if (newpl != MAP_FAILED) {
				ch->payload = newpl;
				ch->ref_cnt++;
				return 0;
			} else {
				if (errno != ENOMEM) return errno;
				return ch_construct(cpool, idx, len, ch_ptr);
			}
		default:
			return err;
	}
}