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

Re: [leafnode-list] C++-ifying leafnode

Timo Geusch schrieb am 2003-07-23:

> Mathias mentioned some time back on this list that he was considering
> to convert part of leafnode-2.0 to either C++ or Python or both.

Looks like it's time to refine and mention my plans.

I think I'll have leafnode-2.0.0 released as a purely C version.

It already offers some advantages over leafnode-1, local groups,
filtering enhancements, much faster fetchnews, some more efficient
internal handling through red-black trees (thanks do Damian Ivereigh's
nice redblack module which is under LGPL), thread-based expire as has
always been promised and never implemented, and I think for portability
versions, I should release such a version.

> Well, it is my pleasure to announce that I've started converting the
> nntp server (nntpd.c) to C++. I'll do the conversion in stages,
> namely:
> 1. Replace printfs with ostreams, C PODs with C++ data types where
> applicable (essentially converting char * to std::string whenever
> possible). The benefits of this are less chance of a printf-induced
> buffer overflow, typesafe data conversions in the ostreams and some
> reduction in the memory management complexity when using std::string.
> 2. Start converting the support library to use C++ data types like
> strings, streams and potentially STL containers. At this point, some
> of the other programs like fetchnews and texpire can also start
> benefiting from the C++ support.
> 3. Change the structure of programs to take advantage of C++.

The C++ change isn't meant to just translate from C to C++. I haven't
yet decided if I want to go with STL either, because it _easily_ bloats
the binary code. I'll also be looking at PTypes.

The stages you mention aren't very much to my intentions.

I'd think I'd identify how I can represent certain common data types as
classes, say, the article store, the "active" store and the overview
stuff. I really don't mind if _libraries_, trivial functions, are still
in C imperative style. There just isn't motivation to just throw stdio
out for the sake of it, because some time into the past, the whole stdio
stuff was analyzed, and string handling often has been changed to the
mastr() module that automatically extends memory as needed, so I'm not
having sleepless nights over buffer handling.

With respect to the library: that's the thing I'd bother about
converting last. If C++ allowed me to simplify code, I'd do it, if the
code doesn't lose complexity, I'd rather leave it alone.

Going into more detail: I've considered storing articles in wire format
(CRLF) for a long time now so that the server can use sendfile or just
mmap and write large chunks, and the first steps that allowed me to do
that was locking down the spool and no longer allowing clients access to
the spool. I don't know any decent newsreader that doesn't talk NNTP, if
someone knows one, speak up.

> Currently I'm in phase 1 and part of the nntp server is converted.
> I'll do the rest sometime this week and post the code on my website -
> I'll send an announcement to the list once that's done. The server is
> still stable :-) and although the C++ binary is considerably bigger on
> FreeBSD compared to the C version I didn't notice a performance
> degradation.

That's one of the STL misfeatures. You end up with a dozen
implementations of the same algorithm linked into the code :-(

> system yet. I'm not very familiar with autoconf so if anyone could
> extend the scripts to support C++ then I'd be grateful. For the time
> being I'll include a build script to compile the C++ code.

I'll clean that up when I merge the parts of the code that interest me.
As written above, I have no plans to just translate from C to C++, there
will be no benefit from that. The goal is to only use C++ where
switching makes the code easier to read or maintain, for example when
destructors save me the hassle of managing memory in each function.

Having said all that, I'll of course appreciate voluntary help with
leafnode, and if my pondering about "C++ or Python" may have been
premature, because it didn't mention plans when that would happen or

So, for the near future, I expect code cleanups and getting TODO items
done so that 2.0 can go out of the door. Some features will have to
wait until after 2.0.

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