Lines Matching defs:pufbuf
105 struct puffs_framebuf *pufbuf;
107 pufbuf = malloc(sizeof(struct puffs_framebuf));
108 if (pufbuf == NULL)
110 memset(pufbuf, 0, sizeof(struct puffs_framebuf));
112 pufbuf->buf = malloc(PUFBUF_INCRALLOC);
113 if (pufbuf->buf == NULL) {
114 free(pufbuf);
117 pufbuf->len = PUFBUF_INCRALLOC;
119 puffs_framebuf_recycle(pufbuf);
120 return pufbuf;
124 puffs_framebuf_destroy(struct puffs_framebuf *pufbuf)
127 assert((pufbuf->istat & ISTAT_NODESTROY) == 0);
129 free(pufbuf->buf);
130 free(pufbuf);
134 puffs_framebuf_recycle(struct puffs_framebuf *pufbuf)
137 assert((pufbuf->istat & ISTAT_NODESTROY) == 0);
139 pufbuf->offset = 0;
140 pufbuf->maxoff = 0;
141 pufbuf->istat = 0;
145 reservespace(struct puffs_framebuf *pufbuf, size_t off, size_t wantsize)
150 if (off <= pufbuf->len && pufbuf->len - off >= wantsize)
154 pufbuf->len + incr < off + wantsize;
158 nd = realloc(pufbuf->buf, pufbuf->len + incr);
162 pufbuf->buf = nd;
163 pufbuf->len += incr;
195 puffs_framebuf_reserve_space(struct puffs_framebuf *pufbuf, size_t wantsize)
198 return reservespace(pufbuf, pufbuf->offset, wantsize);
202 puffs_framebuf_putdata(struct puffs_framebuf *pufbuf,
206 if (PUFBUF_REMAIN(pufbuf) < dlen)
207 if (puffs_framebuf_reserve_space(pufbuf, dlen) == -1)
210 memcpy(pufbuf->buf + pufbuf->offset, data, dlen);
211 pufbuf->offset += dlen;
213 if (pufbuf->offset > pufbuf->maxoff)
214 pufbuf->maxoff = pufbuf->offset;
220 puffs_framebuf_putdata_atoff(struct puffs_framebuf *pufbuf, size_t offset,
224 if (reservespace(pufbuf, offset, dlen) == -1)
227 memcpy(pufbuf->buf + offset, data, dlen);
229 if (offset + dlen > pufbuf->maxoff)
230 pufbuf->maxoff = offset + dlen;
236 puffs_framebuf_getdata(struct puffs_framebuf *pufbuf, void *data, size_t dlen)
239 if (pufbuf->maxoff < pufbuf->offset + dlen) {
244 memcpy(data, pufbuf->buf + pufbuf->offset, dlen);
245 pufbuf->offset += dlen;
251 puffs_framebuf_getdata_atoff(struct puffs_framebuf *pufbuf, size_t offset,
255 if (pufbuf->maxoff < offset + dlen) {
260 memcpy(data, pufbuf->buf + offset, dlen);
265 puffs_framebuf_telloff(struct puffs_framebuf *pufbuf)
268 return pufbuf->offset;
272 puffs_framebuf_tellsize(struct puffs_framebuf *pufbuf)
275 return pufbuf->maxoff;
279 puffs_framebuf_remaining(struct puffs_framebuf *pufbuf)
282 return puffs_framebuf_tellsize(pufbuf) - puffs_framebuf_telloff(pufbuf);
286 puffs_framebuf_seekset(struct puffs_framebuf *pufbuf, size_t newoff)
289 if (reservespace(pufbuf, newoff, 0) == -1)
292 pufbuf->offset = newoff;
297 puffs_framebuf_getwindow(struct puffs_framebuf *pufbuf, size_t winoff,
308 if (reservespace(pufbuf, winoff, winlen) == -1)
311 *data = pufbuf->buf + winoff;
312 if (pufbuf->maxoff < winoff + winlen)
313 pufbuf->maxoff = winoff + winlen;
319 puffs__framebuf_getdataptr(struct puffs_framebuf *pufbuf)
322 return pufbuf->buf;
326 errnotify(struct puffs_usermount *pu, struct puffs_framebuf *pufbuf, int error)
329 pufbuf->rv = error;
330 if (pufbuf->pcc) {
331 puffs__goto(pufbuf->pcc);
332 } else if (pufbuf->fcb) {
333 pufbuf->istat &= ~ISTAT_NODESTROY;
334 pufbuf->fcb(pu, pufbuf, pufbuf->fcb_arg, error);
336 pufbuf->istat &= ~ISTAT_NODESTROY;
337 puffs_framebuf_destroy(pufbuf);
356 struct puffs_framebuf *pufbuf, int flags)
370 pufbuf->pcc = pcc;
371 pufbuf->fcb = NULL;
372 pufbuf->fcb_arg = NULL;
374 pufbuf->offset = 0;
375 pufbuf->istat |= ISTAT_NODESTROY;
378 TAILQ_INSERT_HEAD(&fio->snd_qing, pufbuf, pfb_entries);
380 TAILQ_INSERT_TAIL(&fio->snd_qing, pufbuf, pfb_entries);
383 if (pufbuf->rv) {
384 pufbuf->istat &= ~ISTAT_NODESTROY;
385 errno = pufbuf->rv;
394 struct puffs_framebuf *pufbuf, puffs_framev_cb fcb, void *arg,
402 pufbuf->pcc = NULL;
403 pufbuf->fcb = fcb;
404 pufbuf->fcb_arg = arg;
406 pufbuf->offset = 0;
407 pufbuf->istat |= ISTAT_NODESTROY;
410 TAILQ_INSERT_HEAD(&fio->snd_qing, pufbuf, pfb_entries);
412 TAILQ_INSERT_TAIL(&fio->snd_qing, pufbuf, pfb_entries);
419 struct puffs_framebuf *pufbuf, int reply, int flags)
423 assert((pufbuf->istat & ISTAT_INTERNAL) == 0);
427 pufbuf->pcc = NULL;
428 pufbuf->fcb = NULL;
429 pufbuf->fcb_arg = NULL;
431 pufbuf->offset = 0;
432 pufbuf->istat |= ISTAT_NODESTROY;
434 pufbuf->istat |= ISTAT_NOREPLY;
437 TAILQ_INSERT_HEAD(&fio->snd_qing, pufbuf, pfb_entries);
439 TAILQ_INSERT_TAIL(&fio->snd_qing, pufbuf, pfb_entries);
447 struct puffs_framebuf *pufbuf, int flags /* used in the future */)
452 assert((pufbuf->istat & ISTAT_INTERNAL) == 0);
462 fio->cur_in = pufbuf;
464 pufbuf->pcc = pcc;
465 pufbuf->fcb = NULL;
466 pufbuf->fcb_arg = NULL;
468 pufbuf->offset = 0;
469 pufbuf->istat |= ISTAT_NODESTROY | ISTAT_DIRECT;
472 pufbuf->istat &= ~ISTAT_NODESTROY; /* XXX: not the right place */
473 if (pufbuf->rv) {
474 errno = pufbuf->rv;
483 struct puffs_framebuf *pufbuf, int flags)
488 assert((pufbuf->istat & ISTAT_INTERNAL) == 0);
495 pufbuf->pcc = pcc;
496 pufbuf->fcb = NULL;
497 pufbuf->fcb_arg = NULL;
499 pufbuf->offset = 0;
500 pufbuf->istat |= ISTAT_NODESTROY | ISTAT_DIRECT;
502 TAILQ_INSERT_TAIL(&fio->snd_qing, pufbuf, pfb_entries);
505 if (pufbuf->rv) {
506 pufbuf->istat &= ~ISTAT_NODESTROY;
507 errno = pufbuf->rv;
515 puffs_framev_framebuf_ccpromote(struct puffs_framebuf *pufbuf,
519 if ((pufbuf->istat & ISTAT_ONQUEUE) == 0) {
524 pufbuf->pcc = pcc;
525 pufbuf->fcb = NULL;
526 pufbuf->fcb_arg = NULL;
527 pufbuf->istat &= ~ISTAT_NOREPLY;
661 struct puffs_framebuf *pufbuf, *appbuf;
665 if ((pufbuf = fio->cur_in) == NULL) {
666 pufbuf = puffs_framebuf_make();
667 if (pufbuf == NULL)
669 pufbuf->istat |= ISTAT_INTERNAL;
670 fio->cur_in = pufbuf;
674 rv = fctrl->rfb(pu, pufbuf, fio->io_fd, &complete);
689 if ((pufbuf->istat & ISTAT_DIRECT) == 0) {
690 appbuf = findbuf(pu, fctrl, fio, pufbuf);
698 pufbuf->istat &= ~ISTAT_INTERNAL;
699 fctrl->gotfb(pu, pufbuf);
701 puffs_framebuf_destroy(pufbuf);
706 puffs__framebuf_moveinfo(pufbuf, appbuf);
707 puffs_framebuf_destroy(pufbuf);
709 appbuf = pufbuf;
729 struct puffs_framebuf *pufbuf;
735 for (pufbuf = TAILQ_FIRST(&fio->snd_qing), done = 0;
736 pufbuf && (fio->stat & FIO_DEAD) == 0 && fio->stat & FIO_ENABLE_W;
737 pufbuf = TAILQ_FIRST(&fio->snd_qing)) {
739 rv = fctrl->wfb(pu, pufbuf, fio->io_fd, &complete);
752 TAILQ_REMOVE(&fio->snd_qing, pufbuf, pfb_entries);
756 errnotify(pu, pufbuf, ENXIO);
758 } else if ((pufbuf->istat & ISTAT_DIRECT)) {
759 pufbuf->istat &= ~ISTAT_NODESTROY;
761 puffs__cc_cont(pufbuf->pcc);
762 } else if ((pufbuf->istat & ISTAT_NOREPLY) == 0) {
763 TAILQ_INSERT_TAIL(&fio->res_qing, pufbuf,
766 pufbuf->istat &= ~ISTAT_NODESTROY;
767 puffs_framebuf_destroy(pufbuf);
926 struct puffs_framebuf *pufbuf;
943 while ((pufbuf = TAILQ_FIRST(&fio->res_qing)) != NULL) {
944 TAILQ_REMOVE(&fio->res_qing, pufbuf, pfb_entries);
945 errnotify(pu, pufbuf, error);
963 struct puffs_framebuf *pufbuf;
971 while ((pufbuf = TAILQ_FIRST(&fio->snd_qing)) != NULL) {
972 TAILQ_REMOVE(&fio->snd_qing, pufbuf, pfb_entries);
973 errnotify(pu, pufbuf, error);