This patch does significant cleanup on the join code by using strtok_r instead of mangling strchr to parse channel names and keys in parallel when a JOIN command contains a list of channels and keys.
since strtok_r is not universally portable, Florian was kind enough to provide a working /src/portab/strtok_r.c which I've included into the configure path.
I'd like to more widely move the codebase from using strtok to using strtok_r where possible. A few reasons for this:
1) strtok_r and strtok are the same speed and functionality. there are no compelling reasons to pick strtok() over strtok_r() outside of portability. Since strtok_r is fairly universal (all modern operating systems support it in their standard libraries), and a solid implementation exists in /src/portab, portability is not a compelling concern.
2) strtok_r will alleviate concerns about program state in the future. This is important because functions may need to tokenize strings while a function higher in the stack has not completed tokenization on a different string. This would lead to incorrect behaviour. By using strtok_r, this is no longer a concern when adding features or fixing bugs.
There are other reasons, but most of them relate to thread-safety. While ngircd could benefit from having worker threads processing server input (since reading from a socket is a low cost operation compared to actually processing the input), this isn't a very good argument for ngircd at the moment. There are more useful ways to make ngircd faster at the moment that don't include reorganizing vast swaths of code. More on that later.
Anyway, back to the original point: this patch cleans up IRC_JOIN considerably and provides strtok_r() for future use through /src/portab.
The attached patch applies with no warnings to the latest git head.
./scott
Scott Perry scperry@ucsd.edu wrote:
This patch does significant cleanup on the join code by using strtok_r instead of mangling strchr to parse channel names and keys in parallel when a JOIN command contains a list of channels and keys.
Added to my tree, thanks Scott. If there are no objections i'll push it to ngircd.git soon. http://git.breakpoint.cc/cgi-bin/gitweb.cgi?p=fw/ngircd-fw.git;a=commitdiff;...
Hi!
Am 26.05.2008 um 13:05 schrieb Florian Westphal:
Scott Perry scperry@ucsd.edu wrote:
This patch does significant cleanup on the join code by using strtok_r instead of mangling strchr to parse channel names and keys in parallel when a JOIN command contains a list of channels and keys.
Added to my tree, thanks Scott. If there are no objections i'll push it to ngircd.git soon. http://git.breakpoint.cc/cgi-bin/gitweb.cgi?p=fw/ngircd-fw.git;a=commitdiff;...
Looking at the patch from Scott I missed something ... but the above patch looks complete :-) I'm fine with it.
Regards Alex