Skip to content

Commit 980b62e

Browse files
author
Koen Deforche
committed
Several changes:
- SessionProcess: close all file descriptors after fork() - ProxyReply: properly close sockets as soon as possible - Wt::Dbo: force loading of a ptr when reading its version - fix #4580 WTableView/WAbstractItemView keyWentDown() signal not firing - fix layout mgr + animation interference - trying to fix heuristic for config files (#4560) - Wt::Dbo: added QueryModel::indexOf()
1 parent 09b2ba1 commit 980b62e

24 files changed

+282
-146
lines changed

CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,19 @@ IF(WIN32)
227227

228228
ELSE(WIN32)
229229

230-
SET(RUNDIR "${CMAKE_INSTALL_PREFIX}/var/run/wt" CACHE PATH
231-
"Default path for wt session management (only used by FCGI connector; not relative to CMAKE_INSTALL_PREFIX)")
230+
IF("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr")
231+
SET(CONFIG_PREFIX "")
232+
ELSEIF("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
233+
SET(CONFIG_PREFIX "")
234+
ELSE()
235+
SET(CONFIG_PREFIX ${CMAKE_INSTALL_PREFIX})
236+
ENDIF()
237+
238+
SET(RUNDIR "${CONFIG_PREFIX}/var/run/wt" CACHE PATH
239+
"Default path for wt session management (only used by FCGI connector)")
232240

233-
IF( NOT DEFINED CONFIGDIR )
234-
SET(CONFIGDIR "${CMAKE_INSTALL_PREFIX}/etc/wt" CACHE STRING "Path for the configuration files")
241+
IF(NOT DEFINED CONFIGDIR)
242+
SET(CONFIGDIR "${CONFIG_PREFIX}/etc/wt" CACHE STRING "Path for the configuration files")
235243
ENDIF( NOT DEFINED CONFIGDIR )
236244

237245
# If the user specifies the standard CMAKE_PREFIX_PATH to find packages,
@@ -292,6 +300,7 @@ SET(SKIA_PREFIX ${USERLIB_PREFIX} CACHE PATH
292300
"Prefix of skia library (overrides USERLIB_PREFIX)")
293301

294302
OPTION(DEBUG "Support for debugging, must be enabled also in wt_config.xml" OFF)
303+
295304
IF(CYGWIN)
296305
OPTION(BUILD_TESTS "Build Wt tests" OFF)
297306
ELSE(CYGWIN)

examples/wt-homepage/Home.C

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,18 @@ void Home::readReleases(WTable *releaseTable)
355355

356356
std::string fileName = *i;
357357
std::string description = *(++i);
358-
releaseTable->elementAt(row, 0)->addWidget
359-
(new WText(href("http://prdownloads.sourceforge.net/witty/"
360-
+ fileName + "?download", description)));
361358
releaseTable->elementAt(row, 1)->addWidget(new WText(*(++i)));
362359
releaseTable->elementAt(row, 2)->addWidget(new WText(*(++i)));
363360

361+
++i;
362+
std::string url = "http://prdownloads.sourceforge.net/witty/"
363+
+ fileName + "?download";
364+
if (i != tok.end())
365+
url = *i;
366+
367+
releaseTable->elementAt(row, 0)->addWidget
368+
(new WText(href(url, description)));
369+
364370
++row;
365371
}
366372
}

src/Wt/Dbo/QueryModel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ public:
195195
*/
196196
virtual Result& resultRow(int row);
197197

198+
/*! \brief Returns the index of row.
199+
*
200+
* If the row isn't contained in the model, returns -1.
201+
*/
202+
int indexOf(const Result& row) const;
203+
198204
/*! \brief Rereads the data from the database.
199205
*
200206
* This invalidates the current (cached) data and informs views that

src/Wt/Dbo/QueryModel_impl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ Result& QueryModel<Result>::resultRow(int row)
255255
return cache_[row - cacheStart_];
256256
}
257257

258+
template <class Result>
259+
int QueryModel<Result>::indexOf(const Result& result) const
260+
{
261+
for (int i = 0; i < rowCount(); ++i) {
262+
if (resultRow(i) == result)
263+
return i;
264+
}
265+
266+
return -1;
267+
}
268+
258269
template <class Result>
259270
void QueryModel<Result>::cacheRow(int row) const
260271
{

src/Wt/Dbo/ptr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public:
9999
virtual void setAutogeneratedId(long long id) = 0;
100100

101101
void setVersion(int version) { version_ = version; }
102-
int version() const { return version_; }
102+
virtual int version() const = 0;
103103
bool isTransient() const { return isNew() || isDeleted(); }
104104

105105
void setSession(Session *session) { session_ = session; }
@@ -137,9 +137,9 @@ public:
137137

138138
private:
139139
Session *session_;
140-
int version_;
141140

142141
protected:
142+
int version_;
143143
int state_;
144144
int refCount_;
145145

@@ -367,6 +367,8 @@ public:
367367
void setId(const IdType& id) { id_ = id; }
368368
IdType id() const { return id_; }
369369

370+
int version() const;
371+
370372
private:
371373
C *obj_;
372374
IdType id_;

src/Wt/Dbo/ptr_impl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ C *MetaDbo<C>::obj()
216216
return obj_;
217217
}
218218

219+
template <class C>
220+
int MetaDbo<C>::version() const
221+
{
222+
const_cast<MetaDbo<C> *>(this)->obj(); // Load the object
223+
224+
return version_;
225+
}
226+
219227
template <class C>
220228
MetaDbo<C>::MetaDbo(C *obj)
221229
: MetaDboBase(-1, New | NeedsSave, 0),

src/Wt/WRandom.C

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#include <boost/thread.hpp>
4646
#endif
4747

48+
#ifndef USE_NDT_RANDOM_DEVICE
49+
#include <stdlib.h>
50+
#endif
51+
4852
namespace {
4953
class RandomDevice
5054
{

src/Wt/WSvgImage.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void WSvgImage::drawImage(const WRectF& rect, const std::string& imgUri,
504504
makeNewGroup();
505505

506506
WApplication *app = WApplication::instance();
507-
std::string imageUri;
507+
std::string imageUri = imgUri;
508508
if (app)
509509
imageUri = app->resolveRelativeUrl(imgUri);
510510

src/Wt/WTableView.C

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ void WTableView::defineJavaScript()
763763
/* Two-lines needed for WT_PORT */
764764
EventSignalBase& ccScrolled = contentsContainer_->scrolled();
765765
connectObjJS(ccScrolled, "onContentsContainerScroll");
766+
767+
EventSignalBase& cKeyDown = canvas_->keyWentDown();
768+
connectObjJS(cKeyDown, "onkeydown");
766769
}
767770
}
768771

src/http/ProxyReply.C

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,29 @@ ProxyReply::ProxyReply(Request& request,
4343

4444
ProxyReply::~ProxyReply()
4545
{
46-
if (sessionProcess_ && sessionProcess_->sessionId().empty()) {
46+
if (sessionProcess_ && sessionProcess_->sessionId().empty())
4747
sessionProcess_->stop();
48-
}
49-
50-
boost::system::error_code ignored_ec;
51-
if(socket_.get()) {
52-
socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
53-
socket_->close();
54-
}
5548

49+
closeClientSocket();
50+
}
51+
52+
void ProxyReply::closeClientSocket()
53+
{
54+
if (socket_.get()) {
55+
boost::system::error_code ignored_ec;
56+
socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
57+
socket_->close();
58+
socket_.reset();
59+
}
5660
}
5761

5862
void ProxyReply::reset(const Wt::EntryPoint *ep)
5963
{
60-
if (sessionProcess_ && sessionProcess_->sessionId().empty()) {
64+
if (sessionProcess_ && sessionProcess_->sessionId().empty())
6165
sessionProcess_->stop();
62-
}
6366
sessionProcess_.reset();
64-
boost::system::error_code ignored_ec;
65-
if(socket_.get()) {
66-
socket_->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
67-
socket_->close();
68-
}
69-
socket_.reset();
67+
68+
closeClientSocket();
7069
contentType_.clear();
7170
requestBuf_.consume(requestBuf_.size());
7271
responseBuf_.consume(responseBuf_.size());
@@ -118,8 +117,10 @@ bool ProxyReply::consumeData(Buffer::const_iterator begin,
118117

119118
if (sessionProcess_) {
120119
// Connection with child already established, send request data
121-
asio::async_write(*socket_, asio::buffer(beginRequestBuf_, endRequestBuf_ - beginRequestBuf_),
122-
boost::bind(&ProxyReply::handleDataWritten,
120+
asio::async_write
121+
(*socket_,
122+
asio::buffer(beginRequestBuf_, endRequestBuf_ - beginRequestBuf_),
123+
boost::bind(&ProxyReply::handleDataWritten,
123124
boost::dynamic_pointer_cast<ProxyReply>(shared_from_this()),
124125
asio::placeholders::error,
125126
asio::placeholders::bytes_transferred));
@@ -150,7 +151,8 @@ bool ProxyReply::consumeData(Buffer::const_iterator begin,
150151
}
151152
}
152153

153-
// Don't immediately consume more data, but do this when it has been sent to child
154+
// Don't immediately consume more data, but do this when it has
155+
// been sent to child
154156
return false;
155157
}
156158

@@ -405,6 +407,8 @@ void ProxyReply::handleResponseRead(const boost::system::error_code &ec)
405407
|| ec == boost::asio::error::shut_down
406408
|| ec == boost::asio::error::operation_aborted
407409
|| ec == boost::asio::error::connection_reset) {
410+
closeClientSocket();
411+
408412
more_ = false;
409413

410414
if (request_.type != Request::TCP) {
@@ -465,6 +469,8 @@ bool ProxyReply::nextContentBuffers(std::vector<asio::const_buffer>& result)
465469

466470
void ProxyReply::error(status_type status)
467471
{
472+
closeClientSocket();
473+
468474
if (request_.type == Request::HTTP) {
469475
setStatus(status);
470476
setCloseConnection();
@@ -490,6 +496,8 @@ bool ProxyReply::sendReload()
490496
"if (window.Wt) window.Wt._p_.quit(null); window.location.reload(true);";
491497
send();
492498

499+
closeClientSocket();
500+
493501
return true;
494502
}
495503

0 commit comments

Comments
 (0)