Added a 'non-abortable' flag to the signout request. Re-enabled cancelling
ongoing downloads to allow for a quicker exit of STK.
This commit is contained in:
parent
c62cc7fbaa
commit
49a9ac54d5
@ -322,7 +322,8 @@ namespace Online
|
|||||||
|
|
||||||
// Check if we are asked to abort the download. If so, signal this
|
// Check if we are asked to abort the download. If so, signal this
|
||||||
// back to libcurl by returning a non-zero status.
|
// back to libcurl by returning a non-zero status.
|
||||||
if(request_manager->getAbort() || request->isCancelled() )
|
if( (request_manager->getAbort() || request->isCancelled()) &&
|
||||||
|
request->isAbortable() )
|
||||||
{
|
{
|
||||||
// Indicates to abort the current download, which means that this
|
// Indicates to abort the current download, which means that this
|
||||||
// thread will go back to the mainloop and handle the next request.
|
// thread will go back to the mainloop and handle the next request.
|
||||||
|
@ -240,6 +240,7 @@ namespace Online
|
|||||||
m_player->setUserDetails(this,
|
m_player->setUserDetails(this,
|
||||||
UserConfigParams::m_remember_user ? "client-quit"
|
UserConfigParams::m_remember_user ? "client-quit"
|
||||||
:"disconnect");
|
:"disconnect");
|
||||||
|
setAbortable(false);
|
||||||
} // SignOutRequest
|
} // SignOutRequest
|
||||||
}; // SignOutRequest
|
}; // SignOutRequest
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
|
@ -44,6 +44,7 @@ namespace Online
|
|||||||
{
|
{
|
||||||
m_cancel.setAtomic(false);
|
m_cancel.setAtomic(false);
|
||||||
m_state.setAtomic(S_PREPARING);
|
m_state.setAtomic(S_PREPARING);
|
||||||
|
m_is_abortable.setAtomic(true);
|
||||||
} // Request
|
} // Request
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
@ -105,6 +105,12 @@ namespace Online
|
|||||||
|
|
||||||
/** Cancel this request if it is active. */
|
/** Cancel this request if it is active. */
|
||||||
Synchronised<bool> m_cancel;
|
Synchronised<bool> m_cancel;
|
||||||
|
|
||||||
|
/** If this request can be aborted (at the end of STK). Most requests
|
||||||
|
* can, except the (final) logout and client-quit/signout-request,
|
||||||
|
* which must be finished even when STK is quitting. */
|
||||||
|
Synchronised<bool> m_is_abortable;
|
||||||
|
|
||||||
/** Set to though if the reply of the request is in and callbacks are
|
/** Set to though if the reply of the request is in and callbacks are
|
||||||
* executed */
|
* executed */
|
||||||
Synchronised<State> m_state;
|
Synchronised<State> m_state;
|
||||||
@ -156,6 +162,12 @@ namespace Online
|
|||||||
/** Returns if this request is to be canceled. */
|
/** Returns if this request is to be canceled. */
|
||||||
bool isCancelled() const { return m_cancel.getAtomic(); }
|
bool isCancelled() const { return m_cancel.getAtomic(); }
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
/** Returns if this request can be aborted. */
|
||||||
|
bool isAbortable() const { return m_is_abortable.getAtomic(); }
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
/** Sets if this request is abortable or not. */
|
||||||
|
void setAbortable(bool b) { m_is_abortable.setAtomic(b); }
|
||||||
|
// --------------------------------------------------------------------
|
||||||
/** Sets the request state to busy. */
|
/** Sets the request state to busy. */
|
||||||
void setBusy()
|
void setBusy()
|
||||||
{
|
{
|
||||||
|
@ -147,28 +147,26 @@ namespace Online
|
|||||||
*/
|
*/
|
||||||
void RequestManager::stopNetworkThread()
|
void RequestManager::stopNetworkThread()
|
||||||
{
|
{
|
||||||
// If a download should be active (which means it was cancelled by the
|
// This will queue a sign-out or client-quit request
|
||||||
// user, in which case it will still be ongoing in the background)
|
|
||||||
// we can't get the mutex, and would have to wait for a timeout,
|
|
||||||
// and we couldn't finish STK. This way we request an abort of
|
|
||||||
// a download, which mean we can get the mutex and ask the service
|
|
||||||
// thread here to cancel properly.
|
|
||||||
//cancelAllDownloads(); FIXME if used this way it also cancels the client-quit action
|
|
||||||
PlayerManager::onSTKQuit();
|
PlayerManager::onSTKQuit();
|
||||||
addRequest(new Request(true, HTTP_MAX_PRIORITY, Request::RT_QUIT));
|
|
||||||
} // stopNetworkThread
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// Put in a high priortity quit request in. It has the same priority
|
||||||
/** Signals to the progress function to request any ongoing download to be
|
// as a sign-out request (so the sign-out will be executed before the
|
||||||
* cancelled. This function can also be called if there is actually no
|
// quit request).
|
||||||
* download atm. The function progressDownload checks m_abort and will
|
Request *quit = new Request(true, HTTP_MAX_PRIORITY, Request::RT_QUIT);
|
||||||
* return a non-zero value which causes libcurl to abort. */
|
quit->setAbortable(false);
|
||||||
void RequestManager::cancelAllDownloads()
|
addRequest(quit);
|
||||||
{
|
|
||||||
|
// It is possible that downloads are still ongoing (either an addon
|
||||||
|
// download that the user aborted, or the addon icons etc are still
|
||||||
|
// queued). In order to allow a quick exit of stk we set a flag that
|
||||||
|
// will cause libcurl to abort downloading asap, and then allow the
|
||||||
|
// other requests (sign-out and quit) to be executed asap. Note that
|
||||||
|
// the sign-out request is set to be not abortable, so it still will
|
||||||
|
// be executed (before the quit request is executed, which causes this
|
||||||
|
// thread to exit).
|
||||||
m_abort.setAtomic(true);
|
m_abort.setAtomic(true);
|
||||||
// FIXME doesn't get called at the moment. When using this again,
|
} // stopNetworkThread
|
||||||
// be sure that HTTP_MAX_PRIORITY requests still get executed.
|
|
||||||
} // cancelAllDownloads
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Inserts a request into the queue of all requests. The request will be
|
/** Inserts a request into the queue of all requests. The request will be
|
||||||
|
@ -102,7 +102,6 @@ namespace Online
|
|||||||
static bool isRunning();
|
static bool isRunning();
|
||||||
|
|
||||||
void addRequest(Online::Request *request);
|
void addRequest(Online::Request *request);
|
||||||
void cancelAllDownloads();
|
|
||||||
void startNetworkThread();
|
void startNetworkThread();
|
||||||
void stopNetworkThread();
|
void stopNetworkThread();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user