Reworked the way the servers are started

This commit is contained in:
anschrammh 2022-10-04 08:27:21 +02:00
parent 59be94afb9
commit 6c53ee40e7
4 changed files with 51 additions and 11 deletions

View File

@ -39,12 +39,6 @@ class FTPServer : public TCPServer<T>
strcpy(_password, password); strcpy(_password, password);
} }
} }
_dataServer.begin(_dataPort);
}
void setCustomDataPort(unsigned int port)
{
_dataPort = port;
} }
virtual ~FTPServer() virtual ~FTPServer()
@ -53,7 +47,16 @@ class FTPServer : public TCPServer<T>
free(_username); free(_password); free(_FTPDir); free(_username); free(_password); free(_FTPDir);
} }
virtual void stop() virtual void start(void)
{
if(!TCPServer<T>::_serverStarted)
{
_dataServer.begin(_dataPort);
TCPServer<T>::start();
}
}
virtual void stop(void)
{ {
if(TCPServer<T>::_serverStarted) if(TCPServer<T>::_serverStarted)
{ {
@ -62,6 +65,21 @@ class FTPServer : public TCPServer<T>
} }
} }
virtual void setCustomDataPort(uint16_t port)
{
_dataPort = port;
if(TCPServer<T>::_serverStarted)
{
_dataServer.stop();
_dataServer.begin(_dataPort);
}
}
virtual uint16_t getCustomDataPort(void) const
{
return _dataPort;
}
virtual void setFTPDir(const char *FTPDir) virtual void setFTPDir(const char *FTPDir)
{ {
if(FTPDir) if(FTPDir)
@ -80,6 +98,11 @@ class FTPServer : public TCPServer<T>
} }
} }
virtual const char * getFTPDir(void)
{
return _FTPDir;
}
virtual void setUsername(const char *username) virtual void setUsername(const char *username)
{ {
if(username) if(username)
@ -98,6 +121,11 @@ class FTPServer : public TCPServer<T>
} }
} }
virtual const char * getUsername(void)
{
return _username;
}
virtual void setPassword(const char *password) virtual void setPassword(const char *password)
{ {
if(password) if(password)
@ -116,6 +144,11 @@ class FTPServer : public TCPServer<T>
} }
} }
virtual const char * getPassword(void)
{
return _password;
}
protected: protected:
virtual T* createNewClient(WiFiClient wc) virtual T* createNewClient(WiFiClient wc)
{ {

View File

@ -73,6 +73,8 @@ void SAB::initCommonConfig()
_dbWSServer.begin(); _dbWSServer.begin();
_webServer.enableTCPKeepAlive(15,5,5); _webServer.enableTCPKeepAlive(15,5,5);
_ftpServer.enableTCPKeepAlive(15,5,5); _ftpServer.enableTCPKeepAlive(15,5,5);
_webServer.start();
_ftpServer.start();
} }
void SAB::initGPIO() void SAB::initGPIO()

View File

@ -15,7 +15,7 @@ class TCPServer
public: public:
TCPServer(uint16_t port = 80, uint8_t maxClient = MAX_CLIENT, uint16_t clientDataBufferSize = 256) : _maxClient(maxClient), _clientDataBufferSize(clientDataBufferSize), _wifiServer(port) TCPServer(uint16_t port = 80, uint8_t maxClient = MAX_CLIENT, uint16_t clientDataBufferSize = 256) : _maxClient(maxClient), _clientDataBufferSize(clientDataBufferSize), _wifiServer(port)
{ {
_wifiServer.begin();
} }
virtual ~TCPServer() virtual ~TCPServer()
@ -44,11 +44,11 @@ class TCPServer
getClientData(); getClientData();
} }
virtual void start(uint16_t port = 0) virtual void start(uint16_t port = 0, uint8_t backlog = 5)
{ {
if(!_serverStarted) if(!_serverStarted)
{ {
!port ? _wifiServer.begin() : _wifiServer.begin(port) ; !port ? _wifiServer.begin(getPort()) : _wifiServer.begin(port, backlog) ;
_serverStarted = true; _serverStarted = true;
} }
} }
@ -206,7 +206,7 @@ class TCPServer
return freeId; return freeId;
} }
boolean _serverStarted = true; boolean _serverStarted = false;
uint8_t _maxClient, _TKACount = 0; uint8_t _maxClient, _TKACount = 0;
uint16_t _clientDataBufferSize, _TKAIdleSec = 0, _TKAIntvSec = 0; uint16_t _clientDataBufferSize, _TKAIdleSec = 0, _TKAIntvSec = 0;
WiFiServer _wifiServer; WiFiServer _wifiServer;

View File

@ -92,6 +92,11 @@ class WEBServer : public TCPServer<T>, public HttpConstants
_WWWDir = nullptr; _WWWDir = nullptr;
} }
} }
const char * getWWWDir(void) const
{
return _WWWDir;
}
protected: protected:
private: private:
virtual T* createNewClient(WiFiClient wc) virtual T* createNewClient(WiFiClient wc)