8000 Remove circular dependency · proddy/esp32_https_server@4a5e358 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a5e358

Browse files
committed
Remove circular d 10000 ependency
1 parent 24b838a commit 4a5e358

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

src/ConnectionContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ ConnectionContext::~ConnectionContext() {
1010

1111
}
1212

13+
void ConnectionContext::setWebsocketHandler(WebsocketHandler *wsHandler) {
14+
_wsHandler = wsHandler;
15+
}
16+
1317
} /* namespace httpsserver */

src/ConnectionContext.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class ConnectionContext {
2626
virtual size_t writeBuffer(byte* buffer, size_t length) = 0;
2727

2828
virtual bool isSecure() = 0;
29-
virtual void setWebsocketHandler(WebsocketHandler *wsHandler) = 0;
29+
virtual void setWebsocketHandler(WebsocketHandler *wsHandler);
30+
31+
WebsocketHandler * _wsHandler;
3032
};
3133

3234
} /* namespace httpsserver */

src/HTTPConnection.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,6 @@ size_t HTTPConnection::getCacheSize() {
331331
return (_isKeepAlive ? HTTPS_KEEPALIVE_CACHESIZE : 0);
332332
}
333333

334-
void HTTPConnection::setWebsocketHandler(WebsocketHandler *wsHandler) {
335-
_wsHandler = wsHandler;
336-
}
337-
338334
void HTTPConnection::loop() {
339335
// First, update the buffer
340336
// newByteCount will contain the number of new bytes that have to be processed

src/HTTPConnection.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
#include "HTTPRequest.hpp"
2121
#include "HTTPResponse.hpp"
2222
#include "ConnectionContext.hpp"
23+
#include "Websocket.hpp"
2324

2425
namespace httpsserver {
2526

26-
class Websocket;
27-
2827
class HTTPConnection : private ConnectionContext {
29-
friend class Websocket;
3028
public:
3129
HTTPConnection(ResourceResolver * resResolver);
3230
virtual ~HTTPConnection();
@@ -38,7 +36,6 @@ class HTTPConnection : private ConnectionContext {
3836
void loop();
3937
bool isClosed();
4038
bool isError();
41-
void setWebsocketHandler(WebsocketHandler *wsHandler);
4239

4340
protected:
4441
friend class HTTPRequest;
@@ -151,7 +148,6 @@ class HTTPConnection : private ConnectionContext {
151148
bool _isKeepAlive;
152149

153150
//Websocket connection
154-
WebsocketHandler * _wsHandler;
155151
Websocket * _websocket;
156152

157153
};

src/Websocket.cpp

Lines changed: 3 additions & 4 deletions
67F4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void WebsocketHandler::onError(std::string error) {
8989
} // onError
9090

9191

92-
Websocket::Websocket(HTTPConnection *con) {
92+
Websocket::Websocket(ConnectionContext *con) {
9393
_con = con;
9494
_receivedClose = false;
9595
_sentClose = false;
@@ -102,7 +102,6 @@ Websocket::~Websocket() {
102102

103103
int Websocket::read() {
104104
Frame frame;
105-
_con->updateBuffer();
106105
int length = _con->readBuffer((uint8_t*)&frame, sizeof(frame));
107106
HTTPS_DLOGHEX("[ ] read bytes:", length);
108107
if(length == 0)
@@ -276,11 +275,11 @@ void Websocket::send(uint8_t* data, uint16_t length, uint8_t sendType) {
276275
* @param [in] bufferSize The size of the buffer we wish to allocate to hold data.
277276
*/
278277
WebsocketInputStreambuf::WebsocketInputStreambuf(
279-
HTTPConnection *socket,
278+
ConnectionContext *con,
280279
size_t dataLength,
281280
uint8_t *pMask,
282281
size_t bufferSize) {
283-
_con = socket; // The socket we will be reading from
282+
_con = con; // The socket we will be reading from
284283
_dataLength = dataLength; // The size of the record we wish to read.
285284
_pMask = pMask;
286285
_bufferSize = bufferSize; // The size of the buffer used to hold data

src/Websocket.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
#include <iostream>
1717
#include <streambuf>
1818

19-
#include "HTTPConnection.hpp"
20-
#include "HTTPSConnection.hpp"
21-
// #include "ConnectionContext.hpp"
19+
#include "ConnectionContext.hpp"
2220

2321
namespace httpsserver
2422
{
@@ -56,7 +54,7 @@ class WebsocketInputStreambuf : public std::streambuf
5654
{
5755
public:
5856
WebsocketInputStreambuf(
59-
HTTPConnection *socket,
57+
ConnectionContext *con,
6058
size_t dataLength,
6159
uint8_t *_ = nullptr,
6260
size_t bufferSize = 2048);
@@ -67,7 +65,7 @@ class WebsocketInputStreambuf : public std::streambuf
6765

6866
private:
6967
char *_buffer;
70-
HTTPConnection *_con;
68+
ConnectionContext *_con;
7169
size_t _dataLength;
7270
size_t _bufferSize;
7371
size_t _sizeRead;
@@ -98,15 +96,15 @@ class Websocket
9896
static const uint8_t SEND_TYPE_BINARY = 0x01;
9997
static const uint8_t SEND_TYPE_TEXT = 0x02;
10098

101-
Websocket(HTTPConnection *con);
99+
Websocket(ConnectionContext *con);
102100
~Websocket();
103101
int read();
104102
void close(uint16_t status = CLOSE_NORMAL_CLOSURE, std::string message = "");
105103
void send(std::string data, uint8_t sendType = SEND_TYPE_BINARY);
106104
void send(uint8_t *data, uint16_t length, uint8_t sendType = SEND_TYPE_BINARY);
107105

108106
private:
109-
HTTPConnection *_con;
107+
ConnectionContext *_con;
110108
WebsocketHandler *_wsHandler;
111109
bool _receivedClose; // True when we have received a close request.
112110
bool _sentClose; // True when we have sent a close request.

0 commit comments

Comments
 (0)
0