🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #5022

Patch for improved streaming on inn1.4unoff3

#5022
From: Pete Ashdown
Date: Fri, 16 Feb 1996 00:00
1089 lines
32121 bytes
The following should be able to patch up inn1.4unoff3 with Jerry Aguirre's
improved streaming-mode patch from Jan 4.  I went through and patched mine by
hand and then did a diff against the emacs backup files.

I *think* it should be OK.  Mine compiled and is running fine.

Any questions about the patch in general should be directed to
jerry@strobe.ATC.Olivetti.Com.  I am not the author, I just worked this into 
inn1.4unoff3.

Apply with "patch -p0 <name.of.this.file":

*** innd/chan.c~	Fri Feb 16 08:49:06 1996
--- innd/chan.c	Fri Feb 16 09:03:07 1996
***************
*** 118,123 ****
--- 118,126 ----
      cp->Out = out;
      cp->Tracing = Tracing;
      cp->Sendid.Size=0;
+     cp->Rest=0;
+     cp->SaveUsed=0;
+     cp->Lastch=0;
  
      /* Make the descriptor close-on-exec and non-blocking. */
      CloseOnExec(fd, TRUE);
*** innd/innd.h~	Fri Feb 16 08:49:06 1996
--- innd/innd.h	Fri Feb 16 09:04:42 1996
***************
*** 149,154 ****
--- 149,157 ----
      BUFFER		Out;
      BOOL		Tracing;
      BUFFER		Sendid;
+     int                       Lastch;
+     int                       Rest;
+     int                       SaveUsed;
  } CHANNEL;
  
  
*** backends/innxmit.c~	Thu Sep  7 09:51:17 1995
--- backends/innxmit.c	Fri Feb 16 13:15:31 1996
***************
*** 1,7 ****
  /*  $Revision: 1.14 $
  **
  **  Transmit articles to remote site.
! **  Modified for NNTP streaming: 27June95 Jerry Aguirre
  */
  #include "configdata.h"
  #include <stdio.h>
--- 1,7 ----
  /*  $Revision: 1.14 $
  **
  **  Transmit articles to remote site.
! **  Modified for NNTP streaming: 3Jan96 Jerry Aguirre
  */
  #include "configdata.h"
  #include <stdio.h>
***************
*** 66,81 ****
  	int   st_retry;		/* retry count */
  	int   st_age;		/* age count */
  	QIOSTATE *st_qp;	/* IO to read article contents */
  };
  static struct stbufs stbuf[STNBUF]; /* we keep track of this many articles */
  static int stnq;	/* current number of active entries in stbuf */
- static int stahead;	/* streaming mode "slow start" counter */
  static long stnofail;	/* Count of consecutive successful sends */
  
  static int TryStream = TRUE;	/* Should attempt stream negotation? */
  static int CanStream = FALSE;	/* Result of stream negotation */
  static int DoCheck   = TRUE;	/* Should check before takethis? */
  static char modestream[] = "mode stream";
  
  
  
--- 66,82 ----
  	int   st_retry;		/* retry count */
  	int   st_age;		/* age count */
  	QIOSTATE *st_qp;	/* IO to read article contents */
+ 	int   st_hash;		/* hash value to speed searches */
  };
  static struct stbufs stbuf[STNBUF]; /* we keep track of this many articles */
  static int stnq;	/* current number of active entries in stbuf */
  static long stnofail;	/* Count of consecutive successful sends */
  
  static int TryStream = TRUE;	/* Should attempt stream negotation? */
  static int CanStream = FALSE;	/* Result of stream negotation */
  static int DoCheck   = TRUE;	/* Should check before takethis? */
  static char modestream[] = "mode stream";
+ static long retries = 0;
  
  
  
***************
*** 222,257 ****
  }
  
  /*
! **  Return TRUE if the MessageID duplicates an existing entry.
! **  Duplicates sometime get into the queue and this greatly confuses
  **  the protocol.
  */
! STATIC BOOL
! stisdup(MessageID)
      char		*MessageID;
  {
      register int i;
  
      for (i = 0; i < STNBUF; i++) { /* linear search for ID */
  	if ((stbuf[i].st_id) && (stbuf[i].st_id[0])
! 	 && (0 == strcasecmp(MessageID, stbuf[i].st_id))) {
  	    register int n;
  
! 	    for (n = 0; (MessageID[n] != '@') && (MessageID[n] != '\0'); n++) ;
  	    /* left of '@' is case sensitive */
  	    if (strncmp(MessageID, stbuf[i].st_id, n)) continue;
  	    else break;	/* found a match */
  	}
      }
!     return (i < STNBUF);	/* true if we found an existing entry */
  }
  
  /* stalloc(): save path, ID, and qp into one of the streaming mode entries */
  STATIC int
! stalloc(Article, MessageID, qp)
      char		*Article;
      char		*MessageID;
!     register QIOSTATE	*qp;
  {
      register int i;
  
--- 223,283 ----
  }
  
  /*
! **  Return index to entry matching this message ID.  Else return -1.
! **  The hash is to speed up the search.
  **  the protocol.
  */
! STATIC int
! stindex(MessageID, hash)
      char		*MessageID;
+     int hash;
  {
      register int i;
  
      for (i = 0; i < STNBUF; i++) { /* linear search for ID */
  	if ((stbuf[i].st_id) && (stbuf[i].st_id[0])
! 	 && (stbuf[i].st_hash == hash)) {
  	    register int n;
  
! 	    if (strcasecmp(MessageID, stbuf[i].st_id)) continue;
! 
  	    /* left of '@' is case sensitive */
+ 	    for (n = 0; (MessageID[n] != '@') && (MessageID[n] != '\0'); n++) ;
  	    if (strncmp(MessageID, stbuf[i].st_id, n)) continue;
  	    else break;	/* found a match */
  	}
      }
!     if (i >= STNBUF) i = -1;  /* no match found ? */
!     return (i);
! }
! 
! /* stidhash(): calculate a hash value for message IDs to speed comparisons */
! STATIC int
! stidhash(MessageID)
!     char                *MessageID;
! {
!     register char *p;
!     register int hash;
! 
!     hash = 0;
!     for (p = MessageID + 1; *p && (*p != '>'); p++) {
! 	hash <<= 1;
! 	if (isascii(*p) && isupper(*p)) {
! 	    hash += tolower(*p);
! 	} else {
! 	    hash += *p;
! 	}
!     }
!     return hash;
  }
  
  /* stalloc(): save path, ID, and qp into one of the streaming mode entries */
  STATIC int
! stalloc(Article, MessageID, qp, hash)
      char		*Article;
      char		*MessageID;
!     QIOSTATE		*qp;
!     int			hash;
  {
      register int i;
  
***************
*** 275,280 ****
--- 301,307 ----
      (void)strcpy(stbuf[i].st_fname, Article);
      (void)strcpy(stbuf[i].st_id, MessageID);
      stbuf[i].st_qp = qp;
+     stbuf[i].st_hash = hash;
      stbuf[i].st_retry = 0;
      stbuf[i].st_age = 0;
      stnq++;
***************
*** 302,308 ****
  REMwrite(p, i, escdot)
      register char	*p;
      register int	i;
!     register BOOL	escdot;
  {
      static char		HDR[] = "Content-Transfer-Encoding:";
      static char		COD[] =
--- 329,335 ----
  REMwrite(p, i, escdot)
      register char	*p;
      register int	i;
!     register BOOL       escdot;
  {
      static char		HDR[] = "Content-Transfer-Encoding:";
      static char		COD[] =
***************
*** 444,449 ****
--- 471,478 ----
      syslog(L_NOTICE, STAT1,
  	REMhost, STAToffered, STATaccepted, STATrefused, STATrejected);
      syslog(L_NOTICE, STAT2, REMhost, usertime, systime, STATend - STATbegin);
+     if (retries)
+ 	syslog(L_NOTICE, "%s %lu Streaming retries", REMhost, retries);
  
      if (BATCHfp != NULL && unlink(BATCHtemp) < 0 && errno != ENOENT)
  	(void)fprintf(stderr, "Can't remove \"%s\", %s\n",
***************
*** 549,580 ****
      }
      Requeue(Article, MessageID);
  
!     if (BATCHqp) {
! 	for ( ; ; ) {
! 	    if ((p = QIOread(BATCHqp)) == NULL) {
! 		if (QIOtoolong(BATCHqp)) {
! 		    (void)fprintf(stderr, "Skipping long line in \"%s\".\n",
! 			    BATCHname);
! 		    (void)QIOread(BATCHqp);
! 		    continue;
! 		}
! 		if (QIOerror(BATCHqp)) {
! 		    (void)fprintf(stderr, "Can't read \"%s\", %s\n",
! 			    BATCHname, strerror(errno));
! 		    ExitWithStats(1);
! 		}
  
! 		/* Normal EOF. */
! 		break;
! 	    }
  
! 	    if (fprintf(BATCHfp, "%s\n", p) == EOF
! 	     || ferror(BATCHfp)) {
! 		(void)fprintf(stderr, "Can't requeue \"%s\", %s\n",
! 			p, strerror(errno));
! 		ExitWithStats(1);
! 	    }
! 	}
      }
  
      CloseAndRename();
--- 578,607 ----
      }
      Requeue(Article, MessageID);
  
!     for ( ; BATCHqp; ) {
!         if ((p = QIOread(BATCHqp)) == NULL) {
!             if (QIOerror(BATCHqp)) {
!                 (void)fprintf(stderr, "Can't read \"%s\", %s\n",
!                         BATCHname, strerror(errno));
!                 ExitWithStats(1);
!             }
!             if (QIOtoolong(BATCHqp)) {
!                 (void)fprintf(stderr, "Skipping long line in \"%s\".\n",
!                         BATCHname);
!                 (void)QIOread(BATCHqp);
!                 continue;
!             }
  
!             /* Normal EOF. */
!             break;
!         }
  
!         if (fprintf(BATCHfp, "%s\n", p) == EOF
!          || ferror(BATCHfp)) {
!             (void)fprintf(stderr, "Can't requeue \"%s\", %s\n",
!                     p, strerror(errno));
!             ExitWithStats(1);
!         }
      }
  
      CloseAndRename();
***************
*** 703,710 ****
--- 730,739 ----
      register char	*p;
      register BOOL	ok;
      register BOOL	InHeaders;
+     long                length;
      char		buff[NNTP_STRLEN];
  
+     length = 0;
      for (InHeaders = TRUE; ; ) {
  	if ((p = QIOread(qp)) == NULL) {
  	    if (QIOtoolong(qp)) {
***************
*** 730,735 ****
--- 759,765 ----
  		        Article, strerror(errno));
  	        return FALSE;
  	    }
+ 	    length += QIOlength(qp);
  	}
  	else {
  	    switch (MimeArticle) {
***************
*** 739,744 ****
--- 769,775 ----
  		break;
  	    case MTquotedprintable:
  		ok = REMwriteQuoted(p, QIOlength(qp));
+ 		length += QIOlength(qp);
  		break;
  	    }
  	    if (!ok) {
***************
*** 757,763 ****
  	return FALSE;
      }
      if (Debug)
! 	(void)fprintf(stderr, "> [ article ]%s\n",
  	     MimeArticle == MTnotmime ? "" : " (Mime: quoted-printable)");
      if (GotInterrupt)
  	Interrupted(Article, MessageID);
--- 788,794 ----
  	return FALSE;
      }
      if (Debug)
! 	(void)fprintf(stderr, "> [ article %ld ]%s\n", length,
  	     MimeArticle == MTnotmime ? "" : " (Mime: quoted-printable)");
      if (GotInterrupt)
  	Interrupted(Article, MessageID);
***************
*** 924,930 ****
  	return TRUE;
      }
      STAToffered++;
-     if (stahead > 0) stahead--;
      if (Debug) {
  	if (stbuf[i].st_retry)
  	    (void)fprintf(stderr, "> %s (retry %d)\n", buff, stbuf[i].st_retry);
--- 955,960 ----
***************
*** 978,984 ****
      QIOclose(stbuf[i].st_qp);	/* should not need file again */
      stbuf[i].st_qp = 0;		/* so close to free descriptor */
      stbuf[i].st_age = 0;
-     if (stahead < STNBUFL) stahead++;
      /* That all.  Response is checked later by strlisten() */
      return FALSE;
  }
--- 1008,1013 ----
***************
*** 995,1000 ****
--- 1024,1030 ----
      int		i;
      char	*id, *p;
      char	buff[NNTP_STRLEN];
+     int		hash;
  
      while(TRUE) {
  	if (!REMread(buff, (int)sizeof buff)) {
***************
*** 1019,1036 ****
  	    if (id = strchr(buff, '<')) {
  		p = strchr(id, '>');
  		if (p) *(p+1) = '\0';
! 		for (i = 0; i < STNBUF; i++) { /* linear search for ID */
! 		    if ((stbuf[i].st_id) && (stbuf[i].st_id[0])
! 		     && (0 == strcasecmp(id, stbuf[i].st_id))) {
! 			register int n;
! 
! 			for (n = 0; (id[n] != '@') && (id[n] != '\0'); n++) ;
! 			/* left of '@' is case sensitive */
! 			if (strncmp(id, stbuf[i].st_id, n)) continue;
! 			else break;	/* found a match */
! 		    }
! 		}
! 		if (i >= STNBUF) { /* should not happen */
  		    syslog(L_NOTICE, CANT_FINDIT, REMhost, REMclean(buff));
  		    return (TRUE); /* can't find it! */
  		}
--- 1049,1057 ----
  	    if (id = strchr(buff, '<')) {
  		p = strchr(id, '>');
  		if (p) *(p+1) = '\0';
! 		hash = stidhash(id);
! 		i = stindex(id, hash);	/* find table entry */
! 		if (i < 0) { /* should not happen */
  		    syslog(L_NOTICE, CANT_FINDIT, REMhost, REMclean(buff));
  		    return (TRUE); /* can't find it! */
  		}
***************
*** 1117,1126 ****
--- 1138,1149 ----
      FILE		*From;
      FILE		*To;
      char		buff[NNTP_STRLEN];
+     char                *AltSpool;
      char		*Article;
      char		*ContentEncoding;
      char		*ContentType;
      char		*MessageID;
+     char                *AltPath;
      SIGHANDLER		(*old)();
      unsigned int	ConnectTimeout;
      unsigned int	TotalTimeout;
***************
*** 1169,1175 ****
  	    break;
  	case 'S':
  	    Slavish = TRUE;
! 	    TryStream = FALSE;
  	    break;
  	case 't':
  	    ConnectTimeout = atoi(optarg);
--- 1192,1198 ----
  	    break;
  	case 'S':
  	    Slavish = TRUE;
! 	    TryStream = FALSE; /* streaming does not support xreplic */
  	    break;
  	case 't':
  	    ConnectTimeout = atoi(optarg);
***************
*** 1322,1328 ****
  		    stbuf[i].st_qp = 0;
  		}
  		stnq = 0;
- 		stahead = 0;
  	    }
  	}
      }
--- 1345,1350 ----
***************
*** 1474,1495 ****
  	/* Offer the article. */
  	if (CanStream) {
  	    int i;
  
! 	    if (stisdup(MessageID)) {	/* skip duplicates in queue */
  		if (Debug)
  		    (void)fprintf(stderr, "Skipping duplicate ID %s\n",
  							    MessageID);
  		QIOclose(qp);
  		continue;
  	    }
! 	    while (stnq >= STNBUFL) { /* need to empty a buffer */
! 		if (strlisten()) {
! 		    RequeueRestAndExit(Article, MessageID);
  		}
- 		if ((stahead > 0) && (stnq < STNBUF)) break;
  	    }
  	    /* save new article in the buffer */
! 	    i = stalloc(Article, MessageID, qp);
  	    if (i < 0) {
  		QIOclose(qp);
  		RequeueRestAndExit(Article, MessageID);
--- 1496,1528 ----
  	/* Offer the article. */
  	if (CanStream) {
  	    int i;
+ 	    int lim;
+ 	    int hash;
  
! 	    hash = stidhash(MessageID);
! 	    if (stindex(MessageID, hash) >= 0) { /* skip duplicates in queue */
  		if (Debug)
  		    (void)fprintf(stderr, "Skipping duplicate ID %s\n",
  							    MessageID);
  		QIOclose(qp);
  		continue;
  	    }
! 	    /* This code tries to optimize by sending a burst of "check"
! 	     * commands before flushing the buffer.  This should result
! 	     * in several being sent in one packet reducing the network
! 	     * overhead.
! 	     */
! 	    if (DoCheck && (stnofail < STNC)) lim = STNBUF;
! 	    else                              lim = STNBUFL;
! 	    if (stnq >= lim) { /* need to empty a buffer */
! 		while (stnq >= STNBUFL) { /* or several */
! 		    if (strlisten()) {
! 			RequeueRestAndExit(Article, MessageID);
! 		    }
  		}
  	    }
  	    /* save new article in the buffer */
! 	    i = stalloc(Article, MessageID, qp, hash);
  	    if (i < 0) {
  		QIOclose(qp);
  		RequeueRestAndExit(Article, MessageID);
***************
*** 1503,1514 ****
--- 1536,1549 ----
  		    RequeueRestAndExit((char *)NULL, (char *)NULL);
  		}
  	    }
+ 	    /* check for need to resend any IDs */
  	    for (i = 0; i < STNBUF; i++) {
  		if ((stbuf[i].st_fname) && (stbuf[i].st_fname[0] != '\0')) {
  		    if (stbuf[i].st_age++ > stnq) {
  			/* This should not happen but just in case ... */
  			if (stbuf[i].st_retry < STNRETRY) {
  			    if (check(i)) return TRUE; /* resend check */
+ 			    retries++;
  			    stbuf[i].st_retry++;
  			    stbuf[i].st_age = 0;
  			} else { /* requeue to disk for later */
*** innd/nc.c~	Thu Oct  5 08:31:54 1995
--- innd/nc.c	Fri Feb 16 13:57:17 1996
***************
*** 6,14 ****
  #include "innd.h"
  #include "dbz.h"
  
- /* for debugging the "mode stream" code */
- #undef STR_DEBUG
- 
  #define BAD_COMMAND_COUNT	10
  #define WIP_CHECK		(1 * 60)
  #define SAVE_AMT		10
--- 6,11 ----
***************
*** 119,139 ****
      }
  }
  
- 
  /*
  **  Write an NNTP reply message.
  */
  STATIC void
  NCwritetext(cp, text)
!     CHANNEL	*cp;
!     char	*text;
  {
      RCHANremove(cp);
      WCHANset(cp, text, (int)strlen(text));
      WCHANappend(cp, NCterm, STRLEN(NCterm));
      WCHANadd(cp);
      if (Tracing || cp->Tracing)
! 	syslog(L_TRACE, "%s > %s", CHANname(cp), text);
  }
  
  
--- 116,135 ----
      }
  }
  
  /*
  **  Write an NNTP reply message.
  */
  STATIC void
  NCwritetext(cp, text)
!     CHANNEL     *cp;
!     char        *text;
  {
      RCHANremove(cp);
      WCHANset(cp, text, (int)strlen(text));
      WCHANappend(cp, NCterm, STRLEN(NCterm));
      WCHANadd(cp);
      if (Tracing || cp->Tracing)
!         syslog(L_TRACE, "%s > %s", CHANname(cp), text);
  }
  
  
***************
*** 156,165 ****
      WCHANappend(cp, NCterm, STRLEN(NCterm));	/* add CR NL to text */
      if (i == 0) {	/* if only data then try to write directly */
  	i = write(cp->fd, &bp->Data[bp->Used], bp->Left);
! #ifdef STR_DEBUG
! 	syslog(L_NOTICE, "%s NCwritereply %d=write(%d, \"%.15s\", %d)",
! 	    CHANname(cp), i, cp->fd,  &bp->Data[bp->Used], bp->Left);
! #endif STR_DEBUG
  	if (i > 0) bp->Used += i;
  	if (bp->Used == bp->Left) bp->Used = bp->Left = 0;
  	else i = 0;
--- 152,160 ----
      WCHANappend(cp, NCterm, STRLEN(NCterm));	/* add CR NL to text */
      if (i == 0) {	/* if only data then try to write directly */
  	i = write(cp->fd, &bp->Data[bp->Used], bp->Left);
! 	if (Tracing || cp->Tracing)
! 	    syslog(L_TRACE, "%s NCwritereply %d=write(%d, \"%.15s\", %d)",
! 		CHANname(cp), i, cp->fd,  &bp->Data[bp->Used], bp->Left);
  	if (i > 0) bp->Used += i;
  	if (bp->Used == bp->Left) bp->Used = bp->Left = 0;
  	else i = 0;
***************
*** 664,669 ****
--- 659,666 ----
  	char buff[16];
  	(void)sprintf(buff, "%d StreamOK.", NNTP_OK_STREAM_VAL);
  	NCwritetext(cp, buff);
+ 	syslog(L_NOTICE, "%s NCmode \"mode stream\" received",
+ 	       CHANname(cp));
  	return;
      } else {
  	NCwritetext(cp, NCbadcommand);
***************
*** 823,833 ****
  
  
  /*
! **  Read whatever data is available on the channel.  If we got the
  **  full amount (i.e., the command or the whole article) process it.
  */
  STATIC FUNCTYPE
! NCreader(cp)
      register CHANNEL	*cp;
  {
      register char	*p;
--- 820,830 ----
  
  
  /*
! **  Check whatever data is available on the channel.  If we got the
  **  full amount (i.e., the command or the whole article) process it.
  */
  STATIC FUNCTYPE
! NCproc(cp)
      register CHANNEL	*cp;
  {
      register char	*p;
***************
*** 838,887 ****
      char		buff[SMBUF];
      char		*av[2];
      int			i;
-     int			rest;
-     int			SaveUsed;
- 
- #ifdef STR_DEBUG
-     syslog(L_NOTICE, "%s NCreader Used=%d",
- 	CHANname(cp), cp->In.Used);
- #endif STR_DEBUG
-     /* Read any data that's there; ignore errors (retry next time it's our
-      * turn) and if we got nothing, then it's EOF so mark it closed. */
-     if ((i = CHANreadtext(cp)) < 0) {
- #ifdef SUNOS5
-     /* return of -2 indicates EAGAIN, for SUNOS5.4 poll() bug workaround */
- 	if (i == -2) {
-            return;
- 	}
- #endif
- 	if (cp->BadReads++ >= BAD_IO_COUNT) {
- 	    if (NCcount > 0)
- 		NCcount--;
- 	    CHANclose(cp, CHANname(cp));
- 	}
- 	return;
-     }
-     if (i == 0) {
- 	NCcount--;
- 	return;
-     }
- 
-     /* Update timestamp. */
-     wp = &NCwip[cp->fd];
-     wp->Timestamp = Now.time;
  
      bp = &cp->In;
      p = &bp->Data[bp->Used];
!     rest = SaveUsed = bp->Used;
      for ( ; ; ) {
! #ifdef STR_DEBUG
! 	if (bp->Used > 15)
! 	    syslog(L_NOTICE, "%s NCreader state=%d next \"%.15s\"",
! 		CHANname(cp), cp->State, bp->Data);
! #endif STR_DEBUG
  	switch (cp->State) {
  	default:
! 	    syslog(L_ERROR, "%s internal NCreader state %d",
  		CHANname(cp), cp->State);
  	    break;
  
--- 835,860 ----
      char		buff[SMBUF];
      char		*av[2];
      int			i;
  
+     if (Tracing || cp->Tracing)
+ 	syslog(L_TRACE, "%s NCproc Used=%d",
+ 	    CHANname(cp), cp->In.Used);
+     
      bp = &cp->In;
+     if (bp->Used == 0) return;
+ 
      p = &bp->Data[bp->Used];
!     wp = &NCwip[cp->fd];
      for ( ; ; ) {
! 	cp->Rest = 0;
! 	cp->SaveUsed = bp->Used;
! 	if (Tracing || cp->Tracing)
! 	    if (bp->Used > 15)
! 		syslog(L_TRACE, "%s NCproc state=%d next \"%.15s\"",
! 		    CHANname(cp), cp->State, bp->Data);
  	switch (cp->State) {
  	default:
! 	    syslog(L_ERROR, "%s internal NCproc state %d",
  		CHANname(cp), cp->State);
  	    break;
  
***************
*** 889,902 ****
  	case CSgetauth:
  	    /* Did we get the whole command, terminated with "\r\n"? */
  	    for (i = 0; (i < bp->Used) && (bp->Data[i] != '\n'); i++) ;
! 	    if (i < bp->Used) rest = bp->Used = ++i;
  	    else {
! 		rest = 0;
  		break;	/* come back later for rest of line */
  	    }
! 	    p = &bp->Data[rest];
! 	    if (rest < 2 || p[-2] != '\r' || p[-1] != '\n')
  		break;
  	    p[-2] = '\0';
  	    bp->Used -= 2;
  
--- 862,892 ----
  	case CSgetauth:
  	    /* Did we get the whole command, terminated with "\r\n"? */
  	    for (i = 0; (i < bp->Used) && (bp->Data[i] != '\n'); i++) ;
! 	    if (i < bp->Used) cp->Rest = bp->Used = ++i;
  	    else {
! 		cp->Rest = 0;
  		break;	/* come back later for rest of line */
  	    }
! 	    if (cp->Rest < 2) break;
! 	    p = &bp->Data[cp->Rest];
! 	    if (p[-2] != '\r' || p[-1] != '\n') { /* probably in an article */
! 		int j;
! 
! 		syslog(L_NOTICE, "%s bad_command %s",
! 		    CHANname(cp), MaxLength(bp->Data, bp->Data));
! 		NCwritetext(cp, NCbadcommand);
! 		if (++(cp->BadCommands) >= BAD_COMMAND_COUNT) {
! 		    cp->State = CSwritegoodbye;
! 		    cp->Rest = cp->SaveUsed;
! 		    break;
! 		}
! 		for (j = i + 1; j < cp->SaveUsed; j++)
! 		    if (bp->Data[j] ==  '\n') {
! 			if (bp->Data[j - 1] == '\r') break;
! 			else cp->Rest = bp->Used = j + 1;
! 		    }
  		break;
+ 	    }
  	    p[-2] = '\0';
  	    bp->Used -= 2;
  
***************
*** 932,943 ****
  		NCwritetext(cp, NCbadcommand);
  		if (++(cp->BadCommands) >= BAD_COMMAND_COUNT) {
  		    cp->State = CSwritegoodbye;
! 		    rest = SaveUsed;
  		}
  		for (i = 0; (p = NCquietlist[i]) != NULL; i++)
  		    if (caseEQ(p, dp->Name))
  			break;
! 		if (NCquietlist[i] == NULL)
  		    syslog(L_NOTICE, "%s bad_command %s",
  			CHANname(cp), MaxLength(bp->Data, bp->Data));
  	    }
--- 922,933 ----
  		NCwritetext(cp, NCbadcommand);
  		if (++(cp->BadCommands) >= BAD_COMMAND_COUNT) {
  		    cp->State = CSwritegoodbye;
! 		    cp->Rest = cp->SaveUsed;
  		}
  		for (i = 0; (p = NCquietlist[i]) != NULL; i++)
  		    if (caseEQ(p, dp->Name))
  			break;
! 		if (p == NULL)
  		    syslog(L_NOTICE, "%s bad_command %s",
  			CHANname(cp), MaxLength(bp->Data, bp->Data));
  	    }
***************
*** 948,954 ****
  	    /* Check for the null article. */
  	    if ((bp->Used >= 3) && (bp->Data[0] == '.')
  	     && (bp->Data[1] == '\r') && (bp->Data[2] == '\n')) {
! 		rest = 3;	/* null article (canceled?) */
  		cp->Rejected++;
  		if (cp->Sendid.Size > 3) { /* We be streaming */
  		    char buff[4];
--- 938,944 ----
  	    /* Check for the null article. */
  	    if ((bp->Used >= 3) && (bp->Data[0] == '.')
  	     && (bp->Data[1] == '\r') && (bp->Data[2] == '\n')) {
! 		cp->Rest = 3;	/* null article (canceled?) */
  		cp->Rejected++;
  		if (cp->Sendid.Size > 3) { /* We be streaming */
  		    char buff[4];
***************
*** 967,983 ****
  		break;
  	    }
  	    /* Reading an article; look for "\r\n.\r\n" terminator. */
! 	    for (i = 5; i <= bp->Used; i++) {
  		if ((bp->Data[i - 5] == '\r')
  		 && (bp->Data[i - 4] == '\n')
  		 && (bp->Data[i - 3] == '.')
  		 && (bp->Data[i - 2] == '\r')
  		 && (bp->Data[i - 1] == '\n')) {
! 		    rest = bp->Used = i;
  		    p = &bp->Data[i];
  		    break;
  		}
  	    }
  	    if (i > bp->Used) {	/* did not find terminator */
  		/* Check for big articles. */
  		if (LargestArticle > SAVE_AMT && bp->Used > LargestArticle) {
--- 957,976 ----
  		break;
  	    }
  	    /* Reading an article; look for "\r\n.\r\n" terminator. */
! 	    if (cp->Lastch > 5) i = cp->Lastch; /* only look at new data */
! 	    else         i = 5;
! 	    for ( ; i <= bp->Used; i++) {
  		if ((bp->Data[i - 5] == '\r')
  		 && (bp->Data[i - 4] == '\n')
  		 && (bp->Data[i - 3] == '.')
  		 && (bp->Data[i - 2] == '\r')
  		 && (bp->Data[i - 1] == '\n')) {
! 		    cp->Rest = bp->Used = i;
  		    p = &bp->Data[i];
  		    break;
  		}
  	    }
+ 	    cp->Lastch = i;
  	    if (i > bp->Used) {	/* did not find terminator */
  		/* Check for big articles. */
  		if (LargestArticle > SAVE_AMT && bp->Used > LargestArticle) {
***************
*** 987,995 ****
  		    wp->Size += bp->Used - SAVE_AMT;
  		    bp->Used = SAVE_AMT;
  		    cp->State = CSeatarticle;
! 		} else rest = 0;
  		break;
  	    }
  
  	    /* Strip article terminator and post the article. */
  	    p[-3] = '\0';
--- 980,996 ----
  		    wp->Size += bp->Used - SAVE_AMT;
  		    bp->Used = SAVE_AMT;
  		    cp->State = CSeatarticle;
! 		}
! 		cp->Rest = 0;
  		break;
  	    }
+ 	    if (Mode == OMpaused) { /* defer processing while paused */
+ 		cp->Rest = 0;
+ 		bp->Used = cp->SaveUsed;
+ 		SCHANadd(cp, (time_t)(Now.time + PAUSE_RETRY_TIME),
+ 		    (POINTER)&Mode, NCproc, (POINTER)NULL);
+ 		return;
+ 	    }
  
  	    /* Strip article terminator and post the article. */
  	    p[-3] = '\0';
***************
*** 1007,1019 ****
  	case CSeatarticle:
  	    /* Eat the article and then complain that it was too large */
  	    /* Reading an article; look for "\r\n.\r\n" terminator. */
! 	    for (i = 5; i <= bp->Used; i++) {
  		if ((bp->Data[i - 5] == '\r')
  		 && (bp->Data[i - 4] == '\n')
  		 && (bp->Data[i - 3] == '.')
  		 && (bp->Data[i - 2] == '\r')
  		 && (bp->Data[i - 1] == '\n')) {
! 		    rest = bp->Used = i;
  		    p = &bp->Data[i];
  		    break;
  		}
--- 1008,1022 ----
  	case CSeatarticle:
  	    /* Eat the article and then complain that it was too large */
  	    /* Reading an article; look for "\r\n.\r\n" terminator. */
! 	    if (cp->Lastch > 5) i = cp->Lastch; /* only look at new data */
! 	    else         i = 5;
! 	    for ( ; i <= bp->Used; i++) {
  		if ((bp->Data[i - 5] == '\r')
  		 && (bp->Data[i - 4] == '\n')
  		 && (bp->Data[i - 3] == '.')
  		 && (bp->Data[i - 2] == '\r')
  		 && (bp->Data[i - 1] == '\n')) {
! 		    cp->Rest = bp->Used = i;
  		    p = &bp->Data[i];
  		    break;
  		}
***************
*** 1047,1085 ****
  		/* Clear the work-in-progress entry. */
  		NCclearwip(wp);
  
! 		/* Reset input buffer to the default size; don't let realloc
! 		 * be lazy. */
! 		DISPOSE(bp->Data);
! 		bp->Size = START_BUFF_SIZE;
! 		bp->Used = 0;
! 		bp->Data = NEW(char, bp->Size);
! 		rest = 0;
  	    }
  	    else if (bp->Used > 8 * 1024) {
  		/* Make some room; save the last few bytes of the article */
  		for (p = bp->Data, i = 0; i < SAVE_AMT; p++, i++)
  		    p[0] = p[bp->Used - SAVE_AMT + 0];
  		wp->Size += bp->Used - SAVE_AMT;
! 		bp->Used = SAVE_AMT;
  	    }
  	    break;
  	}
! #ifdef STR_DEBUG
! 	syslog(L_NOTICE, "%s NCreader rest=%d Used=%d SaveUsed=%d",
! 	    CHANname(cp), rest, bp->Used, SaveUsed);
! #endif STR_DEBUG
! 	if (rest > 0) {
! 	    if (rest < SaveUsed) { /* more commands in buffer */
! 		bp->Used = SaveUsed = SaveUsed - rest;
  		/* It would be nice to avoid this copy but that
  		** would require changes to the bp structure and
  		** the way it is used.
  		*/
! 		/* strncpy(bp->Data, &bp->Data[rest], bp->Used); */
! 		(void)memcpy((POINTER)bp->Data, (POINTER)&bp->Data[rest], (SIZE_T)bp->Used);
! 		rest = bp->Used;
  	    } else {
! 		bp->Used = 0;
  		break;
  	    }
  	} else break;
--- 1050,1097 ----
  		/* Clear the work-in-progress entry. */
  		NCclearwip(wp);
  
! 		/* 
! 		 * only free and allocate the buffer back to
! 		 * START_BUFF_SIZE if there's nothing in the buffer we
! 		 * need to save (i.e., following commands.
! 		 * if there is, then we're probably in streaming mode,
! 		 * so probably not much point in trying to keep the
! 		 * buffers minimal anyway...
! 		 */
! 		if (bp->Used == cp->SaveUsed) {
! 		    /* Reset input buffer to the default size; don't let realloc
! 		     * be lazy. */
! 		    DISPOSE(bp->Data);
! 		    bp->Size = START_BUFF_SIZE;
! 		    bp->Used = 0;
! 		    bp->Data = NEW(char, bp->Size);
! 		    cp->SaveUsed = cp->Rest = cp->Lastch = 0;
! 		}
  	    }
  	    else if (bp->Used > 8 * 1024) {
  		/* Make some room; save the last few bytes of the article */
  		for (p = bp->Data, i = 0; i < SAVE_AMT; p++, i++)
  		    p[0] = p[bp->Used - SAVE_AMT + 0];
  		wp->Size += bp->Used - SAVE_AMT;
! 		bp->Used = cp->Lastch = SAVE_AMT;
! 		cp->Rest = 0;
  	    }
  	    break;
  	}
! 	if (Tracing || cp->Tracing)
! 		syslog(L_TRACE, "%s NCproc Rest=%d Used=%d SaveUsed=%d",
! 		    CHANname(cp), cp->Rest, bp->Used, cp->SaveUsed);
! 	if (cp->Rest > 0) {
! 	    if (cp->Rest < cp->SaveUsed) { /* more commands in buffer */
! 		bp->Used = cp->SaveUsed = cp->SaveUsed - cp->Rest;
  		/* It would be nice to avoid this copy but that
  		** would require changes to the bp structure and
  		** the way it is used.
  		*/
! 		(void)memcpy((POINTER)bp->Data, (POINTER)&bp->Data[cp->Rest], (SIZE_T)bp->Used);
! 		cp->Rest = cp->Lastch = 0;
  	    } else {
! 		bp->Used = cp->Lastch = 0;
  		break;
  	    }
  	} else break;
***************
*** 1088,1093 ****
--- 1100,1143 ----
  
  
  /*
+ **  Read whatever data is available on the channel.
+ **  Call NCproc() to process the data.
+ */
+ STATIC FUNCTYPE
+ NCreader(cp)
+     register CHANNEL	*cp;
+ {
+     register WIP	*wp;
+     int			i;
+ 
+     if (Tracing || cp->Tracing)
+ 	syslog(L_TRACE, "%s NCreader Used=%d",
+ 	    CHANname(cp), cp->In.Used);
+     
+     /* Read any data that's there; ignore errors (retry next time it's our
+      * turn) and if we got nothing, then it's EOF so mark it closed. */
+     if ((i = CHANreadtext(cp)) < 0) {
+ 	if (cp->BadReads++ >= BAD_IO_COUNT) {
+ 	    if (NCcount > 0)
+ 		NCcount--;
+ 	    CHANclose(cp, CHANname(cp));
+ 	}
+ 	return;
+     }
+     if (i == 0) {
+ 	NCcount--;
+ 	return;
+     }
+ 
+     /* Update timestamp. */
+     wp = &NCwip[cp->fd];
+     wp->Timestamp = Now.time;
+ 
+     NCproc(cp);	/* check and process data */
+ }
+ 
+ 
+ /*
  **  Set up the NNTP channel state.
  */
  void
***************
*** 1266,1271 ****
--- 1316,1323 ----
  {
      register char	*p;
      int			msglen;
+     register WIP	*wp;
+     register int	i;
  
      /* Snip off the Message-ID. */
      for (p = cp->In.Data; !ISWHITE(*p); p++)
***************
*** 1286,1289 ****
--- 1338,1356 ----
      (void)sprintf(cp->Sendid.Data, "%d %s", NNTP_ERR_FAILID_VAL, p);
  
      cp->State = CSgetarticle;
+     /* set wp->MessageID for benefit of later code in NCreader
+      * (especially while in CSeatarticle state)
+      */
+     wp = &NCwip[cp->fd];
+     if (wp->MessageID == NULL) {
+ 	for (i = SIZEOF(NCfreelist); --i >= 0; )
+ 	    if (NCfreelist[i] != NULL) {
+ 		wp->MessageID = NCfreelist[i];
+ 		NCfreelist[i] = NULL;
+ 		break;
+ 	    }
+ 	if (i < 0)
+ 	    wp->MessageID = NEW(char, DBZMAXKEY + 3);
+     }
+     (void)strcpy(wp->MessageID, p);
  }
-- 


Pete Ashdown             pashdown@xmission.com            Salt Lake City, Utah
     XMission Internet Access - Data: 801 539 0900 - Voice: 801 539 0852

Technical Details
Message-ID: <4g2uek$ikh@slack.xmission.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <4g2uek$ikh@slack.xmission.com>
Subject: Patch for improved streaming on inn1.4unoff3
Date: Fri, 16 Feb 1996 00:00:00 +0000
From: pashdown@slack.xmission.com (Pete Ashdown)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 139655102
Distribution: inet
Organization: XMission Internet (801 539 0900)
Newsgroups: news.software.b,news.software.nntp