Page 1 of 1

ServerApplication oddity

Posted: 30 Aug 2014, 21:48
by AjK

Looking to try to get a very minor contrib in.

Basically I recently wrote a small proof of concept program in C using libevent for the Windows platform. All went well and so I decided to switch to Poco/C++

Again, all was going well until I reached the main loop. In the C program in main() it runs something like this:-

Code: Select all

while (WaitForSingleObject(ghSvcStopEvent, 0) != WAIT_OBJECT_0) {
  event_base_loop(p_evbase, EVLOOP_ONCE | EVLOOP_NONBLOCK);

where ghSvcStopEvent is signalled externally by the SCM.

However, in the ServerApplication it essentially wanted me to waitForTerminationRequest();

Now here's the thing, libevent has an event loop and I have to signal it to terminate or run once non-blocking in my own while loop. But either of these mean I need to see if the termination event has fired.

And in ServerApplication the _terminated event is private and there's no "getter" for it. So I have no way to see the event.

My solution was to hack ServerApplication.h and add the protected function:-

Code: Select all

bool isTerminateSignalled() { return _terminated.tryWait(0); }

Now, it would be nice to add that into the main tree to save me re-adding it through updates.

Do I have to fork the Poco World and do a pull request for something this minor?

thanks for your time

Re: ServerApplication oddity

Posted: 31 Aug 2014, 01:52
by alex
AjK wrote:Do I have to fork the Poco World and do a pull request for something this minor?

yes, please. also, add a test for it and pay attention to coding style guide.

Re: ServerApplication oddity

Posted: 31 Aug 2014, 08:57
by guenter
And make sure it works on non-Windows platforms which do not use Poco::Event for signalling...

Re: ServerApplication oddity

Posted: 03 Sep 2014, 01:02
by AjK
Alex, Guenter

Thanks for the reply, I will follow that route. In fact I just forked it and cloned to my Linux and Windows machines (I usually start with Linux as it's just easy to get stuff done).

As normal, first step is to run a clean build with passing unit tests. While they are off doing that (takes a while) I started looking at the Util test suites to see where I could start by adding a test for the change I propose.

Hmm, there currently seems to be no tests for Application or ServerApplication, seems like I have a bit more to do to add a one line inline header function!

I'll let you know on this forum thread how I get on and ask for rfc before making a pull request.

Thanks again for your time.

Oh and I don't have access to a Mac to test the build on that platform. Hopefully I can find some friendly Mac user at PR time :)


Re: ServerApplication oddity

Posted: 03 Sep 2014, 01:43
by alex
We'll test on Mac.

My reply about adding test was a default one as we often get contributions that should have tests but don't. That said, I would not object if you add Application tests but will not turn down the contribution without it, either. Just make sure it works on Linux and Windows. I think Mac should behave same as Linux.