How to control the boot up & shutdown sequence?
-
OK, in the beginning, i just the one asking horrible questions, now, I’m asking horrible questions + making horrible plugin….
So, i’m making a FLHook plugin (and a protocol, speak in JSON) that allows you to make your plugin to communicate with your website and do something interesting.
And, the code …
https://github.com/raincious/FLBoardYeah, i call it … Board, because itself does nothing but control and sending queues, i leave the actual work to you (to control what to send, and what to receive, and how to response to those received), just like a patch board.
There is the problem: This plugin (let’s say the Host) rely on other plugin (let’s say the Guest).
FLHook looks not allows a plugin to control other plugin’s unregisteration, and plugins looks don’t know each other’s exists (?).
So something could happen like:
// When normal
Host say: Do you want some tea?
(Wait)
Guest say: YesAnd when FLHook shuting down… something will become:
Host say: Do you want some tea?
(Wait)
(Wait)
(Wait)
(Wait)
…
// Yeah, guest already gone.Which may cause crash on shutdown and rehash. Just like i got in my plugin.
Well, it will not crash in my plugin in fact. But the calling progress looks keep handling (The function calls, but never return). It causes problem on thread shuting down.
So, any idea on how to solve this?
I attached a sub plugin used that uses FLBoard, you can try compile and run it and get some idea of that I’m saying.
(You also needs to use the index.php to setup a fake API responser)
Thank you!
How to compile:
The FLBoard and the test plugin is made with VS2013, it use come lib from NuGet which not support VS2008(?), so you have to compile it on VS2013 too.
1, Checkout the SVN to get latest FLHook src
2, Make a folder in <path to=“” your=“” flhook=“” checkout=“”>\plugins name it board, get the code and put those to the root of that folder.
3, Open <path to=“” your=“” flhook=“” checkout=“”>\project-vc12\FLHook.vcxproj with VS2013, add this project in to FLHook solution by right click the “‘FLHook’ Solution” -> Add -> Existing project.
4, Don’t forget to set the dependence by right click the “‘FLHook’ Solution” -> Find the item with word “Dependence” on it, click it, select Board Plugin from the drop down, and check the FLHook.
5, Build solution / board project.
And don’t forget, it also made in China. I already try as hard as i can to fix problems in this plugin (My first C++ program that reachs 1000 lines, I mainly write PHP and other language that no need to care about pointer and memory).
The Board Plugin looks putty stable now, as i tested by let it run for several hours, memory usage almost never changes. But this is my first C++ project, so, may be, there is something i don’t know.
Please review my code to help me improve it if you interested.
However, the test plugin turely have problem in
Plugin_ReceiveCrossServerAPIMessage
function. It will leak memory when can’t found the online player namedeventData.get(L"Receiver")
.This problem may caused by
HkGetClientIdFromCharname
. But it fine for a test.Just make sure you edited the index.php file and replaced the name in line 50 with a correct one.</path></path>
-
Plugin load order is alphabetical, so just name it 0_something or similar to ensure it always is loaded first.
I don’t know how plugin unloading order is handled, but it might just be the reverse of plugin load order.
-
FriendlyFire wrote:
Plugin load order is alphabetical, so just name it 0_something or similar to ensure it always is loaded first.I don’t know how plugin unloading order is handled, but it might just be the reverse of plugin load order.
Yes, it’s unloading behaves like doing reverse.
So in my case, the loading order be like:
board
status // test pluginunloading:
status
boardAnd problem happens.
I tried to use atexit, but looks it runs AFTER heap releasing, some data already lost, which causes more problem.
Let me try if i can to round of this.
-
Yeah, if that ordering doesn’t work for you, it’s a design problem with your plugin, not with Hook. That loading/unloading order is the only logical one.
-
FriendlyFire wrote:
Yeah, if that ordering doesn’t work for you, it’s a design problem with your plugin, not with Hook. That loading/unloading order is the only logical one.OK, i solved that problem.
I realize It’s wrong to resorting boot / shutdown sequence. All i need it to know the function is not exist any more.
So i made a function to let sub plugin creator to tell the board plugin about it.
However the mechanism to make it work needs to lock the specific function call for thread safe. Which make the efficiency across all threads become low.
But for FLServer + non-real time APIs, that’s far beyond enough.