Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit d705f35

Browse files
author
Me No Dev
committed
ssl extra code
1 parent 110a997 commit d705f35

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/ESPAsyncTCP.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ AsyncClient& AsyncClient::operator=(const AsyncClient& other){
119119

120120
_pcb = other._pcb;
121121
if (_pcb) {
122+
if(axl_get(_pcb)){
123+
_pcb_secure = true;
124+
_handshake_done = false;
125+
axl_arg(_pcb, this);
126+
axl_data(_pcb, &_s_data);
127+
axl_handshake(_pcb, &_s_handshake);
128+
axl_err(_pcb, &_s_ssl_error);
129+
} else {
130+
_pcb_secure = false;
131+
_handshake_done = true;
132+
}
122133
tcp_setprio(_pcb, TCP_PRIO_MIN);
123134
tcp_arg(_pcb, this);
124135
tcp_recv(_pcb, &_s_recv);
@@ -243,13 +254,13 @@ size_t AsyncClient::ack(size_t len){
243254
int8_t AsyncClient::_close(){
244255
int8_t err = ERR_OK;
245256
if(_pcb) {
257+
if(_pcb_secure)
258+
axl_free(_pcb);
246259
tcp_arg(_pcb, NULL);
247260
tcp_sent(_pcb, NULL);
248261
tcp_recv(_pcb, NULL);
249262
tcp_err(_pcb, NULL);
250263
tcp_poll(_pcb, NULL, 0);
251-
if(_pcb_secure)
252-
axl_free(_pcb);
253264
err = tcp_close(_pcb);
254265
if(err != ERR_OK) {
255266
err = abort();
@@ -287,13 +298,13 @@ int8_t AsyncClient::_connected(void* pcb, int8_t err){
287298

288299
void AsyncClient::_error(int8_t err) {
289300
if(_pcb){
301+
if(_pcb_secure)
302+
axl_free(_pcb);
290303
tcp_arg(_pcb, NULL);
291304
tcp_sent(_pcb, NULL);
292305
tcp_recv(_pcb, NULL);
293306
tcp_err(_pcb, NULL);
294307
tcp_poll(_pcb, NULL, 0);
295-
if(_pcb_secure)
296-
axl_free(_pcb);
297308
_pcb = NULL;
298309
}
299310
if(_error_cb)
@@ -606,7 +617,7 @@ void AsyncClient::onPoll(AcConnectHandler cb, void* arg){
606617

607618

608619
size_t AsyncClient::space(){
609-
if((_pcb != NULL) && (_pcb->state == 4))
620+
if((_pcb != NULL) && (_pcb->state == 4) && _handshake_done)
610621
return _pcb->snd_buf;
611622
return 0;
612623
}

0 commit comments

Comments
 (0)