Skip to content

Commit 4032707

Browse files
committed
Replace forward declaration of AsyncWebSocketControl with full definition
std::deque requires a fully defined type to function, this commit defines AsyncWebSocketControl in the header to satisfy this requirement.
1 parent 927be07 commit 4032707

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

src/AsyncWebSocket.cpp

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -127,53 +127,42 @@ size_t webSocketSendFrame(AsyncClient *client, bool final, uint8_t opcode, bool
127127
* Control Frame
128128
*/
129129

130-
class AsyncWebSocketControl {
131-
private:
132-
uint8_t _opcode;
133-
uint8_t *_data;
134-
size_t _len;
135-
bool _mask;
136-
bool _finished;
137-
138-
public:
139-
AsyncWebSocketControl(uint8_t opcode, const uint8_t *data=NULL, size_t len=0, bool mask=false)
140-
:_opcode(opcode)
141-
,_len(len)
142-
,_mask(len && mask)
143-
,_finished(false)
130+
131+
AsyncWebSocketControl::AsyncWebSocketControl(uint8_t opcode, const uint8_t *data, size_t len, bool mask)
132+
:_opcode(opcode)
133+
,_len(len)
134+
,_mask(len && mask)
135+
,_finished(false)
136+
{
137+
if (data == NULL)
138+
_len = 0;
139+
if (_len)
144140
{
145-
if (data == NULL)
146-
_len = 0;
147-
if (_len)
148-
{
149-
if (_len > 125)
150-
_len = 125;
141+
if (_len > 125)
142+
_len = 125;
151143

152-
_data = (uint8_t*)malloc(_len);
144+
_data = (uint8_t*)malloc(_len);
153145

154-
if(_data == NULL)
155-
_len = 0;
156-
else
157-
memcpy(_data, data, len);
158-
}
146+
if(_data == NULL)
147+
_len = 0;
159148
else
160-
_data = NULL;
149+
memcpy(_data, data, len);
161150
}
151+
else
152+
_data = NULL;
153+
}
162154

163-
virtual ~AsyncWebSocketControl()
164-
{
165-
if (_data != NULL)
166-
free(_data);
167-
}
155+
AsyncWebSocketControl::~AsyncWebSocketControl()
156+
{
157+
if (_data != NULL)
158+
free(_data);
159+
}
168160

169-
virtual bool finished() const { return _finished; }
170-
uint8_t opcode(){ return _opcode; }
171-
uint8_t len(){ return _len + 2; }
172-
size_t send(AsyncClient *client){
173-
_finished = true;
174-
return webSocketSendFrame(client, true, _opcode & 0x0F, _mask, _data, _len);
175-
}
176-
};
161+
size_t AsyncWebSocketControl::send(AsyncClient *client)
162+
{
163+
_finished = true;
164+
return webSocketSendFrame(client, true, _opcode & 0x0F, _mask, _data, _len);
165+
}
177166

178167

179168
/*

src/AsyncWebSocket.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ typedef enum { WS_CONTINUATION, WS_TEXT, WS_BINARY, WS_DISCONNECT = 0x08, WS_PIN
8484
typedef enum { WS_MSG_SENDING, WS_MSG_SENT, WS_MSG_ERROR } AwsMessageStatus;
8585
typedef enum { WS_EVT_CONNECT, WS_EVT_DISCONNECT, WS_EVT_PONG, WS_EVT_ERROR, WS_EVT_DATA } AwsEventType;
8686

87+
class AsyncWebSocketControl {
88+
private:
89+
uint8_t _opcode;
90+
uint8_t *_data;
91+
size_t _len;
92+
bool _mask;
93+
bool _finished;
94+
95+
public:
96+
AsyncWebSocketControl(uint8_t opcode, const uint8_t *data=NULL, size_t len=0, bool mask=false);
97+
98+
virtual ~AsyncWebSocketControl();
99+
virtual bool finished() const { return _finished; }
100+
uint8_t opcode(){ return _opcode; }
101+
uint8_t len(){ return _len + 2; }
102+
size_t send(AsyncClient *client);
103+
};
104+
87105
class AsyncWebSocketMessage
88106
{
89107
private:

0 commit comments

Comments
 (0)