mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
WiFiServer - 'rename' available() to accept() (#8419)
* WiFiServer - 'rename' available() to accept() * use server.accept() instead of available() * WiFiServer.accept() and ArduinoWiFiServer class doc update
This commit is contained in:
@ -12,13 +12,29 @@ Methods documented for the `Server Class <https://www.arduino.cc/en/Reference/Wi
|
||||
5. `print() <https://www.arduino.cc/en/Reference/WiFiServerPrint>`__
|
||||
6. `println() <https://www.arduino.cc/en/Reference/WiFiServerPrintln>`__
|
||||
|
||||
In ESP8266WiFi library the ``ArduinoWiFiServer`` class implements ``available`` and the write-to-all-clients functionality as described in the Arduino WiFi library reference. The PageServer example shows how ``available`` and the write-to-all-clients works.
|
||||
|
||||
For most use cases the basic WiFiServer class of the ESP8266WiFi library is suitable.
|
||||
|
||||
Methods and properties described further down are specific to ESP8266. They are not covered in `Arduino WiFi library <https://www.arduino.cc/en/Reference/WiFi>`__ documentation. Before they are fully documented please refer to information below.
|
||||
|
||||
accept
|
||||
~~~~~~
|
||||
|
||||
Method ``accept()`` returns a waiting client connection. `accept() is documented <https://www.arduino.cc/en/Reference/EthernetServerAccept>`__ for the Arduino Ethernet library.
|
||||
|
||||
available
|
||||
~~~~~~~~~
|
||||
.. deprecated:: 3.1.0
|
||||
see ``accept``
|
||||
|
||||
``available`` in the ESP8266WiFi library's WiFiServer class doesn't work as documented for the Arduino WiFi library. It works the same way as ``accept``.
|
||||
|
||||
write (write to all clients) not supported
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Please note that the ``write`` method on the ``WiFiServer`` object is not implemented and returns failure always. Use the returned
|
||||
``WiFiClient`` object from the ``WiFiServer::available()`` method to communicate with individual clients. If you need to send
|
||||
``WiFiClient`` object from the ``WiFiServer::accept()`` method to communicate with individual clients. If you need to send
|
||||
the exact same packets to a series of clients, your application must maintain a list of connected clients and iterate over them manually.
|
||||
|
||||
setNoDelay
|
||||
|
@ -92,7 +92,7 @@ Serving of this web page will be done in the ``loop()`` where server is waiting
|
||||
|
||||
void loop()
|
||||
{
|
||||
WiFiClient client = server.available();
|
||||
WiFiClient client = server.accept();
|
||||
if (client)
|
||||
{
|
||||
// we have a new client sending some request
|
||||
@ -196,7 +196,7 @@ Complete sketch is presented below.
|
||||
|
||||
void loop()
|
||||
{
|
||||
WiFiClient client = server.available();
|
||||
WiFiClient client = server.accept();
|
||||
// wait for a client (web browser) to connect
|
||||
if (client)
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ AVRISPState_t ESP8266AVRISP::update() {
|
||||
switch (_state) {
|
||||
case AVRISP_STATE_IDLE: {
|
||||
if (_server.hasClient()) {
|
||||
_client = _server.available();
|
||||
_client = _server.accept();
|
||||
_client.setNoDelay(true);
|
||||
AVRISP_DEBUG("client connect %s:%d", _client.remoteIP().toString().c_str(), _client.remotePort());
|
||||
_client.setTimeout(100); // for getch()
|
||||
@ -121,7 +121,7 @@ AVRISPState_t ESP8266AVRISP::serve() {
|
||||
}
|
||||
|
||||
inline void ESP8266AVRISP::_reject_incoming(void) {
|
||||
while (_server.hasClient()) _server.available().stop();
|
||||
while (_server.hasClient()) _server.accept().stop();
|
||||
}
|
||||
|
||||
uint8_t ESP8266AVRISP::getch() {
|
||||
|
@ -281,7 +281,7 @@ void ESP8266WebServerTemplate<ServerType>::serveStatic(const char* uri, FS& fs,
|
||||
template <typename ServerType>
|
||||
void ESP8266WebServerTemplate<ServerType>::handleClient() {
|
||||
if (_currentStatus == HC_NONE) {
|
||||
ClientType client = _server.available();
|
||||
ClientType client = _server.accept();
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ static const char *HTTP_RES =
|
||||
|
||||
void loop() {
|
||||
static int cnt;
|
||||
BearSSL::WiFiClientSecure incoming = server.available();
|
||||
BearSSL::WiFiClientSecure incoming = server.accept();
|
||||
if (!incoming) {
|
||||
return;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ static const char *HTTP_RES =
|
||||
"</html>\r\n";
|
||||
|
||||
void loop() {
|
||||
BearSSL::WiFiClientSecure incoming = server.available();
|
||||
BearSSL::WiFiClientSecure incoming = server.accept();
|
||||
if (!incoming) {
|
||||
return;
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ unsigned long statusTimeMs = 0;
|
||||
void loop() {
|
||||
|
||||
if (statusServer.hasClient()) {
|
||||
WiFiClient cli = statusServer.available();
|
||||
WiFiClient cli = statusServer.accept();
|
||||
status(cli);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ void loop() {
|
||||
|
||||
//check if there are any new clients
|
||||
if (server.hasClient()) {
|
||||
client = server.available();
|
||||
client = server.accept();
|
||||
Serial.println("New client");
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// Check if a client has connected
|
||||
WiFiClient client = server.available();
|
||||
WiFiClient client = server.accept();
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ void loop() {
|
||||
int i;
|
||||
for (i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
if (!serverClients[i]) { // equivalent to !serverClients[i].connected()
|
||||
serverClients[i] = server.available();
|
||||
serverClients[i] = server.accept();
|
||||
logger->print("New client: index ");
|
||||
logger->print(i);
|
||||
break;
|
||||
@ -138,8 +138,8 @@ void loop() {
|
||||
|
||||
//no free/disconnected spot so reject
|
||||
if (i == MAX_SRV_CLIENTS) {
|
||||
server.available().println("busy");
|
||||
// hints: server.available() is a WiFiClient with short-term scope
|
||||
server.accept().println("busy");
|
||||
// hints: server.accept() is a WiFiClient with short-term scope
|
||||
// when out of scope, a WiFiClient will
|
||||
// - flush() - all data will be sent
|
||||
// - stop() - automatically too
|
||||
|
@ -35,11 +35,6 @@ public:
|
||||
ArduinoCompatibleWiFiServerTemplate(uint16_t port) : TServer(port) {}
|
||||
virtual ~ArduinoCompatibleWiFiServerTemplate() {}
|
||||
|
||||
// https://www.arduino.cc/en/Reference/EthernetServerAccept
|
||||
TClient accept() {
|
||||
return TServer::available();
|
||||
}
|
||||
|
||||
// https://www.arduino.cc/en/Reference/WiFiServerAvailable
|
||||
TClient available() {
|
||||
|
||||
@ -132,7 +127,7 @@ private:
|
||||
void acceptClients() {
|
||||
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) {
|
||||
if (!connectedClients[i]) {
|
||||
connectedClients[i] = accept();
|
||||
connectedClients[i] = TServer::accept();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +130,10 @@ bool WiFiServer::hasMaxPendingClients() {
|
||||
|
||||
WiFiClient WiFiServer::available(byte* status) {
|
||||
(void) status;
|
||||
return accept();
|
||||
}
|
||||
|
||||
WiFiClient WiFiServer::accept() {
|
||||
if (_unclaimed) {
|
||||
WiFiClient result(_unclaimed);
|
||||
|
||||
|
@ -80,7 +80,8 @@ public:
|
||||
WiFiServer(const IPAddress& addr, uint16_t port);
|
||||
WiFiServer(uint16_t port);
|
||||
virtual ~WiFiServer() {}
|
||||
WiFiClient available(uint8_t* status = NULL);
|
||||
WiFiClient accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept
|
||||
WiFiClient available(uint8_t* status = NULL) __attribute__((deprecated("Renamed to accept().")));
|
||||
bool hasClient();
|
||||
// hasClientData():
|
||||
// returns the amount of data available from the first client
|
||||
|
@ -77,6 +77,10 @@ void WiFiServerSecure::setECCert(const X509List *chain, unsigned cert_issuer_key
|
||||
// then any validation (i.e. client cert checking) will have succeeded.
|
||||
WiFiClientSecure WiFiServerSecure::available(uint8_t* status) {
|
||||
(void) status; // Unused
|
||||
return accept();
|
||||
}
|
||||
|
||||
WiFiClientSecure WiFiServerSecure::accept() {
|
||||
if (_unclaimed) {
|
||||
if (_sk && _sk->isRSA()) {
|
||||
WiFiClientSecure result(_unclaimed, _chain, _sk, _iobuf_in_size, _iobuf_out_size, _cache, _client_CA_ta, _tls_min, _tls_max);
|
||||
|
@ -65,7 +65,8 @@ class WiFiServerSecure : public WiFiServer {
|
||||
bool setSSLVersion(uint32_t min = BR_TLS10, uint32_t max = BR_TLS12);
|
||||
|
||||
// If awaiting connection available and authenticated (i.e. client cert), return it.
|
||||
WiFiClientSecure available(uint8_t* status = NULL);
|
||||
WiFiClientSecure accept(); // https://www.arduino.cc/en/Reference/EthernetServerAccept
|
||||
WiFiClientSecure available(uint8_t* status = NULL) __attribute__((deprecated("Renamed to accept().")));
|
||||
|
||||
WiFiServerSecure& operator=(const WiFiServerSecure&) = default;
|
||||
|
||||
|
@ -624,7 +624,7 @@ void ESP8266WiFiMesh::acceptRequest()
|
||||
if(_handler != NULL)
|
||||
{
|
||||
while (true) {
|
||||
_client = _server.available();
|
||||
_client = _server.accept();
|
||||
if (!_client)
|
||||
break;
|
||||
|
||||
@ -647,7 +647,7 @@ void ESP8266WiFiMesh::acceptRequest()
|
||||
{
|
||||
////////////////////////////</DEPRECATED> TODO: REMOVE IN 2.5.0////////////////////////////
|
||||
while (true) {
|
||||
WiFiClient _client = _server.available();
|
||||
WiFiClient _client = _server.accept();
|
||||
|
||||
if (!_client)
|
||||
break;
|
||||
|
@ -533,7 +533,7 @@ void TcpIpMeshBackend::acceptRequests()
|
||||
}
|
||||
|
||||
while (true) {
|
||||
WiFiClient _client = _server.available();
|
||||
WiFiClient _client = _server.accept();
|
||||
|
||||
if (!_client)
|
||||
break;
|
||||
|
@ -76,7 +76,7 @@ void loop(void) {
|
||||
MDNS.update();
|
||||
|
||||
// Check if a client has connected
|
||||
WiFiClient client = server.available();
|
||||
WiFiClient client = server.accept();
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ void Netdump::tcpDumpLoop(WiFiServer &tcpDumpServer, const Filter nf)
|
||||
{
|
||||
if (tcpDumpServer.hasClient())
|
||||
{
|
||||
tcpDumpClient = tcpDumpServer.available();
|
||||
tcpDumpClient = tcpDumpServer.accept();
|
||||
tcpDumpClient.setNoDelay(true);
|
||||
|
||||
bufferIndex = 0;
|
||||
|
@ -58,6 +58,11 @@ WiFiServer::WiFiServer (uint16_t port)
|
||||
WiFiClient WiFiServer::available (uint8_t* status)
|
||||
{
|
||||
(void)status;
|
||||
return accept();
|
||||
}
|
||||
|
||||
WiFiClient WiFiServer::accept ()
|
||||
{
|
||||
if (hasClient())
|
||||
return WiFiClient(new ClientContext(serverAccept(pcb2int(_listen_pcb))));
|
||||
return WiFiClient();
|
||||
|
Reference in New Issue
Block a user