Subject: Re: UIO_MAXIOV
To: None <thorpej@nas.nasa.gov>
From: Anders Dinsen <anders@box.dinsen.dk.eu.org>
List: netbsd-users
Date: 11/29/1998 21:04:38
> On Sat, 28 Nov 1998 16:26:44 GMT 
>  dinsen@DANBBS.DK (Anders Dinsen) wrote:
> 
>  > There's an nntpd substitute called leafnode that functions as a fuly
>  > fledged nntp server, but does'nt need an newsfeed and only fetches
>  > news for groups that are read (but otherwise exposes all accessible
>  > groups).
>  > 
>  > The make complains that UIO_MAXIOV is'nt defined. That's because in
>  > *.h the #define is surrounded by #ifdef _KERNEL
>  > 
>  > I don't know what UIO_MAXIOV does, so my question is:=20
> 
> Why does the program use it?!

Here's the block of code that uses it. It seems he tries to optimize
things by using as many buffers as possible. I don't know the
details of this, but looking in the man page for writev(), I notice
that UIO_MAXIOV is mentioned:

  ...
  In addition, writev() may return one of the following errors:

  [EINVAL]   Iovcnt was less than or equal to 0, or greater than
             {UIO_MAXIOV}.
  ...

To me that implies that UIO_MAXIOV should be visible to userland
programs. I.e. that it is a bug that it is not exposed.

Anders

...
if ( (wfd=open( mktemp(newfile), O_WRONLY|O_CREAT|O_EXCL, 0664 )) ) {
    struct iovec oooh[UIO_MAXIOV];
    int vi, vc, va;

    vi = vc = va = 0;
    for ( art=xfirst; art<=xlast; art++ ) {
	if ( xoverinfo[art-xfirst].exists &&
	     xoverinfo[art-xfirst].text ) {
	    oooh[vi].iov_base = xoverinfo[art-xfirst].text;
	    oooh[vi].iov_len = strlen( xoverinfo[art-xfirst].text );
	    vc += oooh[vi++].iov_len + 1;
	    oooh[vi].iov_base = "\n";
	    oooh[vi++].iov_len = 1;
	    if ( vi >= (UIO_MAXIOV - 1) ) {
		if ( writev( wfd, oooh, vi ) != vc ) {
		    syslog( LOG_ERR,
			    "writev() for .overview failed: %m" );
		    art = xlast+1; /* so the loop will stop */
		}
		vi = vc = 0;
		va = 1;
	    }
	}
    }
    ...