Hi folks,

Anybody up for a complete rewrite of the Iotivity networking code?

For whatever reason I got a bug up my nose about it, so I have spent *many*
hours trying to understand it. I think I do grok it now - but only because
I have rewritten it.

It ain't easy.  No offense but the code seems designed to maximize
obfuscation.

Lots of g_* stuff, often populated at runtime by static functions. Which
defeats the purpose of static, and makes it virtually impossible to
understand the code by inspection.

For example, there is "select network" logic at runtime, which really means
"enable transport". But we already always know at build time which
transports are supported, so that's a waste.

That's just one example. There's also the "register callbacks" stuff. All
of which is unnecessary, just overhead. E.g. for UDP we know at build time
what the callbacks are, so there is no need to look them up at runtime.

And don't get me started on the inane naming. E.g. we have

CAStartIPListeningServer

And

CAIPStartListenServer

Huh? Try keeping that in your head when you're debugging, I double-dog dare
ya!

There are also major inefficiencies. Just look at CAFindReadyMessage.
Looping over the fds? Unroll the loop and you get code that is faster,
smaller, and more readable. Plus, actually reading the fastshutdownFds is
unnecessary, all that matters is that they force select to return.

All those macros, like ISSET or PUSH_SOCKET? They serve one purpose, AFAIK:
obfuscate the code. Make it as hard as possible for the next guy to
understand. Get rid of them and the code becomes much more grokable.

Long story short: I have spent many hours trying to grok the networking
stuff, and failing. So I just rewrote it in way that I think is much
clearer. YMMV.  Caveat: this is just for UDP.  But the other transports
should be workable with this strategy. Work in progress:
https://github.com/OpenOCF/iochibity/tree/master/src/comm/transport/udpip

Gregg

Reply via email to