本文整理汇总了C++中sdsMakeRoomFor函数的典型用法代码示例。如果您正苦于以下问题:C++ sdsMakeRoomFor函数的具体用法?C++ sdsMakeRoomFor怎么用?C++ sdsMakeRoomFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sdsMakeRoomFor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sdsgrowzero
sds sdsgrowzero(sds s, size_t len) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
size_t totlen, curlen = sh->len;
// 如果 len 比字符串的现有长度小,
// 那么直接返回,不做动作
if (len <= curlen) return s;
// 扩展 sds
// T = O(N)
s = sdsMakeRoomFor(s,len-curlen);
// 如果内存不足,直接返回
if (s == NULL) return NULL;
/* Make sure added region doesn't contain garbage */
// 将新分配的空间用 0 填充,防止出现垃圾内容
// T = O(N)
sh = (void*)(s-(sizeof(struct sdshdr)));
memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */
// 更新属性
totlen = sh->len+sh->free;
sh->len = len;
sh->free = totlen-sh->len;
// 返回新的 sds
return s;
}
开发者ID:DevinLow,项目名称:Reading-and-comprehense-redis-2.9.11,代码行数:28,代码来源:sds.c
示例2: sdscpylen
/* copy len elements of t to s*/
sds sdscpylen(sds s, char *t, size_t len) {
/* @sh -> struct which contains s */
struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
/* @totlen -> total length of sh */
size_t totlen = sh->free+sh->len;
/* doesn't have enough space */
if (totlen < len) {
/* make room for the new string */
s = sdsMakeRoomFor(s,len-totlen);
/* failed to make more room */
if (s == NULL) return NULL;
/*update sh and totlen */
sh = (void*) (s-(sizeof(struct sdshdr)));
totlen = sh->free+sh->len;
}
/* copy the contents */
memcpy(s, t, len);
/* add '\0' to the end of the string */
s[len] = '\0';
/* update sh->len and sh->free */
sh->len = len;
sh->free = totlen-len;
/* return s */
return s;
}
开发者ID:klion26,项目名称:redis-1.0-annotation,代码行数:27,代码来源:sds.c
示例3: pub_ev_handler
static void pub_ev_handler(evutil_socket_t fd, short event, void *args)
{
if (!(event & EV_READ)) {
srv_log(LOG_WARN, "publisher [fd %d] invalid event: %d", event);
return;
}
pub_client *c = (pub_client *) args;
c->read_buf = sdsMakeRoomFor(c->read_buf, PUB_READ_BUF_LEN);
size_t cur_len = sdslen(c->read_buf);
int nread = read(fd, c->read_buf + cur_len, PUB_READ_BUF_LEN);
if (nread == -1) {
if (errno == EAGAIN || errno == EINTR) {
/* temporary unavailable */
} else {
srv_log(LOG_ERROR, "[fd %d] failed to read from publisher: %s",
fd, strerror(errno));
pub_cli_release(c);
}
} else if (nread == 0) {
srv_log(LOG_INFO, "[fd %d] publisher detached", fd);
pub_cli_release(c);
} else {
/*
chunk[n] = '\0';
srv_log(LOG_INFO, "[fd %d] publisher send: %s", fd, chunk);
write(fd, "hello", 5);
*/
/* data process */
sdsIncrLen(c->read_buf, nread);
process_pub_read_buf(c);
/*process_publish(c, chunk, nread);*/
}
}
开发者ID:amyangfei,项目名称:mini-pubsub-broker,代码行数:35,代码来源:event.c
示例4: sub_ev_handler
void sub_ev_handler(evutil_socket_t fd, short event, void *args)
{
sub_client *c = (sub_client *) args;
if (event & EV_READ) {
c->read_buf = sdsMakeRoomFor(c->read_buf, SUB_READ_BUF_LEN);
size_t cur_len = sdslen(c->read_buf);
int n = read(fd, c->read_buf + cur_len, SUB_READ_BUF_LEN);
if (n == -1) {
if (errno == EAGAIN || errno == EINTR) {
/* temporary unavailable */
return;
} else {
srv_log(LOG_ERROR, "[fd %d] failed to read from sublisher: %s",
fd, strerror(errno));
sub_cli_release(c);
return;
}
} else if (n == 0) {
srv_log(LOG_INFO, "[fd %d] sublisher detached", fd);
sub_cli_release(c);
return;
} else {
sdsIncrLen(c->read_buf, n);
}
process_sub_read_buf(c);
} else if (event & EV_WRITE) {
send_reply_to_subcli(c);
}
}
开发者ID:amyangfei,项目名称:mini-pubsub-broker,代码行数:30,代码来源:event.c
示例5: sdscatlen
/* Append the specified binary-safe string pointed by 't' of 'len' bytes to the
* end of the specified sds string 's'.
*
* After the call, the passed sds string is no longer valid and all the
* references must be substituted with the new pointer returned by the call. */
sds sdscatlen(sds s, const void *t, size_t len) {
struct sdshdr *sh;
// 原有字符串长度
size_t curlen = sdslen(s);
// 扩展 sds 空间
// T = O(N)
s = sdsMakeRoomFor(s,len);
// 内存不足?直接返回
if (s == NULL) return NULL;
// 复制 t 中的内容到字符串后部
// T = O(N)
sh = (void*) (s-(sizeof(struct sdshdr)));
memcpy(s+curlen, t, len);
// 更新属性
sh->len = curlen+len;
sh->free = sh->free-len;
// 添加新结尾符号
s[curlen+len] = '\0';
// 返回新 sds
return s;
}
开发者ID:DevinLow,项目名称:Reading-and-comprehense-redis-2.9.11,代码行数:34,代码来源:sds.c
示例6: sdscpylen
// 将给定的 C 字符串复制到 SDS 里面, 覆盖 SDS 原有的字符串。 O(N) , N 为被复制 C 字符串的长度。
sds sdscpylen(sds s, const char *t, size_t len) {
struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
// sds 现有 buf 的长度
size_t totlen = sh->free+sh->len;
// 如果 s 的 buf 长度不满足 len ,那么扩展它
if (totlen < len) {
// T = O(N)
s = sdsMakeRoomFor(s,len-sh->len);
if (s == NULL) return NULL;
sh = (void*) (s-(sizeof(struct sdshdr)));
totlen = sh->free+sh->len;
}
// 复制内容
// T = O(N)
memcpy(s, t, len);
// 添加终结符号
s[len] = '\0';
// 更新属性
sh->len = len;
sh->free = totlen-len;
// 返回新的 sds
return s;
}
开发者ID:DevinLow,项目名称:Reading-and-comprehense-redis-2.9.11,代码行数:31,代码来源:sds.c
示例7: sdscatlen
/* Append the specified binary-safe string pointed by 't' of 'len' bytes to the
* end of the specified sds string 's'.
*
* After the call, the passed sds string is no longer valid and all the
* references must be substituted with the new pointer returned by the call. */
sds sdscatlen(sds s, const void *t, size_t len) {
size_t curlen = sdslen(s);
s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
memcpy(s+curlen, t, len);
sdssetlen(s, curlen+len);
s[curlen+len] = '\0';
return s;
}
开发者ID:Ardnived,项目名称:flarum-chat-server,代码行数:15,代码来源:sds.c
示例8: sdscpylen
/* Destructively modify the sds string 's' to hold the specified binary
* safe string pointed by 't' of length 'len' bytes. */
sds sdscpylen(sds s, const char *t, size_t len) {
if (sdsalloc(s) < len) {
s = sdsMakeRoomFor(s,len-sdslen(s));
if (s == NULL) return NULL;
}
memcpy(s, t, len);
s[len] = '\0';
sdssetlen(s, len);
return s;
}
开发者ID:Ardnived,项目名称:flarum-chat-server,代码行数:12,代码来源:sds.c
示例9: readQueryFromClient
void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
client *c = (client*) privdata;
int nread, readlen;
size_t qblen;
UNUSED(el);
UNUSED(mask);
readlen = PROTO_IOBUF_LEN;
/* If this is a multi bulk request, and we are processing a bulk reply
* that is large enough, try to maximize the probability that the query
* buffer contains exactly the SDS string representing the object, even
* at the risk of requiring more read(2) calls. This way the function
* processMultiBulkBuffer() can avoid copying buffers to create the
* Redis Object representing the argument. */
if (c->reqtype == PROTO_REQ_MULTIBULK && c->multibulklen && c->bulklen != -1
&& c->bulklen >= PROTO_MBULK_BIG_ARG)
{
int remaining = (unsigned)(c->bulklen+2)-sdslen(c->querybuf);
if (remaining < readlen) readlen = remaining;
}
qblen = sdslen(c->querybuf);
if (c->querybuf_peak < qblen) c->querybuf_peak = qblen;
c->querybuf = sdsMakeRoomFor(c->querybuf, readlen);
nread = read(fd, c->querybuf+qblen, readlen);
if (nread == -1) {
if (errno == EAGAIN) {
return;
} else {
Log(LL_VERBOSE, "Reading from client: %s",strerror(errno));
freeClient(c);
return;
}
} else if (nread == 0) {
Log(LL_VERBOSE, "Client closed connection");
freeClient(c);
return;
}
sdsIncrLen(c->querybuf,nread);
c->lastinteraction = server.unixtime;
server.stat_net_input_bytes += nread;
if (sdslen(c->querybuf) > server.client_max_querybuf_len) {
sds ci = catClientInfoString(sdsempty(),c), bytes = sdsempty();
bytes = sdscatrepr(bytes,c->querybuf,64);
Log(LL_WARNING,"Closing client that reached max query buffer length: %s (qbuf initial bytes: %s)", ci, bytes);
sdsfree(ci);
sdsfree(bytes);
freeClient(c);
return;
}
processInputBuffer(c);
}
开发者ID:icoulter,项目名称:workspace_tubii,代码行数:55,代码来源:networking.c
示例10: sdscatlen
sds sdscatlen(sds s, const void* t, size_t len) {
size_t curlen = sdslen(s);
s = sdsMakeRoomFor(s, len);
if (s == NULL) return NULL;
struct sdshdr *sh = (void*)(s - (sizeof(struct sdshdr)));
memcpy(s + curlen, t, len);
sh->len = curlen + len;
sh->free = sh->free - len;
s[curlen + len] = '\0';
return s;
}
开发者ID:Git-WillWang,项目名称:myRedis,代码行数:11,代码来源:sds.c
示例11: sdsgrowzero
/* Grow the sds to have the specified length. Bytes that were not part of
* the original length of the sds will be set to zero.
*
* if the specified length is smaller than the current length, no operation
* is performed. */
sds sdsgrowzero(sds s, size_t len) {
size_t curlen = sdslen(s);
if (len <= curlen) return s;
s = sdsMakeRoomFor(s,len-curlen);
if (s == NULL) return NULL;
/* Make sure added region doesn't contain garbage */
memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */
sdssetlen(s, len);
return s;
}
开发者ID:Ardnived,项目名称:flarum-chat-server,代码行数:17,代码来源:sds.c
示例12: sdscatlen
/* Append the specified binary-safe string pointed by 't' of 'len' bytes to the
* end of the specified sds string 's'.
*
* After the call, the passed sds string is no longer valid and all the
* references must be substituted with the new pointer returned by the call. */
sds sdscatlen(sds s, const void *t, size_t len) {
sdshdr *sh;
size_t curlen = sdslen(s);
s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
sh = sds_start(s);
memcpy(s+curlen, t, len);
sh->len = curlen+len;
sh->free = sh->free-len;
s[curlen+len] = '\0';
return s;
}
开发者ID:asanosoyokaze,项目名称:sds,代码行数:18,代码来源:sds.c
示例13: sdsgrowzero
sds sdsgrowzero(sds s, size_t len) {
struct sdshdr *sh = (void*)(s - (sizeof(struct sdshdr)));
size_t totlen, curlen = sh->len;
if (len <= curlen) return s;
s = sdsMakeRoomFor(s, len - curlen);
if (s == NULL) return NULL;
sh = (void*)(s - (sizeof(struct sdshdr)));
memset(s + curlen, 0, (len - curlen + 1));
totlen = sh->len + sh->free;
sh->len = len;
sh->free = totlen - sh->len;
return s;
}
开发者ID:Git-WillWang,项目名称:myRedis,代码行数:13,代码来源:sds.c
示例14: sdscpylen
sds sdscpylen(sds s, const char *t, size_t len) {
struct sdshdr *sh = (void*)(s - (sizeof(struct sdshdr)));
size_t totlen = sh->free + sh->len;
if (totlen < len) {
s = sdsMakeRoomFor(s, len - sh->len);
if (s == NULL) return NULL;
sh = (void*)(s - (sizeof(struct sdshdr)));
totlen = sh->free + sh->len;
}
memcpy(s, t, len);
s[len] = len;
sh->free = totlen - len;
return s;
}
开发者ID:Git-WillWang,项目名称:myRedis,代码行数:14,代码来源:sds.c
示例15: readQueryFromClient
void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
vuiClient *c = (vuiClient *) privdata;
int nread, readlen;
size_t qblen;
/* If this is a multi bulk request, and we are processing a bulk reply
* that is large enough, try to maximize the probability that the query
* buffer contains exactly the SDS string representing the object, even
* at the risk of requiring more read(2) calls. This way the function
* processMultiBulkBuffer() can avoid copying buffers to create the
* Redis Object representing the argument. */
if (c->prot.waiting)
{
readlen = c->prot.waiting;
}
else
{
readlen = 1024 * 2;
}
qblen = sdslen(c->querybuf);
c->querybuf = sdsMakeRoomFor(c->querybuf, readlen);
nread = read(fd, c->querybuf+qblen, readlen);
if (nread == -1) {
if (errno == EAGAIN) {
nread = 0;
} else {
LogInfo("Reading from client: %s",strerror(errno));
freeClient(c);
return;
}
} else if (nread == 0) {
LogInfo("Client closed connection");
freeClient(c);
return;
}
if (nread) {
sdsIncrLen(c->querybuf,nread);
}
//TODO
if (sdslen(c->querybuf) > 1024 * 1024) {
LogWarn("Closing client that reached max query buffer length");
sdsclear(c->querybuf);
freeClient(c);
return;
}
processInputBuffer(c);
}
开发者ID:ChellsChen,项目名称:wind,代码行数:49,代码来源:client.c
示例16: getAllClientsInfoString
sds getAllClientsInfoString(void) {
listNode *ln;
listIter li;
client *client;
sds o = sdsempty();
o = sdsMakeRoomFor(o,200*listLength(server.clients));
listRewind(server.clients,&li);
while ((ln = listNext(&li)) != NULL) {
client = listNodeValue(ln);
o = catClientInfoString(o,client);
o = sdscatlen(o,"\n",1);
}
return o;
}
开发者ID:icoulter,项目名称:workspace_tubii,代码行数:15,代码来源:networking.c
示例17: sdsgrowzero
/* Grow the sds to have the specified length. Bytes that were not part of
* the original length of the sds will be set to zero.
*
* if the specified length is smaller than the current length, no operation
* is performed. */
sds sdsgrowzero(sds s, size_t len) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
size_t totlen, curlen = sh->len;
if (len <= curlen) return s;
s = sdsMakeRoomFor(s,len-curlen);
if (s == NULL) return NULL;
/* Make sure added region doesn't contain garbage */
sh = (void*)(s-(sizeof(struct sdshdr)));
memset(s+curlen,0,(len-curlen+1)); /* also set trailing \0 byte */
totlen = sh->len+sh->free;
sh->len = (int)len;
sh->free = (int)(totlen-sh->len);
return s;
}
开发者ID:freb,项目名称:rules,代码行数:21,代码来源:sds.c
示例18: sdscatlen
/* 以t作为新添加的len长度buf的数据,实现追加操作 */
sds sdscatlen(sds s, const void *t, size_t len) {
struct sdshdr *sh;
size_t curlen = sdslen(s);
//为原字符串扩展len长度空间
s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
sh = (void*) (s-(sizeof(struct sdshdr)));
//多余的数据以t作初始化
memcpy(s+curlen, t, len);
//更改相应的len,free值
sh->len = curlen+len;
sh->free = sh->free-len;
s[curlen+len] = '\0';
return s;
}
开发者ID:AplayER,项目名称:Redis-Code,代码行数:17,代码来源:sds.c
示例19: sdscatlen
/* concate len elements of t at the end of s */
sds sdscatlen(sds s, void *t, size_t len) {
/* @sh -> struct contains s */
struct sdshdr *sh;
size_t curlen = sdslen(s);
/* make enough room */
s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
sh = (void*) (s-(sizeof(struct sdshdr)));
/* copy the len elements after s */
memcpy(s+curlen, t, len);
/* update sh->len and sh->free */
sh->len = curlen+len;
sh->free = sh->free-len;
/* add '\0' at the end of the string */
s[curlen+len] = '\0';
return s;
}
开发者ID:klion26,项目名称:redis-1.0-annotation,代码行数:18,代码来源:sds.c
示例20: sdscpylen
/* Destructively modify the sds string 's' to hold the specified binary
* safe string pointed by 't' of length 'len' bytes. */
sds sdscpylen(sds s, const char *t, size_t len) {
if (s == NULL) return NULL;
sdshdr *sh = sds_start(s);
size_t totlen = sh->free+sh->len;
if (totlen < len) {
s = sdsMakeRoomFor(s,len-sh->len);
if (s == NULL) return NULL;
sh = sds_start(s);
totlen = sh->free+sh->len;
}
memcpy(s, t, len);
s[len] = '\0';
sh->len = len;
sh->free = totlen-len;
return s;
}
开发者ID:asanosoyokaze,项目名称:sds,代码行数:20,代码来源:sds.c
注:本文中的sdsMakeRoomFor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论