mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-17 18:29:19 +01:00
Fix exiting
This commit is contained in:
parent
258e93d01e
commit
6e2ea75917
@ -7,7 +7,6 @@ BackgroundThread *BackgroundThread::instance = nullptr;
|
|||||||
|
|
||||||
BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread::getPriority()) {
|
BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread::getPriority()) {
|
||||||
DEBUG_FUNCTION_LINE("Start FTP Server");
|
DEBUG_FUNCTION_LINE("Start FTP Server");
|
||||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
|
||||||
this->serverSocket = create_server(PORT);
|
this->serverSocket = create_server(PORT);
|
||||||
OSMemoryBarrier();
|
OSMemoryBarrier();
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Resume Thread");
|
DEBUG_FUNCTION_LINE_VERBOSE("Resume Thread");
|
||||||
@ -16,7 +15,6 @@ BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread:
|
|||||||
|
|
||||||
BackgroundThread::~BackgroundThread() {
|
BackgroundThread::~BackgroundThread() {
|
||||||
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
|
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
|
||||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
|
||||||
if (this->serverSocket >= 0) {
|
if (this->serverSocket >= 0) {
|
||||||
cleanup_ftp();
|
cleanup_ftp();
|
||||||
network_close(this->serverSocket);
|
network_close(this->serverSocket);
|
||||||
@ -25,15 +23,14 @@ BackgroundThread::~BackgroundThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOL BackgroundThread::whileLoop() {
|
BOOL BackgroundThread::whileLoop() {
|
||||||
std::lock_guard<std::recursive_mutex> lock(mutex);
|
|
||||||
if (this->serverSocket >= 0) {
|
if (this->serverSocket >= 0) {
|
||||||
network_down = process_ftp_events(this->serverSocket);
|
network_down = process_ftp_events(this->serverSocket);
|
||||||
if (network_down) {
|
if (network_down) {
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Network is down %d", this->serverSocket);
|
DEBUG_FUNCTION_LINE_WARN("Network is down");
|
||||||
cleanup_ftp();
|
cleanup_ftp();
|
||||||
network_close(this->serverSocket);
|
network_close(this->serverSocket);
|
||||||
this->serverSocket = -1;
|
this->serverSocket = -1;
|
||||||
DCFlushRange(&(this->serverSocket), 4);
|
OSMemoryBarrier();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->serverSocket = create_server(PORT);
|
this->serverSocket = create_server(PORT);
|
||||||
|
@ -11,7 +11,7 @@ public:
|
|||||||
static BackgroundThread *getInstance() {
|
static BackgroundThread *getInstance() {
|
||||||
if (instance == nullptr) {
|
if (instance == nullptr) {
|
||||||
instance = new BackgroundThread();
|
instance = new BackgroundThread();
|
||||||
DCFlushRange(&instance, 4);
|
OSMemoryBarrier();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@ -20,15 +20,9 @@ public:
|
|||||||
if (instance != nullptr) {
|
if (instance != nullptr) {
|
||||||
delete instance;
|
delete instance;
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
DCFlushRange(&instance, 4);
|
OSMemoryBarrier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void destroyInstance(bool forceKill) {
|
|
||||||
if (instance != nullptr) {
|
|
||||||
instance->skipJoin = true;
|
|
||||||
}
|
|
||||||
destroyInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
BackgroundThread();
|
BackgroundThread();
|
||||||
|
|
||||||
|
@ -55,10 +55,6 @@ ON_APPLICATION_START() {
|
|||||||
nn::ac::GetAssignedAddress(&hostIpAddress);
|
nn::ac::GetAssignedAddress(&hostIpAddress);
|
||||||
initLogging();
|
initLogging();
|
||||||
|
|
||||||
//Make sure the server instance is destroyed.
|
|
||||||
// Skipping joining the thread as it's not even running at this point but still may be allocated.
|
|
||||||
BackgroundThread::destroyInstance(true);
|
|
||||||
thread = nullptr;
|
|
||||||
if (gFTPServerEnabled) {
|
if (gFTPServerEnabled) {
|
||||||
startServer();
|
startServer();
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ protected:
|
|||||||
CThread::setThreadPriority(priority);
|
CThread::setThreadPriority(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::recursive_mutex mutex;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void executeThread() override;
|
void executeThread() override;
|
||||||
|
|
||||||
|
@ -101,22 +101,15 @@ public:
|
|||||||
|
|
||||||
//! Shutdown thread
|
//! Shutdown thread
|
||||||
virtual void shutdownThread() {
|
virtual void shutdownThread() {
|
||||||
if (skipJoin) {
|
//! wait for thread to finish
|
||||||
DEBUG_FUNCTION_LINE_WARN("Skip joining the thread \"%s\", it's not running.", pThreadName.c_str());
|
if (pThread && !(iAttributes & eAttributeDetach)) {
|
||||||
} else {
|
if (isThreadSuspended()) {
|
||||||
//! wait for thread to finish
|
resumeThread();
|
||||||
if (pThread && !(iAttributes & eAttributeDetach)) {
|
|
||||||
if (!isThreadTerminated()) {
|
|
||||||
if (isThreadSuspended()) {
|
|
||||||
resumeThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
OSJoinThread(pThread, nullptr);
|
|
||||||
} else {
|
|
||||||
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSJoinThread(pThread, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! free the thread stack buffer
|
//! free the thread stack buffer
|
||||||
if (pThreadStack) {
|
if (pThreadStack) {
|
||||||
free(pThreadStack);
|
free(pThreadStack);
|
||||||
@ -139,8 +132,6 @@ public:
|
|||||||
eAttributePinnedAff = 0x10
|
eAttributePinnedAff = 0x10
|
||||||
};
|
};
|
||||||
|
|
||||||
bool skipJoin = false;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int threadCallback(int argc, const char **argv) {
|
static int threadCallback(int argc, const char **argv) {
|
||||||
//! After call to start() continue with the internal function
|
//! After call to start() continue with the internal function
|
||||||
|
Loading…
Reference in New Issue
Block a user