Project

General

Profile

Bug #9106 » 0001-Modified-hello-example-for-test-of-webrequest-leak.patch

Bruce Toll, 09/24/2021 07:49 PM

View differences:

examples/hello/hello.C
#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WDialog.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WServer.h>
#include <Wt/WTimer.h>
#include <Wt/WText.h>
#if !defined(WT_WIN32)
#include <signal.h>
#endif
#define STRSTREAM_LOG
#if defined(STRSTREAM_LOG)
#include <sstream>
#endif
/*
* A simple hello world application class which demonstrates how to react
* to events, read input, and give feed-back.
......
private:
Wt::WLineEdit *nameEdit_;
Wt::WText *greeting_;
Wt::Core::observing_ptr<Wt::WDialog> idleTimeoutDialog_;
void greet();
void idleTimeout() override;
};
/*
......
greeting_->setText("Hello there, " + nameEdit_->text());
}
void HelloApplication::idleTimeout()
{
log("info") << "HelloApplication: idleTimeout() called";
if (idleTimeoutDialog_)
return; // Prevent multiple dialogs
log("info") << "HelloApplication: idleTimeout() about to show dialog";
idleTimeoutDialog_ = addChild(Wt::cpp14::make_unique<Wt::WDialog>("Idle timeout"));
idleTimeoutDialog_->contents()->addNew<Wt::WText>("This session has timed-out, "
"press 'restart' to continue using the application");
auto btn = idleTimeoutDialog_->footer()->addNew<Wt::WPushButton>("restart");
btn->setLink(bookmarkUrl());
btn->setFocus();
idleTimeoutDialog_->show();
quit();
}
#if defined(STRSTREAM_LOG)
class BufferLog {
public:
~BufferLog() {
ss_ << std::ends;
std::cerr << ss_.str() << std::endl;
}
void setup() {
Wt::logInstance().setStream(ss_);
};
private:
std::ostringstream ss_;
};
#endif
int WRun(int argc, char *argv[], Wt::ApplicationCreator createApplication)
{
// insure buffered log contents are sent to stderr on exit
BufferLog bufferLog;
try {
Wt::WServer server(argv[0], "");
try {
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
// override the default log output established in setServerConfiguration
bufferLog.setup();
server.addEntryPoint(Wt::EntryPointType::Application, createApplication);
if (server.start()) {
#ifdef WT_THREADED
// MacOSX + valgrind:
// for (;;) { sleep(100); }
int sig = Wt::WServer::waitForShutdown();
Wt::log("info") << "shutdown (signal = " << sig << ")";
#endif
server.stop();
#ifdef WT_THREADED
#ifndef WT_WIN32
if (sig == SIGHUP)
// Mac OSX: _NSGetEnviron()
Wt::WServer::restart(argc, argv, nullptr);
#endif // WIN32
#endif // WT_THREADED
}
return 0;
} catch (std::exception& e) {
Wt::log("error") << "fatal: " << e.what();
return 1;
}
} catch (Wt::WServer::Exception& e) {
Wt::log("error") << "fatal: " << e.what();
return 1;
} catch (std::exception& e) {
Wt::log("error") << "fatal: " << e.what();
return 1;
}
}
int main(int argc, char **argv)
{
/*
......
* support. The function should return a newly instantiated application
* object.
*/
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
return WRun(argc, argv, [](const Wt::WEnvironment &env) {
/*
* You could read information from the environment to decide whether
* the user has permission to start a new application
examples/hello/wt_config.xml
<server>
<application-settings location="*">
<session-management>
<timeout>90</timeout>
<idle-timeout>120</idle-timeout>
</session-management>
<log-config>* -debug debug:websession debug:wthttp debug:wthttp/async</log-config>
<web-sockets>true</web-sockets>
</application-settings>
</server>
examples/hello/wt_config_less_debug.xml
<server>
<application-settings location="*">
<session-management>
<timeout>90</timeout>
<idle-timeout>120</idle-timeout>
</session-management>
<log-config>* -debug</log-config>
<web-sockets>true</web-sockets>
</application-settings>
</server>
src/http/WtReply.C
fetchMoreDataCallback_ = callBack;
if (sending_ != 0) {
LOG_DEBUG("WtReply::send(): still busy sending... ignoring");
LOG_INFO("WtReply::send(): still busy sending... ignoring");
return;
}
(1-1/4)