Gnutella Forums

Gnutella Forums (https://www.gnutellaforums.com/)
-   Gnucleus (Windows) (https://www.gnutellaforums.com/gnucleus-windows/)
-   -   Question on Gnucleus socket Close() (https://www.gnutellaforums.com/gnucleus-windows/8289-question-gnucleus-socket-close.html)

swabby March 1st, 2002 12:01 PM

Open the Gnucleus.cpp file, if you look in the initialize funtion you'll see that there are two lines.

m_pDoc = new CGnucleusDoc(this);
CFrameMain* pMainFrame = new CFrameMain(m_pDoc);

Both CGnucleusDoc and CFrameMain are created and referenced from CGnucleus which is the root node because it is the first class to be run on start up.

The structure represents the fold down on gnucleus, CGnucleus is created, CGnucleus creates CGnucleusDoc and CFrameMain, CGnucleusDoc creates CGnuControl and all the other important data type classes like preferences, chat, sharing, and the cache. When CFrameMain is initialized it creates things like the window, the toolbar, the menu and it also is in charge of creating new windows, we call this the view.

Its called document/view architechture, the data of a program and all the processing to the data is in the document, which is seperate from the view which simply displays the data.

Step throuh the constructors of the program and you can see this, the program is nicely laid out, and the structure picture is a great help in getting from point a in the code to point b.

Thanks for the questions, I like going through the code and verifying things. Thanks too for the typo fix, once I install visio again I'll make sure I change that and update the page. I just put up a screenshots section last night, check it out. :)

Moak March 1st, 2002 12:12 PM

Ah, I had an older version of your code again (using CVS now).

Now you create the CGnuControll object in CGnucleusDoc, but the timer function for CGnuControll are still feed via CFrameMain (m_pComm = m_pDoc->m_pComm)...

About nice layout, well, in this particular case you might want encapsulate the timer for the network functions into the network class. For exmaple SetTimer() is a Win32 API functions that allows callback too, then you don't need to send a WM_TIMER via the viewport and the whole way down to a subclass. When using a MFC wrapper, CWnd::SetTimer allows callback too.

Greets, Moak

swabby March 1st, 2002 12:27 PM

The Timer in CFrameMain is a global timer, it handles all the sockets, chat, cleaning of old memory, everything. It is centrallized like this so that accurate statistics can be made on the status of gnucleus.

Moak March 1st, 2002 12:39 PM

Perhaps you want to show those dependencies also in the 'structure'? I prefer no crossover dependencies, however, it's your code... see it as a suggestion. I just found this when looking into your code about network timers. Then I reported what was irritating in my eyes.

Have a nice weekend, Moak

swabby March 1st, 2002 12:51 PM

The stucture represents what creates what, because if you want to access say a download that is going from the transfer window, you would look at the stucture and say, 'ok first i have to get a pointer to the frame, that will give me a pointer to the root, from the root i can get to the document, from the document i can get to the socket controller (cgnucontrol) and from there the download socket list.

There are many many interactions between classes, and thats because its a normal application and class interaction is normal.

Have a nice weekend also, sooo much code to write...

Moak March 1st, 2002 04:41 PM

SetTimer() vs timeSetEvent()
 
PS: I did finally decide to avoid SetTimer in my project, since I don't have a viewport/window handle in my later network class (designed to work in a DLL) and also WM_TIMER message has some bottlenecks. If you're interested read http://www.codeproject.com/system/simpletime.asp - especially the last part in the "WM_TIMER" paragraph. I think I will use an own worker thread inside the server network class (or a multimedia timer with timeSetEvent()), this can also handle notifies for finished DNS resolution or friendly TCP disconnects.

Happy coding... Moak

PS: CGnuNod::m_nSecsAlive might be better a DWORD instead of an int, it's the same on standart MS Windows architectures, but you never know your target.

Moak March 5th, 2002 03:57 PM

CriticalSection/Mutex
 
Hi again Swabby,
what I wonder... you use a mutex (e.g. CCriticalSection CGnuControl::m_NodeAccess) only on write access to your socket lists (adding/removing nodes), but not also on read access (broadcasting packets). I don't think that std::vector<> is thread safe. I did cross check with Mutella, and Max does use a Mutex on read and write access - which is what i do usually too.

I would expect unexpectable behaviours in Gnucleus - or did I overprotect my code?

Greets, Moak

swabby March 5th, 2002 04:08 PM

Not sure, I'll look at it.


All times are GMT -7. The time now is 01:05 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 ©2011, Crawlability, Inc.

Copyright © 2020 Gnutella Forums.
All Rights Reserved.