@@ -39,6 +39,8 @@ extern "C"{
39
39
#include < NetworkInterface.h>
40
40
#endif
41
41
42
+ #define INVALID_CLOSED_SLOT -1
43
+
42
44
/*
43
45
* TCP/IP Event Task
44
46
* */
@@ -402,7 +404,7 @@ typedef struct {
402
404
static err_t _tcp_output_api (struct tcpip_api_call_data *api_call_msg){
403
405
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
404
406
msg->err = ERR_CONN;
405
- if (msg->closed_slot == - 1 || !_closed_slots[msg->closed_slot ]) {
407
+ if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot ]) {
406
408
msg->err = tcp_output (msg->pcb );
407
409
}
408
410
return msg->err ;
@@ -422,7 +424,7 @@ static esp_err_t _tcp_output(tcp_pcb * pcb, int8_t closed_slot) {
422
424
static err_t _tcp_write_api (struct tcpip_api_call_data *api_call_msg){
423
425
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
424
426
msg->err = ERR_CONN;
425
- if (msg->closed_slot == - 1 || !_closed_slots[msg->closed_slot ]) {
427
+ if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot ]) {
426
428
msg->err = tcp_write (msg->pcb , msg->write .data , msg->write .size , msg->write .apiflags );
427
429
}
428
430
return msg->err ;
@@ -445,7 +447,7 @@ static esp_err_t _tcp_write(tcp_pcb * pcb, int8_t closed_slot, const char* data,
445
447
static err_t _tcp_recved_api (struct tcpip_api_call_data *api_call_msg){
446
448
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
447
449
msg->err = ERR_CONN;
448
- if (msg->closed_slot != - 1 && !_closed_slots[msg->closed_slot ]) {
450
+ if (msg->closed_slot != INVALID_CLOSED_SLOT && !_closed_slots[msg->closed_slot ]) {
449
451
msg->err = 0 ;
450
452
tcp_recved (msg->pcb , msg->received );
451
453
}
@@ -467,7 +469,7 @@ static esp_err_t _tcp_recved(tcp_pcb * pcb, int8_t closed_slot, size_t len) {
467
469
static err_t _tcp_close_api (struct tcpip_api_call_data *api_call_msg){
468
470
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
469
471
msg->err = ERR_CONN;
470
- if (msg->closed_slot == - 1 || !_closed_slots[msg->closed_slot ]) {
472
+ if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot ]) {
471
473
msg->err = tcp_close (msg->pcb );
472
474
}
473
475
return msg->err ;
@@ -487,7 +489,7 @@ static esp_err_t _tcp_close(tcp_pcb * pcb, int8_t closed_slot) {
487
489
static err_t _tcp_abort_api (struct tcpip_api_call_data *api_call_msg){
488
490
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
489
491
msg->err = ERR_CONN;
490
- if (msg->closed_slot == - 1 || !_closed_slots[msg->closed_slot ]) {
492
+ if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot ]) {
491
493
tcp_abort (msg->pcb );
492
494
}
493
495
return msg->err ;
@@ -593,7 +595,7 @@ AsyncClient::AsyncClient(tcp_pcb* pcb)
593
595
, next (NULL )
594
596
{
595
597
_pcb = pcb;
596
- _closed_slot = - 1 ;
598
+ _closed_slot = INVALID_CLOSED_SLOT ;
597
599
if (_pcb){
598
600
_rx_last_packet = millis ();
599
601
tcp_arg (_pcb, this );
@@ -879,29 +881,29 @@ int8_t AsyncClient::_close(){
879
881
}
880
882
881
883
bool AsyncClient::_allocate_closed_slot (){
882
- if (_closed_slot != - 1 ) {
884
+ if (_closed_slot != INVALID_CLOSED_SLOT ) {
883
885
return true ;
884
886
}
885
887
xSemaphoreTake (_slots_lock, portMAX_DELAY);
886
888
uint32_t closed_slot_min_index = 0 ;
887
889
for (int i = 0 ; i < _number_of_closed_slots; ++ i) {
888
- if ((_closed_slot == - 1 || _closed_slots[i] <= closed_slot_min_index) && _closed_slots[i] != 0 ) {
890
+ if ((_closed_slot == INVALID_CLOSED_SLOT || _closed_slots[i] <= closed_slot_min_index) && _closed_slots[i] != 0 ) {
889
891
closed_slot_min_index = _closed_slots[i];
890
892
_closed_slot = i;
891
893
}
892
894
}
893
- if (_closed_slot != - 1 ) {
895
+ if (_closed_slot != INVALID_CLOSED_SLOT ) {
894
896
_closed_slots[_closed_slot] = 0 ;
895
897
}
896
898
xSemaphoreGive (_slots_lock);
897
- return (_closed_slot != - 1 );
899
+ return (_closed_slot != INVALID_CLOSED_SLOT );
898
900
}
899
901
900
902
void AsyncClient::_free_closed_slot (){
901
903
xSemaphoreTake (_slots_lock, portMAX_DELAY);
902
- if (_closed_slot != - 1 ) {
904
+ if (_closed_slot != INVALID_CLOSED_SLOT ) {
903
905
_closed_slots[_closed_slot] = _closed_index;
904
- _closed_slot = - 1 ;
906
+ _closed_slot = INVALID_CLOSED_SLOT ;
905
907
++ _closed_index;
906
908
}
907
909
xSemaphoreGive (_slots_lock);
0 commit comments