Lines Matching refs: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;
663 struct puffs_framebuf *pufbuf, *appbuf;
667 if ((pufbuf = fio->cur_in) == NULL) {
668 pufbuf = puffs_framebuf_make();
669 if (pufbuf == NULL)
671 pufbuf->istat |= ISTAT_INTERNAL;
672 fio->cur_in = pufbuf;
676 rv = fctrl->rfb(pu, pufbuf, fio->io_fd, &complete);
691 if ((pufbuf->istat & ISTAT_DIRECT) == 0) {
692 appbuf = findbuf(pu, fctrl, fio, pufbuf);
700 pufbuf->istat &= ~ISTAT_INTERNAL;
701 fctrl->gotfb(pu, pufbuf);
703 puffs_framebuf_destroy(pufbuf);
708 puffs__framebuf_moveinfo(pufbuf, appbuf);
709 puffs_framebuf_destroy(pufbuf);
711 appbuf = pufbuf;
731 struct puffs_framebuf *pufbuf;
737 for (pufbuf = TAILQ_FIRST(&fio->snd_qing), done = 0;
738 pufbuf && (fio->stat & FIO_DEAD) == 0 && fio->stat & FIO_ENABLE_W;
739 pufbuf = TAILQ_FIRST(&fio->snd_qing)) {
741 rv = fctrl->wfb(pu, pufbuf, fio->io_fd, &complete);
754 TAILQ_REMOVE(&fio->snd_qing, pufbuf, pfb_entries);
758 errnotify(pu, pufbuf, ENXIO);
760 } else if ((pufbuf->istat & ISTAT_DIRECT)) {
761 pufbuf->istat &= ~ISTAT_NODESTROY;
763 puffs__cc_cont(pufbuf->pcc);
764 } else if ((pufbuf->istat & ISTAT_NOREPLY) == 0) {
765 TAILQ_INSERT_TAIL(&fio->res_qing, pufbuf,
768 pufbuf->istat &= ~ISTAT_NODESTROY;
769 puffs_framebuf_destroy(pufbuf);
922 struct puffs_framebuf *pufbuf;
939 while ((pufbuf = TAILQ_FIRST(&fio->res_qing)) != NULL) {
940 TAILQ_REMOVE(&fio->res_qing, pufbuf, pfb_entries);
941 errnotify(pu, pufbuf, error);
959 struct puffs_framebuf *pufbuf;
967 while ((pufbuf = TAILQ_FIRST(&fio->snd_qing)) != NULL) {
968 TAILQ_REMOVE(&fio->snd_qing, pufbuf, pfb_entries);
969 errnotify(pu, pufbuf, error);