当前位置: 首页>>代码示例>>C++>>正文


C++ zmalloc函数代码示例

本文整理汇总了C++中zmalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ zmalloc函数的具体用法?C++ zmalloc怎么用?C++ zmalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zmalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: put

 *
 * if contains key
 * 		extract list no to tail, free old value(Is there any consistent problem?), update list pair value,
 * else
 * 		if FULL
 * 			delete list head and delete head (key, value) in map
 * 		add key value to list tail and put (key, list node address) to map
 *
 * 	There is a problem, if cache is full, new node will replace one old node and old node will be released,
 * 	object who owns the old node value will make error, so we strongly recommend to transport a value_dup function
 * 	to the cache, on which we will try to return a value dup_copy to the object.
 */
static void put(lru_cache_t *this, sds key, void *value) {
	void *v = this->map->op->get(this->map, key);

	pair_t *p = zmalloc(sizeof(pair_t));
	p->key = sds_dup(key);
	p->value = this->value_dup ? this->value_dup(value) : value;

	if(v == NULL) {
		if(this->max_size == this->list->len) {
			//if full, delete list head,
			this->map->op->del(this->map, ((pair_t *)(this->list->head->value))->key);
			this->list->list_ops->list_del_node(this->list, this->list->head);
		}
		this->list->list_ops->list_add_node_tail(this->list, p);
	}else {
		//delete old key-value in list
		list_node_t **node = v;

		if(this->list->free) {
开发者ID:Binyang2014,项目名称:filesystem,代码行数:31,代码来源:lru_cache.c

示例2: return

gv_argvlist_t *gvNEWargvlist(void)
{
    return (gv_argvlist_t*)zmalloc(sizeof(gv_argvlist_t));
}
开发者ID:CharlieSa,项目名称:livizjs,代码行数:4,代码来源:gvjobs.c

示例3: luaRedisGenericCommand

int luaRedisGenericCommand(lua_State *lua, int raise_error) {
    int j, argc = lua_gettop(lua);
    struct redisCommand *cmd;
    robj **argv;
    redisClient *c = server.lua_client;
    sds reply;

    /* Require at least one argument */
    if (argc == 0) {
        luaPushError(lua,
            "Please specify at least one argument for redis.call()");
        return 1;
    }

    /* Build the arguments vector */
    argv = zmalloc(sizeof(robj*)*argc);
    for (j = 0; j < argc; j++) {
        if (!lua_isstring(lua,j+1)) break;
        argv[j] = createStringObject((char*)lua_tostring(lua,j+1),
                                     lua_strlen(lua,j+1));
    }
    
    /* Check if one of the arguments passed by the Lua script
     * is not a string or an integer (lua_isstring() return true for
     * integers as well). */
    if (j != argc) {
        j--;
        while (j >= 0) {
            decrRefCount(argv[j]);
            j--;
        }
        zfree(argv);
        luaPushError(lua,
            "Lua redis() command arguments must be strings or integers");
        return 1;
    }

    /* Setup our fake client for command execution */
    c->argv = argv;
    c->argc = argc;

    /* Command lookup */
    cmd = lookupCommand(argv[0]->ptr);
    if (!cmd || ((cmd->arity > 0 && cmd->arity != argc) ||
                   (argc < -cmd->arity)))
    {
        if (cmd)
            luaPushError(lua,
                "Wrong number of args calling Redis command From Lua script");
        else
            luaPushError(lua,"Unknown Redis command called from Lua script");
        goto cleanup;
    }

    /* There are commands that are not allowed inside scripts. */
    if (cmd->flags & REDIS_CMD_NOSCRIPT) {
        luaPushError(lua, "This Redis command is not allowed from scripts");
        goto cleanup;
    }

    /* Write commands are forbidden against read-only slaves, or if a
     * command marked as non-deterministic was already called in the context
     * of this script. */
    if (cmd->flags & REDIS_CMD_WRITE) {
        if (server.lua_random_dirty) {
            luaPushError(lua,
                "Write commands not allowed after non deterministic commands");
            goto cleanup;
        } else if (server.masterhost && server.repl_slave_ro &&
                   !server.loading &&
                   !(server.lua_caller->flags & REDIS_MASTER))
        {
            luaPushError(lua, shared.roslaveerr->ptr);
            goto cleanup;
        } else if (server.stop_writes_on_bgsave_err &&
                   server.saveparamslen > 0 &&
                   server.lastbgsave_status == REDIS_ERR)
        {
            luaPushError(lua, shared.bgsaveerr->ptr);
            goto cleanup;
        }
    }

    /* If we reached the memory limit configured via maxmemory, commands that
     * could enlarge the memory usage are not allowed, but only if this is the
     * first write in the context of this script, otherwise we can't stop
     * in the middle. */
    if (server.maxmemory && server.lua_write_dirty == 0 &&
        (cmd->flags & REDIS_CMD_DENYOOM))
    {
        if (freeMemoryIfNeeded() == REDIS_ERR) {
            luaPushError(lua, shared.oomerr->ptr);
            goto cleanup;
        }
    }

    if (cmd->flags & REDIS_CMD_RANDOM) server.lua_random_dirty = 1;
    if (cmd->flags & REDIS_CMD_WRITE) server.lua_write_dirty = 1;

    /* Run the command */
//.........这里部分代码省略.........
开发者ID:Whitespace,项目名称:redis,代码行数:101,代码来源:scripting.c

示例4: zunionInterGenericCommand

void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
    int i, j, setnum;
    int aggregate = REDIS_AGGR_SUM;
    zsetopsrc *src;
    robj *dstobj;
    zset *dstzset;
    zskiplistNode *znode;
    dictIterator *di;
    dictEntry *de;
    int touched = 0;

    /* expect setnum input keys to be given */
    setnum = atoi(c->argv[2]->ptr);
    if (setnum < 1) {
        addReplyError(c,
            "at least 1 input key is needed for ZUNIONSTORE/ZINTERSTORE");
        return;
    }

    /* test if the expected number of keys would overflow */
    if (3+setnum > c->argc) {
        addReply(c,shared.syntaxerr);
        return;
    }

    /* read keys to be used for input */
    src = zmalloc(sizeof(zsetopsrc) * setnum);
    for (i = 0, j = 3; i < setnum; i++, j++) {
        robj *obj = lookupKeyWrite(c->db,c->argv[j]);
        if (!obj) {
            src[i].dict = NULL;
        } else {
            if (obj->type == REDIS_ZSET) {
                src[i].dict = ((zset*)obj->ptr)->dict;
            } else if (obj->type == REDIS_SET) {
                src[i].dict = (obj->ptr);
            } else {
                zfree(src);
                addReply(c,shared.wrongtypeerr);
                return;
            }
        }

        /* default all weights to 1 */
        src[i].weight = 1.0;
    }

    /* parse optional extra arguments */
    if (j < c->argc) {
        int remaining = c->argc - j;

        while (remaining) {
            if (remaining >= (setnum + 1) && !strcasecmp(c->argv[j]->ptr,"weights")) {
                j++; remaining--;
                for (i = 0; i < setnum; i++, j++, remaining--) {
                    if (getDoubleFromObjectOrReply(c,c->argv[j],&src[i].weight,
                            "weight value is not a double") != REDIS_OK)
                    {
                        zfree(src);
                        return;
                    }
                }
            } else if (remaining >= 2 && !strcasecmp(c->argv[j]->ptr,"aggregate")) {
                j++; remaining--;
                if (!strcasecmp(c->argv[j]->ptr,"sum")) {
                    aggregate = REDIS_AGGR_SUM;
                } else if (!strcasecmp(c->argv[j]->ptr,"min")) {
                    aggregate = REDIS_AGGR_MIN;
                } else if (!strcasecmp(c->argv[j]->ptr,"max")) {
                    aggregate = REDIS_AGGR_MAX;
                } else {
                    zfree(src);
                    addReply(c,shared.syntaxerr);
                    return;
                }
                j++; remaining--;
            } else {
                zfree(src);
                addReply(c,shared.syntaxerr);
                return;
            }
        }
    }

    /* sort sets from the smallest to largest, this will improve our
     * algorithm's performance */
    qsort(src,setnum,sizeof(zsetopsrc),qsortCompareZsetopsrcByCardinality);

    dstobj = createZsetObject();
    dstzset = dstobj->ptr;

    if (op == REDIS_OP_INTER) {
        /* skip going over all entries if the smallest zset is NULL or empty */
        if (src[0].dict && dictSize(src[0].dict) > 0) {
            /* precondition: as src[0].dict is non-empty and the zsets are ordered
             * from small to large, all src[i > 0].dict are non-empty too */
            di = dictGetIterator(src[0].dict);
            while((de = dictNext(di)) != NULL) {
                double score, value;

//.........这里部分代码省略.........
开发者ID:JakSprats,项目名称:Alchemy-Database,代码行数:101,代码来源:t_zset.c

示例5: zmalloc

redisSortOperation *createSortOperation(int type, robj *pattern) {
    redisSortOperation *so = zmalloc(sizeof(*so));
    so->type = type;
    so->pattern = pattern;
    return so;
}
开发者ID:JoonyLi,项目名称:redis-android,代码行数:6,代码来源:sort.c

示例6: smemgetCommand

void smemgetCommand(client *c)
{
    long long ll_size;
    int size;
    int mem_id = -1;
    listNode *ln;
    listIter li;
    struct smem_t * smem_p = NULL;


    // check the size

    if(getLongLongFromObject(c->argv[1],&ll_size) == C_OK){
        //serverLog(LL_WARNING,"[smemgetCommand] will get share memory size: %lld", ll_size);
        size = ll_size;
        
        // get buffer from list
        listRewind(server.smem_list_available, &li);
        while ((ln = listNext(&li)) != NULL) {
            smem_p = ln->value;

            // compare the size
            if((smem_p->state == SMEM_T_STATE_AVAILAVLE) && (size <= smem_p->size)){
                
                smem_p->state = SMEM_T_STATE_USED;
                smem_p->cnt = 1;
                smem_p->free_cnt = 0;
                smem_p->last_time = server.unixtime;
                mem_id = smem_p->id;

                // move it to used list
                smemlistMoveNode(server.smem_list_available, server.smem_list_used, ln);

                break;
            } 
        }
        
        if(mem_id == -1){
            // check the share memory max limit
            if((server.share_memory_size + size) <= server.share_memory_limit){
                // get buffer by use smem
                mem_id = smem_get_buffer(size);

                if(mem_id != -1){
                    
                    smem_p = zmalloc(sizeof(struct smem_t));
                    if(smem_p == NULL){
                        mem_id = -1;
                        serverLog(LL_WARNING,"[smemgetCommand] zmalloc failed.");
                    }else{
                        smem_p->id = mem_id;
                        smem_p->size = size;
                        smem_p->state = SMEM_T_STATE_USED;
                        smem_p->cnt = 1;
                        smem_p->free_cnt = 0;
                        smem_p->last_time = server.unixtime;
                        
                        // add itme to list
                        listAddNodeTail(server.smem_list_used, smem_p);

                        // update the share memory used status
                        server.share_memory_size += size;

                    }
                    
                }
            }else{
                serverLog(LL_WARNING,"[smemgetCommand] server.share_memory_size:%d + %d > server.share_memory_limit:%d", server.share_memory_size, size, server.share_memory_limit);
            }



        }
        
    }

    //serverLog(LL_WARNING,"[smemgetCommand] get share memory id: %d", mem_id);

    addReplyLongLong(c,mem_id);
    return C_OK;
}
开发者ID:shenhailuanma,项目名称:selfTestCode,代码行数:81,代码来源:smem4redis_old.c

示例7: lttng_userspace_probe_location_tracepoint_create_no_check

static struct lttng_userspace_probe_location *
lttng_userspace_probe_location_tracepoint_create_no_check(const char *binary_path,
		const char *provider_name, const char *probe_name,
		struct lttng_userspace_probe_location_lookup_method *lookup_method,
		bool open_binary)
{
	int binary_fd = -1;
	char *probe_name_copy = NULL;
	char *provider_name_copy = NULL;
	char *binary_path_copy = NULL;
	struct lttng_userspace_probe_location *ret = NULL;
	struct lttng_userspace_probe_location_tracepoint *location;

	if (open_binary) {
		binary_fd = open(binary_path, O_RDONLY);
		if (binary_fd < 0) {
			PERROR("open");
			goto error;
		}
	} else {
		binary_fd = -1;
	}

	probe_name_copy = lttng_strndup(probe_name, LTTNG_SYMBOL_NAME_LEN);
	if (!probe_name_copy) {
		PERROR("lttng_strndup");
		goto error;
	}

	provider_name_copy = lttng_strndup(provider_name, LTTNG_SYMBOL_NAME_LEN);
	if (!provider_name_copy) {
		PERROR("lttng_strndup");
		goto error;
	}

	binary_path_copy = lttng_strndup(binary_path, LTTNG_PATH_MAX);
	if (!binary_path_copy) {
		PERROR("lttng_strndup");
		goto error;
	}

	location = zmalloc(sizeof(*location));
	if (!location) {
		PERROR("zmalloc");
		goto error;
	}

	location->probe_name = probe_name_copy;
	location->provider_name = provider_name_copy;
	location->binary_path = binary_path_copy;
	location->binary_fd = binary_fd;

	ret = &location->parent;
	ret->lookup_method = lookup_method;
	ret->type = LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT;
	goto end;

error:
	free(probe_name_copy);
	free(provider_name_copy);
	free(binary_path_copy);
	if (binary_fd >= 0) {
		if (close(binary_fd)) {
			PERROR("Error closing binary fd in error path");
		}
	}
end:
	return ret;
}
开发者ID:lttng,项目名称:lttng-tools,代码行数:69,代码来源:userspace-probe.c

示例8: sinterGenericCommand

void sinterGenericCommand(redisClient *c, robj **setkeys, unsigned long setnum, robj *dstkey) {
    robj **sets = zmalloc(sizeof(robj*)*setnum);
    setTypeIterator *si;
    robj *eleobj, *dstset = NULL;
    int64_t intobj;
    void *replylen = NULL;
    unsigned long j, cardinality = 0;
    int encoding;

    for (j = 0; j < setnum; j++) {
        robj *setobj = dstkey ?
            lookupKeyWrite(c->db,setkeys[j]) :
            lookupKeyRead(c->db,setkeys[j]);
        if (!setobj) {
            zfree(sets);
            if (dstkey) {
                if (dbDelete(c->db,dstkey)) {
                    touchWatchedKey(c->db,dstkey);
                    server.dirty++;
                }
                addReply(c,shared.czero);
            } else {
                addReply(c,shared.emptymultibulk);
            }
            return;
        }
        if (checkType(c,setobj,REDIS_SET)) {
            zfree(sets);
            return;
        }
        sets[j] = setobj;
    }
    /* Sort sets from the smallest to largest, this will improve our
     * algorithm's performace */
    qsort(sets,setnum,sizeof(robj*),qsortCompareSetsByCardinality);

    /* The first thing we should output is the total number of elements...
     * since this is a multi-bulk write, but at this stage we don't know
     * the intersection set size, so we use a trick, append an empty object
     * to the output list and save the pointer to later modify it with the
     * right length */
    if (!dstkey) {
        replylen = addDeferredMultiBulkLength(c);
    } else {
        /* If we have a target key where to store the resulting set
         * create this key with an empty set inside */
        dstset = createIntsetObject();
    }

    /* Iterate all the elements of the first (smallest) set, and test
     * the element against all the other sets, if at least one set does
     * not include the element it is discarded */
    si = setTypeInitIterator(sets[0]);
    while((encoding = setTypeNext(si,&eleobj,&intobj)) != -1) {
        for (j = 1; j < setnum; j++) {
            if (encoding == REDIS_ENCODING_INTSET) {
                /* intset with intset is simple... and fast */
                if (sets[j]->encoding == REDIS_ENCODING_INTSET &&
                    !intsetFind((intset*)sets[j]->ptr,intobj))
                {
                    break;
                /* in order to compare an integer with an object we
                 * have to use the generic function, creating an object
                 * for this */
                } else if (sets[j]->encoding == REDIS_ENCODING_HT) {
                    eleobj = createStringObjectFromLongLong(intobj);
                    if (!setTypeIsMember(sets[j],eleobj)) {
                        decrRefCount(eleobj);
                        break;
                    }
                    decrRefCount(eleobj);
                }
            } else if (encoding == REDIS_ENCODING_HT) {
                /* Optimization... if the source object is integer
                 * encoded AND the target set is an intset, we can get
                 * a much faster path. */
                if (eleobj->encoding == REDIS_ENCODING_INT &&
                    sets[j]->encoding == REDIS_ENCODING_INTSET &&
                    !intsetFind((intset*)sets[j]->ptr,(long)eleobj->ptr))
                {
                    break;
                /* else... object to object check is easy as we use the
                 * type agnostic API here. */
                } else if (!setTypeIsMember(sets[j],eleobj)) {
                    break;
                }
            }
        }

        /* Only take action when all sets contain the member */
        if (j == setnum) {
            if (!dstkey) {
                if (encoding == REDIS_ENCODING_HT)
                    addReplyBulk(c,eleobj);
                else
                    addReplyBulkLongLong(c,intobj);
                cardinality++;
            } else {
                if (encoding == REDIS_ENCODING_INTSET) {
                    eleobj = createStringObjectFromLongLong(intobj);
//.........这里部分代码省略.........
开发者ID:jrun,项目名称:redis,代码行数:101,代码来源:t_set.c

示例9: sunionDiffGenericCommand

void sunionDiffGenericCommand(redisClient *c, robj **setkeys, int setnum, robj *dstkey, int op) {
    robj **sets = zmalloc(sizeof(robj*)*setnum);
    setTypeIterator *si;
    robj *ele, *dstset = NULL;
    int j, cardinality = 0;

    for (j = 0; j < setnum; j++) {
        robj *setobj = dstkey ?
            lookupKeyWrite(c->db,setkeys[j]) :
            lookupKeyRead(c->db,setkeys[j]);
        if (!setobj) {
            sets[j] = NULL;
            continue;
        }
        if (checkType(c,setobj,REDIS_SET)) {
            zfree(sets);
            return;
        }
        sets[j] = setobj;
    }

    /* We need a temp set object to store our union. If the dstkey
     * is not NULL (that is, we are inside an SUNIONSTORE operation) then
     * this set object will be the resulting object to set into the target key*/
    dstset = createIntsetObject();

    /* Iterate all the elements of all the sets, add every element a single
     * time to the result set */
    for (j = 0; j < setnum; j++) {
        if (op == REDIS_OP_DIFF && j == 0 && !sets[j]) break; /* result set is empty */
        if (!sets[j]) continue; /* non existing keys are like empty sets */

        si = setTypeInitIterator(sets[j]);
        while((ele = setTypeNextObject(si)) != NULL) {
            if (op == REDIS_OP_UNION || j == 0) {
                if (setTypeAdd(dstset,ele)) {
                    cardinality++;
                }
            } else if (op == REDIS_OP_DIFF) {
                if (setTypeRemove(dstset,ele)) {
                    cardinality--;
                }
            }
            decrRefCount(ele);
        }
        setTypeReleaseIterator(si);

        /* Exit when result set is empty. */
        if (op == REDIS_OP_DIFF && cardinality == 0) break;
    }

    /* Output the content of the resulting set, if not in STORE mode */
    if (!dstkey) {
        addReplyMultiBulkLen(c,cardinality);
        si = setTypeInitIterator(dstset);
        while((ele = setTypeNextObject(si)) != NULL) {
            addReplyBulk(c,ele);
            decrRefCount(ele);
        }
        setTypeReleaseIterator(si);
        decrRefCount(dstset);
    } else {
        /* If we have a target key where to store the resulting set
         * create this key with the result set inside */
        dbDelete(c->db,dstkey);
        if (setTypeSize(dstset) > 0) {
            dbAdd(c->db,dstkey,dstset);
            addReplyLongLong(c,setTypeSize(dstset));
        } else {
            decrRefCount(dstset);
            addReply(c,shared.czero);
        }
        touchWatchedKey(c->db,dstkey);
        server.dirty++;
    }
    zfree(sets);
}
开发者ID:jrun,项目名称:redis,代码行数:77,代码来源:t_set.c

示例10: triggleGenericCommand

void triggleGenericCommand(redisClient *c, int nx, robj *db_id, robj *key_pattern,robj *event_type, robj *script_source) {
    redisLog(REDIS_NOTICE,"dbid: %s keypattern: %s script_source: %s ",db_id->ptr,key_pattern->ptr,script_source->ptr);
    int id = atoi(db_id->ptr);
    int int_event=process_trigglecmd(event_type->ptr);
    if(int_event==-1)
    {
        addReplyError(c,"undefine event in redis triggle");
        return;
    }


    
    //redisLog(REDIS_NOTICE,"get event:%d for: %s",int_event,event_type->ptr);
    if(id<0||id>server.dbnum)
    {
        addReplyError(c,"wrong dbid for triggle");
        return;
    }

//    redisLog(REDIS_NOTICE,"add  into stack: %d",lua_gettop(server.lua));

    /*lua_check*/
    sds funcdef = sdsempty();

    funcdef = sdscat(funcdef,"function ");
    funcdef = sdscatlen(funcdef,key_pattern->ptr,sdslen(key_pattern->ptr));
    funcdef = sdscatlen(funcdef,"() ",3);
    funcdef = sdscatlen(funcdef,script_source->ptr,sdslen(script_source->ptr));
    funcdef = sdscatlen(funcdef," end",4);
    //redisLog(REDIS_NOTICE,"script function:%s",funcdef);

    if (luaL_loadbuffer(server.lua,funcdef,sdslen(funcdef),"@user_script")) {
        addReplyErrorFormat(c,"Error compiling script (new function): %s\n",
                lua_tostring(server.lua,-1));
        lua_pop(server.lua,1);
        sdsfree(funcdef);
        return ;
    }
    sdsfree(funcdef);


    //redisLog(REDIS_NOTICE,"add load buffer stack: %d",lua_gettop(server.lua));
    if (lua_pcall(server.lua,0,0,0)) {
        addReplyErrorFormat(c,"Error running script (new function): %s\n",
                lua_tostring(server.lua,-1));
        lua_pop(server.lua,1);
        return ;
    }

    //redisLog(REDIS_NOTICE,"run buffer stack: %d",lua_gettop(server.lua));
   
    struct bridge_db_triggle_t *tmptrg=zmalloc(sizeof(struct bridge_db_triggle_t));
    tmptrg->dbid=id;
    tmptrg->event=int_event;
    tmptrg->lua_scripts=script_source;
    incrRefCount(script_source);
    sds copy=sdsdup(key_pattern->ptr);
    dictAdd(server.bridge_db.triggle_scipts[id],copy,tmptrg);
    addReply(c, nx ? shared.cone : shared.ok);


}
开发者ID:crestxu,项目名称:redis-triggle,代码行数:62,代码来源:triggle_process.c

示例11: msaddCommand

void msaddCommand(redisClient *c) {
    int setnum, valnum;
    int i, j;
    robj **sets;

    setnum = atoi(c->argv[1]->ptr);
    valnum = atoi(c->argv[2]->ptr);

    if (setnum < 1) {
        addReplyError(c,
            "at least 1 input key is needed for MSADD");
        return;
    }

    if (valnum < 1) {
        addReplyError(c,
            "at least 1 input value is needed for MSADD");
        return;
    }
 
    /* test if the expected number of keys would overflow */
    if (3+setnum+valnum > c->argc) {
        addReply(c,shared.syntaxerr);
        return;
    }

    int useintset = 0;
    for (j = 0; j < valnum; j++) {
        robj *value = c->argv[3 + setnum + j];
        if (isObjectRepresentableAsLongLong(value,NULL) != REDIS_OK) {
            useintset = 1;
            break;
        }
    }

    sets = zmalloc(sizeof(robj*)*setnum);
    int notset = 0;
    for (i = 0; i < setnum; i++) {
        robj *key = c->argv[3 + i];
        robj *set = lookupKeyWrite(c->db, key);
        if (set == NULL) {
            if (useintset == 1)
                set = createIntsetObject();
            else
                set = createSetObject();
            dbAdd(c->db,key,set);
        } else {
            if (set->type != REDIS_SET) {
                notset = 1;
                break;
            }
        }
        sets[i] = set;
    }

    if (notset == 1) {
        addReply(c,shared.wrongtypeerr);
    } else {
        long long inserted = 0;
        for (i = 0; i < setnum; i++) {
            for (j = 0; j < valnum; j++) {
                robj *key = c->argv[3 + i];
                robj *value = c->argv[3 + setnum + j];
                robj *set = sets[i];
                if (setTypeAdd(set,value)) {
                    touchWatchedKey(c->db,key);
                    server.dirty++;
                    inserted++;
                }
            }
        }
        addReplyLongLong(c,inserted);
    }
    zfree(sets); 
}
开发者ID:jrun,项目名称:redis,代码行数:75,代码来源:t_set.c

示例12: zmalloc

/* Create an empty intset. */
intset *intsetNew(void) {
    intset *is = zmalloc(sizeof(intset));
    is->encoding = intrev32ifbe(INTSET_ENC_INT16);
    is->length = 0;
    return is;
}
开发者ID:xiaowei0516,项目名称:redis_comment,代码行数:7,代码来源:intset.c

示例13: handler

static void handler (zsock_t *pipe, void *args) {
    curl_global_init(CURL_GLOBAL_ALL);
    CURLM *multi = curl_multi_init ();
    CURLSH *share = curl_share_init ();
    curl_share_setopt (share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
    curl_share_setopt (share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
    curl_share_setopt (share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);

    long verbose = (*(bool *) args) ? 1L : 0L;
    long timeout = 30;
    CURLMcode code;

    SOCKET pipefd = zsock_fd (pipe);
    struct curl_waitfd waitfd = {pipefd, CURL_WAIT_POLLIN};

    //  List to hold pending curl handles, in case we are destroy the client
    //  while request are inprogress
    zlistx_t *pending_handles = zlistx_new ();
    zlistx_set_destructor (pending_handles, (zlistx_destructor_fn *) curl_destructor);

    zsock_signal (pipe, 0);

    bool terminated = false;
    while (!terminated) {
        int events = zsock_events (pipe);
        if ((events & ZMQ_POLLIN) == 0) {
            code = curl_multi_wait (multi, &waitfd, 1, 1000, NULL);
            assert (code == CURLM_OK);
        }

        events = zsock_events (pipe);
        if (events & ZMQ_POLLIN) {
            char* command = zstr_recv (pipe);
            if (!command)
                break;          //  Interrupted

            //  All actors must handle $TERM in this way
            if (streq (command, "$TERM"))
                terminated = true;
            else if (streq (command, "GET")) {
                char *url;
                zlistx_t *headers;
                void *userp;
                int rc = zsock_recv (pipe, "slp", &url, &headers, &userp);
                assert (rc == 0);

                zchunk_t *data = zchunk_new (NULL, 100);
                assert (data);
                struct curl_slist *curl_headers = zlistx_to_slist (headers);
                CURL *curl = curl_easy_init ();
                zlistx_add_end (pending_handles, curl);
                http_request *request = (http_request *) zmalloc (sizeof (http_request));
                assert (request);
                request->userp = userp;
                request->curl = curl;
                request->data = data;
                request->headers = curl_headers;

                curl_easy_setopt (curl, CURLOPT_SHARE, share);
                curl_easy_setopt (curl, CURLOPT_TIMEOUT, timeout);
                curl_easy_setopt (curl, CURLOPT_VERBOSE, verbose);
                curl_easy_setopt (curl, CURLOPT_HTTPHEADER, curl_headers);
                curl_easy_setopt (curl, CURLOPT_URL, url);
                curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_data);
                curl_easy_setopt (curl, CURLOPT_WRITEDATA, data);
                curl_easy_setopt (curl, CURLOPT_PRIVATE, request);

                code = curl_multi_add_handle (multi, curl);
                assert (code == CURLM_OK);
                zlistx_destroy (&headers);
                zstr_free (&url);
           }
           else {
               puts ("E: invalid message to actor");
               assert (false);
           }
           zstr_free (&command);
        }

        int still_running;
        code = curl_multi_perform (multi, &still_running);
        assert (code == CURLM_OK);

        int msgq = 0;
        struct CURLMsg *msg = curl_multi_info_read(multi, &msgq);

        while (msg) {
            if(msg->msg == CURLMSG_DONE) {
                CURL *curl = msg->easy_handle;
                http_request *request;
                curl_easy_getinfo(curl, CURLINFO_PRIVATE, &request);

                long response_code_long;
                curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &response_code_long);
                int response_code = (int)response_code_long;

                int rc = zsock_send (pipe, "icp", response_code, request->data, request->userp);
                assert (rc == 0);

                curl_multi_remove_handle (multi, curl);
//.........这里部分代码省略.........
开发者ID:jimklimov,项目名称:czmq,代码行数:101,代码来源:zhttp_client.c

示例14: zyre_event_new

zyre_event_t *
zyre_event_new (zyre_t *node)
{
    zmsg_t *msg = zyre_recv (node);
    if (!msg)
        return NULL;            //  Interrupted

    zyre_event_t *self = (zyre_event_t *) zmalloc (sizeof (zyre_event_t));
    assert (self);

    char *type = zmsg_popstr (msg);
    self->sender = zmsg_popstr (msg);
    self->name = zmsg_popstr (msg);

    if (streq (type, "ENTER")) {
        self->type = ZYRE_EVENT_ENTER;
        zframe_t *headers = zmsg_pop (msg);
        if (headers) {
            self->headers = zhash_unpack (headers);
            zframe_destroy (&headers);
        }
        self->address = zmsg_popstr (msg);
    }
    else
    if (streq (type, "EXIT"))
        self->type = ZYRE_EVENT_EXIT;
    else
    if (streq (type, "JOIN")) {
        self->type = ZYRE_EVENT_JOIN;
        self->group = zmsg_popstr (msg);
    }
    else
    if (streq (type, "LEAVE")) {
        self->type = ZYRE_EVENT_LEAVE;
        self->group = zmsg_popstr (msg);
    }
    else
    if (streq (type, "WHISPER")) {
        self->type = ZYRE_EVENT_WHISPER;
        self->msg = msg;
        msg = NULL;
    }
    else
    if (streq (type, "SHOUT")) {
        self->type = ZYRE_EVENT_SHOUT;
        self->group = zmsg_popstr (msg);
        self->msg = msg;
        msg = NULL;
    }
    else
    if (streq (type, "STOP")) {
        self->type = ZYRE_EVENT_STOP;
    }
    else
    if (streq (type, "EVASIVE")) {
        self->type = ZYRE_EVENT_EVASIVE;
    }
    else
        zsys_warning ("bad message received from node: %s\n", type);

    free (type);
    zmsg_destroy (&msg);
    return self;
}
开发者ID:GameFilebyOpenSourse,项目名称:zyre,代码行数:64,代码来源:zyre_event.c

示例15: symbol_number

symbol_t * symbol_number(long double d) {
    symbol_t *s = (symbol_t*)zmalloc(sizeof(symbol_t));
    s->type = stNumber;
    s->number = d;
    return s;
}
开发者ID:rodolf0,项目名称:natools,代码行数:6,代码来源:semanter.c


注:本文中的zmalloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。