Fix a weirdosity in the framebuf gotfb interface: hand buffer

ownership to the called routine instead of keeping it.  This means
that callees must now destroy the buffer once they are done with it.
This commit is contained in:
pooka 2008-01-29 10:07:29 +00:00
parent 64c4bfc90e
commit be5ed87c1e
4 changed files with 25 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: framebuf.c,v 1.27 2008/01/28 18:35:50 pooka Exp $ */
/* $NetBSD: framebuf.c,v 1.28 2008/01/29 10:07:29 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: framebuf.c,v 1.27 2008/01/28 18:35:50 pooka Exp $");
__RCSID("$NetBSD: framebuf.c,v 1.28 2008/01/29 10:07:29 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -359,7 +359,7 @@ puffs_framev_enqueue_cc(struct puffs_cc *pcc, int fd,
struct puffs_fctrl_io *fio;
/*
* Technically we shouldn't allow this is RDGONE, but it's
* Technically we shouldn't allow this if RDGONE, but it's
* difficult to trap write close without allowing writes.
* And besides, there's probably a disconnect sequence in
* the protocol, so unexpectedly getting a closed fd is
@ -420,6 +420,8 @@ puffs_framev_enqueue_justsend(struct puffs_usermount *pu, int fd,
{
struct puffs_fctrl_io *fio;
assert((pufbuf->istat & ISTAT_INTERNAL) == 0);
GETFIO(fd);
pufbuf->pcc = NULL;
@ -447,6 +449,8 @@ puffs_framev_enqueue_directreceive(struct puffs_cc *pcc, int fd,
struct puffs_usermount *pu = pcc->pcc_pu;
struct puffs_fctrl_io *fio;
assert((pufbuf->istat & ISTAT_INTERNAL) == 0);
fio = getfiobyfd(pu, fd);
if (fio == NULL) {
errno = EINVAL;
@ -481,6 +485,8 @@ puffs_framev_enqueue_directsend(struct puffs_cc *pcc, int fd,
struct puffs_usermount *pu = pcc->pcc_pu;
struct puffs_fctrl_io *fio;
assert((pufbuf->istat & ISTAT_INTERNAL) == 0);
if (flags & PUFFS_FBQUEUE_URGENT)
abort(); /* EOPNOTSUPP for now */
@ -695,12 +701,12 @@ puffs__framev_input(struct puffs_usermount *pu, struct puffs_framectrl *fctrl,
* gotfb, give frame to that. Otherwise drop it.
*/
if (appbuf == NULL) {
if (fctrl->gotfb)
if (fctrl->gotfb) {
pufbuf->istat &= ~ISTAT_INTERNAL;
fctrl->gotfb(pu, pufbuf);
/* XXX: ugly */
pufbuf->istat &= ~ISTAT_NODESTROY;
puffs_framebuf_destroy(pufbuf);
} else {
puffs_framebuf_destroy(pufbuf);
}
continue;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs.h,v 1.106 2008/01/28 18:42:09 pooka Exp $ */
/* $NetBSD: puffs.h,v 1.107 2008/01/29 10:07:29 pooka Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
@ -358,7 +358,7 @@ enum {
PUFFSOP_PROTOS(puffs_null) /* XXX */
#define PUFFS_DEVEL_LIBVERSION 33
#define PUFFS_DEVEL_LIBVERSION 34
#define puffs_init(a,b,c,d,e) \
_puffs_init(PUFFS_DEVEL_LIBVERSION,a,b,c,d,e)

View File

@ -1,4 +1,4 @@
.\" $NetBSD: puffs_framebuf.3,v 1.21 2007/12/08 10:56:06 wiz Exp $
.\" $NetBSD: puffs_framebuf.3,v 1.22 2008/01/29 10:07:30 pooka Exp $
.\"
.\" Copyright (c) 2007 Antti Kantee. All rights reserved.
.\"
@ -509,7 +509,10 @@ request.
May not block.
.It Fn puffs_framev_gotframe_fn pu pufbuf
Called when no outstanding request matches an incoming frame.
The incoming buffer must not be destroyed.
The ownership of
.Ar pufbuf
is transferred to the called function and must be destroyed once
processing is over.
May not block.
.It Fn puffs_framev_fdnotify_fn pu fd what
Is called when the read or write side of the file descriptor

View File

@ -1,4 +1,4 @@
/* $NetBSD: requests.c,v 1.21 2008/01/28 18:35:51 pooka Exp $ */
/* $NetBSD: requests.c,v 1.22 2008/01/29 10:07:30 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: requests.c,v 1.21 2008/01/28 18:35:51 pooka Exp $");
__RCSID("$NetBSD: requests.c,v 1.22 2008/01/29 10:07:30 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -235,15 +235,7 @@ puffs__fsframe_cmp(struct puffs_usermount *pu,
void
puffs__fsframe_gotframe(struct puffs_usermount *pu, struct puffs_framebuf *pb)
{
struct puffs_framebuf *newpb;
if ((newpb = puffs_framebuf_make()) == NULL)
abort();
/* XXX: optimize */
puffs__framebuf_moveinfo(pb, newpb);
puffs_framebuf_seekset(newpb, 0);
if (puffs_framebuf_reserve_space(newpb, PUFFS_MSG_MAXSIZE) == -1)
abort();
puffs__ml_dispatch(pu, newpb);
puffs_framebuf_seekset(pb, 0);
puffs__ml_dispatch(pu, pb);
}