Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
My feeling about the current API is that cNetwork has too many responsibilities. I feel it should be split up either into three classes, one handling DNS, one handling Connect and one handling Listen, or they should all be made into free functions.
I think that the best outcome would be to split the Network code into three sets of h/cpp files, one holding the two DNS free functions, one holding the connections code and one holding the TCPLink code as most code will need at most two of the files.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
If you split the code into multiple files, you will need to expose the internal implementation classes, because they are dependent on each other, as well as the cNetworkSingleton. My goal was to hide the implementation behind a facade that exposes only the minimum interface needed for usage, so that the internals may change dramatically without changing the interface.
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
Then maybe we need to put the implementation classes into headers of their own, like with the simulators. My worry is that Network.cpp is only going to grow and grow as people ask for additional features like UDP support. Also it can be difficult to understand the structure at the moment because the code is just a huge lump.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
The code can't be split without exposing cNetworkSingleton - most of the implementation relies on its internals. And I don't want to expose it, since it has libevent stuff in it, so we'd need to put libevent dependencies in the header.
I don't think the Network stuff is gonna grow much more. It's pretty much complete on the TCP side, and the UDP side can have a separate file of its own - after all, libevent doesn't have such a high level support for it anyway.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
And here I was, thinking that the Network code was actually pretty well written. You seem to be rather opposed to most of it, so how would you write it if you were to write it?
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
The code is fine. Its just what files to put it in I disagree about. Once we've sorted that out I reckon its ready to merge.
As for UDP, if UDP goes in a separate file then you need to expose cNetworkSingleton anyway, as UDP will depend on cNetworkSingleton. My feeling is that cNetworkSingleton should be exposed but we just don't use it outside OSSupport. Also if you add a method to access m_DNSBase and m_EventBase then you can get rid of the friend class. Yes it leaks the libevent abstraction but so does accessing them through friends.