state mashine upd

This commit is contained in:
2024-10-29 15:14:23 +03:00
parent f3e1dd6ee8
commit 94ea050345
4 changed files with 149 additions and 74 deletions

View File

@ -10,7 +10,10 @@ enum ConnectionStatusSimple{
CONNECT_SUCCESS = 1,
CONNECT_CONNECTING = 2,
CONNECT_START = 3,
CONNECT_IDLE = 4
CONNECT_IDLE = 4,
CONNECT_CONNECTED = 5,
CONNECT_STOP_START = 6,
CONNECT_STOP_WAITING = 7,
};

View File

@ -45,4 +45,42 @@ ConnectionStatusSimple EthernetMaketClient::connectNonBlock(IPAddress ip, uint16
}
return CONNECT_CONNECTING;
}
}
void EthernetMaketClient::disconnect(){
if (_sock == MAX_SOCK_NUM)
return;
::disconnect(_sock);
}
void EthernetMaketClient::close(){
if (_sock == MAX_SOCK_NUM)
return;
::close(_sock);
_sock = MAX_SOCK_NUM;
}
// void EthernetMaketClient::stop() {
// if (_sock == MAX_SOCK_NUM)
// return;
// // attempt to close the connection gracefully (send a FIN to other side)
// disconnect(_sock);
// unsigned long start = millis();
// // wait a second for the connection to close
// uint8_t s;
// do {
// s = status();
// if (s == SnSR::CLOSED)
// break; // exit the loop
// delay(1);
// } while (millis() - start < 1000);
// // if it hasn't closed, close it forcefully
// if (status() != SnSR::CLOSED)
// close(_sock);
// EthernetClass::_server_port[_sock] = 0;
// _sock = MAX_SOCK_NUM;
// }

View File

@ -9,7 +9,9 @@ public:
using EthernetClient::EthernetClient;
ConnectionStatusSimple connectNonBlock(IPAddress ip, uint16_t port);
// void stop() override;
void disconnect();
void close();
};
#endif // __MAKET_TCP_H__