0001-Detect-and-kill-unused-CoreSessions.patch
| src/core/core.cpp | ||
|---|---|---|
| 985 | 985 |
return settings; |
| 986 | 986 |
} |
| 987 | 987 | |
| 988 |
void Core::deleteCoreSession(UserId id) {
|
|
| 989 |
sessions.take(id)->deleteLater(); |
|
| 990 |
} |
|
| 988 | 991 | |
| 989 | 992 |
#ifdef Q_OS_WIN32 |
| 990 | 993 |
void Core::stdInEcho(bool on) {
|
| src/core/core.h | ||
|---|---|---|
| 391 | 391 |
void syncStorage(); |
| 392 | 392 |
void setupInternalClientSession(SignalProxy *proxy); |
| 393 | 393 | |
| 394 |
//! Delete an unused CoreSession and its corresponding thread |
|
| 395 |
/** \param id The UserId of the Session |
|
| 396 |
*/ |
|
| 397 |
void deleteCoreSession(UserId id); |
|
| 398 | ||
| 394 | 399 |
signals: |
| 395 | 400 |
//! Sent when a BufferInfo is updated in storage. |
| 396 | 401 |
void bufferInfoUpdated(UserId user, const BufferInfo &info); |
| src/core/coresession.cpp | ||
|---|---|---|
| 89 | 89 |
p->synchronize(ircListHelper()); |
| 90 | 90 |
p->synchronize(&_coreInfo); |
| 91 | 91 | |
| 92 |
// let core remove the session from its structures and delete it afterwards |
|
| 93 |
connect(this, SIGNAL(deleteCoreSession(UserId)), Core::instance(), SLOT(deleteCoreSession(UserId)), Qt::QueuedConnection); |
|
| 94 |
connect(this, SIGNAL(deleteCoreSessionLater(UserId)), this, SIGNAL(deleteCoreSession(UserId)), Qt::QueuedConnection); |
|
| 92 | 95 |
// Restore session state |
| 93 | 96 |
if(restoreState) |
| 94 |
restoreSessionState(); |
|
| 97 |
if(!restoreSessionState()) |
|
| 98 |
// if we have nothing to restore, this CoreSession is useless |
|
| 99 |
// until the user decides to connect |
|
| 100 |
emit deleteCoreSessionLater(_user); |
|
| 95 | 101 | |
| 96 | 102 |
emit initialized(); |
| 97 | 103 |
} |
| ... | ... | |
| 150 | 156 |
_bufferViewManager->saveBufferViews(); |
| 151 | 157 |
} |
| 152 | 158 | |
| 153 |
void CoreSession::restoreSessionState() {
|
|
| 159 |
bool CoreSession::restoreSessionState() {
|
|
| 154 | 160 |
QList<NetworkId> nets = Core::connectedNetworks(user()); |
| 161 | ||
| 162 |
if(nets.empty()) |
|
| 163 |
return false; |
|
| 164 | ||
| 155 | 165 |
CoreNetwork *net = 0; |
| 166 |
bool restored = false; |
|
| 156 | 167 |
foreach(NetworkId id, nets) {
|
| 157 | 168 |
net = network(id); |
| 158 | 169 |
Q_ASSERT(net); |
| 159 | 170 |
net->connectToIrc(); |
| 171 |
restored = true; |
|
| 160 | 172 |
} |
| 173 |
return restored; |
|
| 161 | 174 |
} |
| 162 | 175 | |
| 163 | 176 |
void CoreSession::addClient(QIODevice *device) {
|
| ... | ... | |
| 462 | 475 |
CoreNetwork *net = 0; |
| 463 | 476 |
IrcUser *me = 0; |
| 464 | 477 |
QString awayReason; |
| 478 |
bool activeNetworks = false; |
|
| 479 | ||
| 465 | 480 |
while(netIter != _networks.end()) {
|
| 466 | 481 |
net = *netIter; |
| 467 | 482 |
netIter++; |
| 468 | 483 | |
| 484 |
if(net->connectionState() != Network::Disconnected) |
|
| 485 |
activeNetworks = true; |
|
| 469 | 486 |
if(!net->isConnected()) |
| 470 | 487 |
continue; |
| 471 | 488 |
identity = net->identityPtr(); |
| ... | ... | |
| 482 | 499 |
net->userInputHandler()->handleAway(BufferInfo(), awayReason); |
| 483 | 500 |
} |
| 484 | 501 |
} |
| 502 |
// if no networks are active and the last client disconnected, we assume the session is useless |
|
| 503 |
if(!activeNetworks) |
|
| 504 |
emit deleteCoreSessionLater(_user); |
|
| 485 | 505 |
} |
| src/core/coresession.h | ||
|---|---|---|
| 68 | 68 | |
| 69 | 69 |
//! Return necessary data for restoring the session after restarting the core |
| 70 | 70 |
void saveSessionState() const; |
| 71 |
void restoreSessionState(); |
|
| 71 |
//! Restore session after restarting the core |
|
| 72 |
/** Returns true if anything is restored, false if not. |
|
| 73 |
*/ |
|
| 74 |
bool restoreSessionState(); |
|
| 72 | 75 | |
| 73 | 76 |
public slots: |
| 74 | 77 |
void addClient(QIODevice *device); |
| ... | ... | |
| 131 | 134 |
void networkCreated(NetworkId); |
| 132 | 135 |
void networkRemoved(NetworkId); |
| 133 | 136 | |
| 137 |
//! CoreSession assumed useless |
|
| 138 |
/** This signal is propagated to the core to request the destruction of the senders session. |
|
| 139 |
* \param id The UserId of this session |
|
| 140 |
*/ |
|
| 141 |
void deleteCoreSession(UserId id); |
|
| 142 | ||
| 143 |
//! CoreSession assumed useles |
|
| 144 |
/** This signal is only a helper to deleteCoreSession and emits that whenever the eventloop is |
|
| 145 |
* running. |
|
| 146 |
* \param id The UserId of this session |
|
| 147 |
*/ |
|
| 148 |
void deleteCoreSessionLater(UserId id); |
|
| 149 | ||
| 134 | 150 |
private slots: |
| 135 | 151 |
void removeClient(QIODevice *dev); |
| 136 | 152 | |
| 137 |
- |
|