NNTP's IHAVE gets carried away
David C Lawrence
tale at cs.rpi.edu
Tue Feb 27 21:15:30 AEST 1990
> I've hacked arround this (it's not the best fix, but it was simple),
> by adding a second parameter to gethistent, which is a flag "returnpath".
Well, it's essentially the fix used by this; though this still hadn't
made it into the 1.5.7 release a few of us (well, me and John Coolidge
at least. I have good guesses about a handful of others that have
likely applied it to) have been running with it for several months.
>From news.software.nntp Thu Jul 13 18:04:47 1989
>From: david at elroy.jpl.nasa.gov (David Robinson)
Newsgroups: news.software.nntp
Subject: ihave speedup
Message-ID: <1989Jul13.031603.13790 at elroy.jpl.nasa.gov>
Date: 13 Jul 89 03:16:03 GMT
Organization: Image Analysis Systems Grp, JPL
Lines: 128
Below is a noticeable speedup in the processing of IHAVE requests,
especially if you receive many duplicates.
In the function ihave(), gethistent() is called to see if
the proposed article exists if it returns non-NULL a "Got It"
message is sent back, otherwise the article is accepted. No
where is the value returned (the path of the article) ever used
by ihave().
In gethistent(), a database lookup is performed and the resulting
value is used to seek into the history file and then read the
line. Since ihave() doesn't really need the path, the extra lseek()
and fgets() (which usually forces a hard disk read) is wasted.
These diffs add a lookup variable as an argument to gethistent,
it it is non-zero only a history lookup is performed and a bogus
non-NULL pointer is returned.
Gethistent should probably be rewritten into two pieces, one part
to get back the database value and the other to actually read the
history file.
I also noticed a rewind() that is done on the history file right
before the fseek() to an absolute offset. I see no good reason to
do this and it has the side effect of flushing the stdio input
buffer.
-David Robinson
==================
*** misc.c-orig Wed Jun 14 19:32:32 1989
--- misc.c Wed Jul 12 20:09:46 1989
***************
*** 72,77 ****
--- 72,78 ----
*
* Parameters: "msg_id" is the message ID of the
* article, enclosed in <>'s.
+ * "lookup", only check if article exists
*
* Returns: A char pointer to a static data area
* containing the full pathname of the
***************
*** 91,98 ****
#endif not DBM
char *
! gethistent(msg_id)
char *msg_id;
{
char line[MAXBUFLEN];
char *tmp;
--- 92,100 ----
#endif not DBM
char *
! gethistent(msg_id, lookup)
char *msg_id;
+ int lookup;
{
char line[MAXBUFLEN];
char *tmp;
***************
*** 167,172 ****
--- 169,181 ----
if (content.dptr == NULL)
return (NULL);
+ /*
+ * If we are just checking to see if it exists return a non-NULL
+ * result
+ */
+ if (lookup)
+ return ((char *)1);
+
if (hfp == NULL) {
hfp = fopen(historyfile, "r");
if (hfp == NULL) {
***************
*** 177,182 ****
--- 186,192 ----
return (NULL);
}
} else {
+ /* Why do this if we are going to do an absolute fseek below? XXX */
rewind(hfp);
}
***************
*** 241,247 ****
{
char *path;
! path = gethistent(msg_id);
if (path != NULL)
return (fopen(path, "r"));
else
--- 251,257 ----
{
char *path;
! path = gethistent(msg_id, 0);
if (path != NULL)
return (fopen(path, "r"));
else
*** ihave.c-orig Wed Jun 14 19:32:32 1989
--- ihave.c Mon Jul 10 20:00:46 1989
***************
*** 30,36 ****
return;
}
! cp = gethistent(argv[1]);
if (cp != NULL) {
printf("%d Got it.\r\n", ERR_GOTIT);
(void) fflush(stdout);
--- 30,36 ----
return;
}
! cp = gethistent(argv[1], 1);
if (cp != NULL) {
printf("%d Got it.\r\n", ERR_GOTIT);
(void) fflush(stdout);
--
David Robinson elroy!david at csvax.caltech.edu ARPA
david at elroy.jpl.nasa.gov ARPA
{cit-vax,ames}!elroy!david UUCP
Disclaimer: No one listens to me anyway!
More information about the Alt.sources.patches
mailing list