mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-17 10:19:23 +01:00
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include "BackgroundThread.hpp"
|
|
#include "ftp.h"
|
|
#include "net.h"
|
|
#include <sys/socket.h>
|
|
|
|
BackgroundThread *BackgroundThread::instance = nullptr;
|
|
|
|
BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread::getPriority()) {
|
|
DEBUG_FUNCTION_LINE("Start FTP Server");
|
|
this->serverSocket = create_server(PORT);
|
|
OSMemoryBarrier();
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Resume Thread");
|
|
CThread::resumeThread();
|
|
}
|
|
|
|
BackgroundThread::~BackgroundThread() {
|
|
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
|
|
if (this->serverSocket >= 0) {
|
|
cleanup_ftp();
|
|
network_close(this->serverSocket);
|
|
this->serverSocket = -1;
|
|
}
|
|
}
|
|
|
|
BOOL BackgroundThread::whileLoop() {
|
|
if (this->serverSocket >= 0) {
|
|
network_down = process_ftp_events(this->serverSocket);
|
|
if (network_down) {
|
|
DEBUG_FUNCTION_LINE_WARN("Network is down");
|
|
cleanup_ftp();
|
|
network_close(this->serverSocket);
|
|
this->serverSocket = -1;
|
|
OSMemoryBarrier();
|
|
}
|
|
} else {
|
|
this->serverSocket = create_server(PORT);
|
|
if (this->serverSocket < 0) {
|
|
if (errno != EBUSY) {
|
|
DEBUG_FUNCTION_LINE_WARN("Creating server failed: %d", errno);
|
|
}
|
|
OSSleepTicks(OSMillisecondsToTicks(10));
|
|
}
|
|
}
|
|
return true;
|
|
}
|