mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-30 07:37:14 +02:00
use native contructor and destructor to initialize WSclient_t
This commit is contained in:
@ -258,7 +258,19 @@ typedef struct {
|
|||||||
uint8_t * maskKey;
|
uint8_t * maskKey;
|
||||||
} WSMessageHeader_t;
|
} WSMessageHeader_t;
|
||||||
|
|
||||||
typedef struct {
|
struct WSclient_t {
|
||||||
|
|
||||||
|
WSclient_t() = default;
|
||||||
|
|
||||||
|
WSclient_t(uint8_t num, uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount):
|
||||||
|
num(num),
|
||||||
|
status(WSC_NOT_CONNECTED),
|
||||||
|
pingInterval(pingInterval),
|
||||||
|
pongTimeout(pongTimeout),
|
||||||
|
disconnectTimeoutCount(disconnectTimeoutCount)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t num; ///< connection number
|
uint8_t num; ///< connection number
|
||||||
|
|
||||||
WSclientsStatus_t status;
|
WSclientsStatus_t status;
|
||||||
@ -309,7 +321,7 @@ typedef struct {
|
|||||||
String cHttpLine; ///< HTTP header lines
|
String cHttpLine; ///< HTTP header lines
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} WSclient_t;
|
};
|
||||||
|
|
||||||
class WebSockets {
|
class WebSockets {
|
||||||
protected:
|
protected:
|
||||||
|
@ -41,6 +41,8 @@ class WebSockets4WebServer : public WebSocketsServerCore {
|
|||||||
onEvent(event);
|
onEvent(event);
|
||||||
|
|
||||||
return [&, wsRootDir](const String & method, const String & url, WiFiClient * tcpClient, ESP8266WebServer::ContentTypeFunction contentType) {
|
return [&, wsRootDir](const String & method, const String & url, WiFiClient * tcpClient, ESP8266WebServer::ContentTypeFunction contentType) {
|
||||||
|
(void)contentType;
|
||||||
|
|
||||||
if(!(method == "GET" && url.indexOf(wsRootDir) == 0)) {
|
if(!(method == "GET" && url.indexOf(wsRootDir) == 0)) {
|
||||||
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
|
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,6 @@ WebSocketsServerCore::WebSocketsServerCore(const String & origin, const String &
|
|||||||
_httpHeaderValidationFunc = NULL;
|
_httpHeaderValidationFunc = NULL;
|
||||||
_mandatoryHttpHeaders = NULL;
|
_mandatoryHttpHeaders = NULL;
|
||||||
_mandatoryHttpHeaderCount = 0;
|
_mandatoryHttpHeaderCount = 0;
|
||||||
|
|
||||||
memset(&_clients[0], 0x00, (sizeof(WSclient_t) * WEBSOCKETS_SERVER_CLIENT_MAX));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketsServer::WebSocketsServer(uint16_t port, const String & origin, const String & protocol)
|
WebSocketsServer::WebSocketsServer(uint16_t port, const String & origin, const String & protocol)
|
||||||
@ -73,47 +71,15 @@ WebSocketsServer::~WebSocketsServer() {
|
|||||||
* called to initialize the Websocket server
|
* called to initialize the Websocket server
|
||||||
*/
|
*/
|
||||||
void WebSocketsServerCore::begin(void) {
|
void WebSocketsServerCore::begin(void) {
|
||||||
WSclient_t * client;
|
|
||||||
|
|
||||||
// init client storage
|
// init client storage
|
||||||
for(uint8_t i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
|
for (int i = 0; i < WEBSOCKETS_SERVER_CLIENT_MAX; i++) {
|
||||||
client = &_clients[i];
|
WSclient_t * client = &_clients[i];
|
||||||
|
|
||||||
client->num = i;
|
// reset instance:
|
||||||
client->status = WSC_NOT_CONNECTED;
|
// destructor in place
|
||||||
client->tcp = NULL;
|
client->~WSclient_t();
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32)
|
// constructor in place
|
||||||
client->isSSL = false;
|
new (client) WSclient_t(i, _pingInterval, _pongTimeout, _disconnectTimeoutCount);
|
||||||
client->ssl = NULL;
|
|
||||||
#endif
|
|
||||||
client->cUrl = "";
|
|
||||||
client->cCode = 0;
|
|
||||||
|
|
||||||
client->cIsClient = false;
|
|
||||||
client->cIsUpgrade = false;
|
|
||||||
client->cIsWebsocket = false;
|
|
||||||
|
|
||||||
client->cSessionId = "";
|
|
||||||
client->cKey = "";
|
|
||||||
client->cAccept = "";
|
|
||||||
client->cProtocol = "";
|
|
||||||
client->cExtensions = "";
|
|
||||||
client->cVersion = 0;
|
|
||||||
|
|
||||||
client->cWsRXsize = 0;
|
|
||||||
|
|
||||||
client->base64Authorization = "";
|
|
||||||
client->plainAuthorization = "";
|
|
||||||
|
|
||||||
client->extraHeaders = "";
|
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
|
||||||
client->cHttpLine = "";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
client->pingInterval = _pingInterval;
|
|
||||||
client->pongTimeout = _pongTimeout;
|
|
||||||
client->disconnectTimeoutCount = _disconnectTimeoutCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
|
Reference in New Issue
Block a user