Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 03 Dec 1995 11:15:31 -0500
From:      Robert Withrow <witr@rwwa.com>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        freebsd-hackers@freebsd.org, witr@rwwa.com
Subject:   Re: Proper way to determine non-blocking status... 
Message-ID:  <199512031615.LAA13131@spooky.rwwa.com>
In-Reply-To: Your message of "Sun, 03 Dec 1995 14:58:40 %2B1100." <199512030358.OAA07217@godzilla.zeta.org.au> 

next in thread | previous in thread | raw e-mail | index | archive | help
Do you mind if I pepper you with some more questions?

1) Is there any guidance on what priority pass to tsleep?

2) Would I be correct in assuming that IPL will be the
same *after* tsleep returns as it was *before*.  (I'm
already pretty sure of that, reading the code.  It makes
sense anyway.)

3) Is there anyway short of using timeout() to hook
into the clock interrupt (like xxpoll() in SYSV)?

4) I'm porting a streams driver to FreeBSD.  It isn't
a network style device, so I need to use the character
dev model.  The backend (and parts of the frontend)
construct and enqueue messages to pass to the user
when he eventually does a read.  I need to alloc
memory for each of these messages (which have random
sizes, from dozens of bytes up to 1024 bytes).  I'm curently
using malloc(size,M_DEVBUF,waitflag).  Is there better
way to do this?

5) Are there any ipl restrictions on calling wakeup()?

6) Where does device ipl come from?  I don't see it in the
config file?  How do I know what ipl my device interrupts
at?

7) xxintr(int unit).  Which unit?  How computed?  I'm used
to xxintr(int vec).

8) I see that people often avoid having xxread/xxwrite routines
for this situation.  I did the opposite: I have xxread/xxwrite
routines and require the stuff sent to be protocol packets.
Is there any major drawback to this besides the possiblity
of having some butthead do ``cat /etc/passwd /dev/mcc''?

Also:

> The ugl^H^H^Hrightly formatted way is:

Actual routine is:

int mccread(dev_t dev, struct uio *uio, int ioflag)
{
  mcc_t *mcc = MCC_DEV(dev);		/* Private data for this channel */
  mcc_mblk_t *mp;
  int oldspl;

  /* Send first accumulated message, or wait if possible */
 again:
  oldspl = SPLINT();			/* Lock */
  mp = l_remove_head(&mcc->mcc_done);	/* Get anything there */
  if (mp) {				/* Return it */
    mc_primitives_union_t *mcp = MCC_MBLK_DATA(mp);
    if (mcp->header.mc_length > uio->uio_resid) {
      /* 
	 We refuse to copy less than a complete message,
         so we requeue this one!
      */
      l_add_head(&mcc->mcc_done,mp);	/* Return it to head of list */
      splx(oldspl);			/* Unlock */
      return EINVAL;
    } else {
      splx(oldspl);			/* Unlock */
      uiomove(mcp, mcp->header.mc_length, uio);
      free(mp,M_DEVBUF);
      return 0;
    }
  } else if (ioflag & IO_NDELAY) {	/* Can't block, sorry */
    splx(oldspl);			/* Unlock */
    return EWOULDBLOCK;
  } else {				/* Otherwise try again */
    int error;
    mcc->mcc_blocked = 1;		/* Mark ourselves blocked */
    error = tsleep(&mcc->mcc_done, PZERO | PCATCH, "mccin", 0);
    mcc->mcc_blocked = 0;		/* Mark ourselves unblocked */
    splx(oldspl);			/* Unlock */
    if (error && (error != ERESTART)) return error;
    goto again;
  }
}

-----------------------------------------------------------------------------
Robert Withrow, Tel: +1 617 598 4480, Fax: +1 617 598 4430 Net: witr@rwwa.COM
     R.W. Withrow Associates, 319 Lynnway Suite 201, Lynn MA 01901 USA




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512031615.LAA13131>