Home » U++ Library support » U++ MT-multithreading and servers » How to close Skylark server except using Ctrl+C
How to close Skylark server except using Ctrl+C [message #36887] |
Tue, 17 July 2012 04:46 |
kasome
Messages: 78 Registered: July 2008 Location: Taiwan
|
Member |
|
|
Hello,
i am trying to use the Skylark to do something like the following
class WebServer : public SkylarkApp {
public:
void StopServer();
void StartServer();
};
class SimpleGUI : public TopWindow , public WebServer {
public:
SimpleGUI() {
StartServer();
}
virtual ~SimpleGUI() {
StopServer();
}
}
GUI operation for desktop user, and web operation for smart phone user.
so i try to modify the code, like
class WebServer : public SkylarkApp {
public:
WebServer() {
Run();
}
virtual ~WebServer(){
}
void StopServer() {
TheApp().quit = true;
TcpSocket h;
h.Connect("127.0.0.1", TheApp().port);
h.Put("quit");
}
void StartServer() {
for( int i=0; i<threads; ++i ) {
Thread::Start( THISBACK(ThreadRun) );
}
}
virtual void Main() {
}
};
and it didn't work apparently,
well, is there better way to close Skylark server except using Ctrl+C ?
[Updated on: Tue, 17 July 2012 05:03] Report message to a moderator
|
|
|
|
|
Re: How to close Skylark server except using Ctrl+C [message #39855 is a reply to message #39844] |
Tue, 07 May 2013 04:30 |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
At least for my application in C++ and Java is to shut down threads INSIDE each individual thread.
void endX(){
endApp = true;
snd("clear61", 0);
Sleep(200);
snd("clear62", 0);
Sleep(200);
snd("clear63", 0);
Sleep(200);
snd("clear64", 0);
Sleep(200);
snd("clear", 0);
Sleep(2000);
if(CommPort1.IsOpened()) CommPort1.Close();
if(CommPort2.IsOpened()) CommPort2.Close();
}
GUI_APP_MAIN{
NefbG2().Run();
endX();
}
And in each thread something like this:
while(!inF.IsEof()){
if(endApp){if(inF) inF.Close(); break;}
if(Thread::IsShutdownThreads() || cF==1){
if(inF) inF.Close();
cF=0;
break;
}
Hope this helps as if an app opens a port and it is not closed properly it stays open when the app closes, plus other things happen that IS NOT nice to contend to.
edit: As mentioned try and close the threads inside the thread.
This is when the app exits or even to end a thread while the app is running.
[Updated on: Tue, 07 May 2013 04:41] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sat Apr 27 18:44:54 CEST 2024
Total time taken to generate the page: 0.58686 seconds
|