Populate the length object and try gluing it to the next chunk. */
| 769 | |
| 770 | /* Populate the length object and try gluing it to the next chunk. */ |
| 771 | void setDeferredAggregateLen(client *c, void *node, long length, char prefix) { |
| 772 | serverAssert(length >= 0); |
| 773 | |
| 774 | if (FCorrectThread(c)) { |
| 775 | /* Abort when *node is NULL: when the client should not accept writes |
| 776 | * we return NULL in addReplyDeferredLen() */ |
| 777 | if (node == NULL) return; |
| 778 | char lenstr[128]; |
| 779 | size_t lenstr_len = snprintf(lenstr, sizeof(lenstr), "%c%ld\r\n", prefix, length); |
| 780 | setDeferredReply(c, node, lenstr, lenstr_len); |
| 781 | } else { |
| 782 | char lenstr[128]; |
| 783 | int lenstr_len = snprintf(lenstr, sizeof(lenstr), "%c%ld\r\n", prefix, length); |
| 784 | |
| 785 | size_t idxSplice = (size_t)node; |
| 786 | serverAssert(idxSplice <= c->replyAsync->used); |
| 787 | if (c->replyAsync->size < (c->replyAsync->used + lenstr_len)) |
| 788 | { |
| 789 | int newsize = std::max(c->replyAsync->used + lenstr_len, c->replyAsync->size*2); |
| 790 | clientReplyBlock *replyNew = (clientReplyBlock*)zmalloc(sizeof(clientReplyBlock) + newsize); |
| 791 | replyNew->size = zmalloc_usable_size(replyNew) - sizeof(clientReplyBlock); |
| 792 | replyNew->used = c->replyAsync->used; |
| 793 | memcpy(replyNew->buf(), c->replyAsync->buf(), c->replyAsync->used); |
| 794 | zfree(c->replyAsync); |
| 795 | c->replyAsync = replyNew; |
| 796 | } |
| 797 | |
| 798 | memmove(c->replyAsync->buf() + idxSplice + lenstr_len, c->replyAsync->buf() + idxSplice, c->replyAsync->used - idxSplice); |
| 799 | memcpy(c->replyAsync->buf() + idxSplice, lenstr, lenstr_len); |
| 800 | c->replyAsync->used += lenstr_len; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | void setDeferredArrayLen(client *c, void *node, long length) { |
| 805 | setDeferredAggregateLen(c,node,length,'*'); |
no test coverage detected