[news.software.nntp] Inefficiency in serve.c

jerry@olivey.olivetti.com (Jerry Aguirre) (07/29/89)

I notice that the following code in server/serve.c seems less than
optimal:

	if (space() < 0 && !canpost ) {
		printf("%d %s NNTP server out of space. Try later.\r\n",
			ERR_GOODBYE, host);
		(void) fflush(stdout);
#ifdef LOG
		syslog(LOG_INFO, "%s no space", hostname);
#endif
		exit(1);
	}

Notice that it is checking space() first and then "!canpost".  As
"canpost" is a simple variable it is going to require a lot less
overhead to test it.  If "canpost" is false then there should be no
reason to check space.

What this means is unnecessary overhead in starting up NNTP servers for
readers.  I would suggest reversing the test to:

	if (!canpost && space() < 0) {

Interestingly this doesn't test if there is space available but rather
whether the space command can find if there is space available.  Another
interesting bit of code is the "space()" command itself which returns a
long value recast to an int.  Not exactly portable to systems with 16
bit ints.

	int
	space()
	{
	    long room_for_news, dfree();

	    room_for_news = dfree(SPOOLDIR);
	    if (room_for_news < MINFREE)
		return(room_for_news);

	    return(0);
	}


I would suggest changing its code to:

	    if (room_for_news < MINFREE) {
		if (room_for_news < 0) return(-1);
		return(1);
	    }
	    return(0);

In the interests of portability.
				Jerry