[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] getaline()




Ok,  I think getaline() in miscutil.c is wrong about something.

Consider the following line I added:

    while ((p=fgets(buf+len, size-len, f)) != NULL) {
        len += strlen(buf+len);
        if (len > 0 && ( buf[len-1] == '\n' || len < size-1 ) )
            break;          /* the whole line has been read */

        size += size+100;
+       fprintf(stderr, "getaline:size=%ld\n", (long)size);
        buf = critrealloc(buf, size, "reading line" );
    }


And observe the output:

thune:/usr/src/leafnode/leafnode-1.9.14# ./fetchnews 
getaline:size=612
getaline:size=1324
getaline:size=2748
getaline:size=5596

This will continue until eventually I get:
realloc(746586012) failed: reading line


Now, I think I understand what the intent is, but I think the
implementation isn't all that great.

First, I think the size += size+100 is kinda silly.  Either double with
size += size (or size << 2 or something) or increase by 100 (size += 100).
But doing both isn't necessary.

Second, the logic behind the idea that, if you didn't read an entire line,
it's because the buffer wasn't large enough, is completely bogus when
dealing with sockets.  Packets don't have to end on a new line boundary.
So I could see it possible the stdio buffering to cause all sorts of funny
things to happen here.

I'm not certain that reading article data one line at a time is the most
effecient method.  Maybe on slower connections, it doesn't make much
difference, but on higher speed connections, I could see where this might
be a performance bottle neck.

Look more into this tomorrow after some sleep.

mrc
-- 
       Mike Castle       Life is like a clock:  You can work constantly
  dalgoda@xxxxxxxxxxxxx  and be right all the time, or not work at all
www.netcom.com/~dalgoda/ and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list