struct ccn_charbuf* CcnbOR_read(CcnbOR self) { if (NBS_error(self->nbs)) { self->error = true; return NULL; } uint8_t* buf = (uint8_t*)malloc(2048); size_t readSize = NBS_read(self->nbs, buf, 2048, NULL); if (readSize == 0) { free(buf); return NULL; } ssize_t consumeSize = ccn_skeleton_decode(self->rd, buf, readSize); if (self->rd->state < 0) self->error = true; else ccn_charbuf_append(self->cbuf, buf, consumeSize); if (consumeSize < readSize) NBS_pushback(self->nbs, buf, consumeSize, readSize - consumeSize, NULL); else free(buf); if (CCN_FINAL_DSTATE(self->rd->state)) { struct ccn_charbuf* cbuf = self->cbuf; self->cbuf = ccn_charbuf_create(); CcnbOR_clear(self); return cbuf; } return NULL; }
void LMD_demux(LMD self) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; LMDRec rec; SockAddr addr = SockAddr_ctor(); struct ccn_charbuf* hashkey; void* buf = malloc(self->mtu); size_t len; hashtb_start(self->demux, hte); while ((len = NBS_read(self->nbs, buf, self->mtu, addr)) > 0) { hashkey = SockAddr_hashkey(addr); htres = hashtb_seek(hte, hashkey->buf, hashkey->length, 0); rec = NULL; if (htres == HT_OLD_ENTRY) { rec = *((LMDRec*)hte->data); } else { rec = self->fallback; if (htres == HT_NEW_ENTRY) hashtb_delete(hte); } if (rec != NULL) { LMDRec_deliver(rec, buf, len, addr); buf = malloc(self->mtu); } } free(buf); hashtb_end(hte); SockAddr_dtor(addr); }