Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
kasome is currently offline  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 #37163 is a reply to message #36887] Sun, 02 September 2012 10:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, at this moment, this usage scenario is unexplored teritory.

Anyway, your method does not look that bad, what are symptoms?

Mirek
Re: How to close Skylark server except using Ctrl+C [message #39844 is a reply to message #37163] Sun, 05 May 2013 20:20 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Hi,

I made some tests and it is possible to close skylark nicely, but there are two problems. First - quit flag is private, second "main" function waits for all threads in application.

Mirek, can you add Quit (public) method to skylark and modify Main?

void SkylarkApp::Quit()
{
	quit = true;
#ifdef PLATFORM_POSIX
	Broadcast(SIGTERM);
#endif
	TcpSocket s;
	s.Timeout(100);
	s.Connect("127.0.0.1", port);
}


void SkylarkApp::Main()
{
	Buffer<Thread> uwt(threads);
	for(int i = 0; i < threads; i++)
		uwt[i].Run(THISBACK(ThreadRun));
	
	/* Wait for threads to shut down */
	for (int i = 0; i < threads; i++)
		uwt[i].Wait();
}


Re: How to close Skylark server except using Ctrl+C [message #39855 is a reply to message #39844] Tue, 07 May 2013 04:30 Go to previous messageGo to next message
nlneilson is currently offline  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

Re: How to close Skylark server except using Ctrl+C [message #39862 is a reply to message #39855] Tue, 07 May 2013 09:45 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks, patch applied.

Mirek
Previous Topic: Skylark and GUI in one app - need some advices
Next Topic: Fatal error - GuiLock
Goto Forum:
  


Current Time: Thu Mar 28 15:55:06 CET 2024

Total time taken to generate the page: 0.01521 seconds