Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.



memcheck example 6: how to stop a Wt server is a
memcheck example that tests how to stop a Wt server cleanly.
This example was developed, because tools like valgrind
and the profiler gprof require a program to quit without errors.
This web application creates four buttons, that each use a different way to let main
return. Of these four buttons, two are disabled: these call methods that do not cause
the application to terminate (yet). When starting the web application from command line, pressing CTRL-C
is another option to cleanly terminate it.
Technical facts
Operating system(s) or programming environment(s)
IDE(s):
Project type:
C++ standard:
Compiler(s):
Libraries used:
STL: GNU ISO C++ Library, version 4.9.2
Qt project file: ./CppMemcheckExample6/CppMemcheckExample6.pro
./CppMemcheckExample6/main.cpp
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
//#include <Wt/WLineEdit>
#include <Wt/WPushButton>
//#include <Wt/WText>
#include <Wt/WServer>
struct ApplicationCppValgrindExample6 : public Wt::WApplication
{
ApplicationCppValgrindExample6(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
this->setTitle("CppValgrindExample6");
{
Wt::WPushButton * button = new Wt::WPushButton("Call std::exit(0)");
button->clicked().connect(this,&ApplicationCppValgrindExample6::DoExit);
this->root()->addWidget(button);
}
{
Wt::WPushButton * button = new Wt::WPushButton("Call Wt::WServer::waitForShutdown and Wt::WServer::stop");
button->setEnabled(false);
button->clicked().connect(this,&ApplicationCppValgrindExample6::DoStop1);
this->root()->addWidget(button);
}
{
Wt::WPushButton * button = new Wt::WPushButton("Call Wt::WServer::stop");
button->setEnabled(false);
button->clicked().connect(this,&ApplicationCppValgrindExample6::DoStop2);
this->root()->addWidget(button);
}
{
Wt::WPushButton * button = new Wt::WPushButton("Throw");
button->clicked().connect(this,&ApplicationCppValgrindExample6::DoThrow);
this->root()->addWidget(button);
}
}
void DoExit() { std::exit(0); }
void DoStop1()
{
Wt::WServer::instance()->waitForShutdown();
Wt::WServer::instance()->stop();
}
void DoStop2() { Wt::WServer::instance()->stop(); }
void DoThrow() { throw; }
};
Wt::WApplication * CreateApplication(const Wt::WEnvironment& env)
{
return new ApplicationCppValgrindExample6(env);
}
int main(int, char *argv[])
{
//C++0x initializer list
const char * const v[7] =
{
argv[0],
"--docroot", ".",
"--http-port", "8080",
"--http-address", "0.0.0.0"
};
return WRun(7, const_cast<char**>(v), &CreateApplication);
}
|
./CppMemcheckExample6/valgrind_memcheck.sh
#!/bin/sh
valgrind --leak-check=full -v --show-reachable=yes --log-file=valgrind_memcheck.txt ../CppValgrindExample6-build-desktop/./CppValgrindExample6
|
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.

This page has been created by the tool CodeToHtml