1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-10 04:22:05 +03:00

Allman now (#6080)

* switch restyle script for CI

* remove confirmation

* restyle with allman
This commit is contained in:
Allman-astyler
2019-05-13 16:41:34 +02:00
committed by david gauchard
parent 625c3a62c4
commit 98125f8860
255 changed files with 51238 additions and 42984 deletions

View File

@ -1,23 +1,23 @@
/*
WiFiUdp.cpp - UDP client/server for esp8266, mostly compatible
WiFiUdp.cpp - UDP client/server for esp8266, mostly compatible
with Arduino WiFi shield library
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define LWIP_INTERNAL
@ -25,9 +25,9 @@
extern "C"
{
#include "include/wl_definitions.h"
#include "osapi.h"
#include "ets_sys.h"
#include "include/wl_definitions.h"
#include "osapi.h"
#include "ets_sys.h"
}
#include "debug.h"
@ -53,7 +53,9 @@ WiFiUDP::WiFiUDP(const WiFiUDP& other)
{
_ctx = other._ctx;
if (_ctx)
{
_ctx->ref();
}
WiFiUDP::_add(this);
}
@ -61,7 +63,9 @@ WiFiUDP& WiFiUDP::operator=(const WiFiUDP& rhs)
{
_ctx = rhs._ctx;
if (_ctx)
{
_ctx->ref();
}
return *this;
}
@ -69,13 +73,16 @@ WiFiUDP::~WiFiUDP()
{
WiFiUDP::_remove(this);
if (_ctx)
{
_ctx->unref();
}
}
/* Start WiFiUDP socket, listening at local port */
uint8_t WiFiUDP::begin(uint16_t port)
{
if (_ctx) {
if (_ctx)
{
_ctx->unref();
_ctx = 0;
}
@ -87,35 +94,41 @@ uint8_t WiFiUDP::begin(uint16_t port)
uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
{
if (_ctx) {
if (_ctx)
{
_ctx->unref();
_ctx = 0;
}
if (igmp_joingroup(interfaceAddr, multicast)!= ERR_OK) {
if (igmp_joingroup(interfaceAddr, multicast) != ERR_OK)
{
return 0;
}
_ctx = new UdpContext;
_ctx->ref();
ip_addr_t addr = IPADDR4_INIT(INADDR_ANY);
if (!_ctx->listen(&addr, port)) {
if (!_ctx->listen(&addr, port))
{
return 0;
}
return 1;
}
/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available() {
/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available()
{
int result = 0;
if (_ctx) {
if (_ctx)
{
result = static_cast<int>(_ctx->getSize());
}
if (!result) {
if (!result)
{
// yielding here will not make more data "available",
// but it will prevent the system from going into WDT reset
optimistic_yield(1000);
@ -127,7 +140,8 @@ int WiFiUDP::available() {
/* Release any resources being used by this WiFiUDP instance */
void WiFiUDP::stop()
{
if (_ctx) {
if (_ctx)
{
_ctx->disconnect();
_ctx->unref();
}
@ -146,7 +160,8 @@ int WiFiUDP::beginPacket(const char *host, uint16_t port)
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
{
if (!_ctx) {
if (!_ctx)
{
_ctx = new UdpContext;
_ctx->ref();
}
@ -154,13 +169,15 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
}
int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
IPAddress interfaceAddress, int ttl)
IPAddress interfaceAddress, int ttl)
{
if (!_ctx) {
if (!_ctx)
{
_ctx = new UdpContext;
_ctx->ref();
}
if (!_ctx->connect(multicastAddress, port)) {
if (!_ctx->connect(multicastAddress, port))
{
return 0;
}
_ctx->setMulticastInterface(interfaceAddress);
@ -171,7 +188,9 @@ int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
int WiFiUDP::endPacket()
{
if (!_ctx)
{
return 0;
}
return (_ctx->send()) ? 1 : 0;
}
@ -184,7 +203,9 @@ size_t WiFiUDP::write(uint8_t byte)
size_t WiFiUDP::write(const uint8_t *buffer, size_t size)
{
if (!_ctx)
{
return 0;
}
return _ctx->append(reinterpret_cast<const char*>(buffer), size);
}
@ -192,9 +213,12 @@ size_t WiFiUDP::write(const uint8_t *buffer, size_t size)
int WiFiUDP::parsePacket()
{
if (!_ctx)
{
return 0;
}
if (!_ctx->next()) {
if (!_ctx->next())
{
optimistic_yield(100);
return 0;
}
@ -205,7 +229,9 @@ int WiFiUDP::parsePacket()
int WiFiUDP::read()
{
if (!_ctx)
{
return -1;
}
return _ctx->read();
}
@ -213,7 +239,9 @@ int WiFiUDP::read()
int WiFiUDP::read(unsigned char* buffer, size_t len)
{
if (!_ctx)
{
return 0;
}
return _ctx->read(reinterpret_cast<char*>(buffer), len);
}
@ -221,7 +249,9 @@ int WiFiUDP::read(unsigned char* buffer, size_t len)
int WiFiUDP::peek()
{
if (!_ctx)
{
return -1;
}
return _ctx->peek();
}
@ -234,7 +264,9 @@ void WiFiUDP::flush()
IPAddress WiFiUDP::remoteIP()
{
if (!_ctx)
{
return INADDR_ANY;
}
return _ctx->getRemoteAddress();
}
@ -242,7 +274,9 @@ IPAddress WiFiUDP::remoteIP()
uint16_t WiFiUDP::remotePort()
{
if (!_ctx)
{
return 0;
}
return _ctx->getRemotePort();
}
@ -250,7 +284,9 @@ uint16_t WiFiUDP::remotePort()
IPAddress WiFiUDP::destinationIP() const
{
if (!_ctx)
{
return INADDR_ANY;
}
return _ctx->getDestAddress();
}
@ -258,22 +294,28 @@ IPAddress WiFiUDP::destinationIP() const
uint16_t WiFiUDP::localPort() const
{
if (!_ctx)
{
return 0;
}
return _ctx->getLocalPort();
}
void WiFiUDP::stopAll()
{
for (WiFiUDP* it = _s_first; it; it = it->_next) {
for (WiFiUDP* it = _s_first; it; it = it->_next)
{
DEBUGV("%s %p %p\n", __func__, it, _s_first);
it->stop();
}
}
void WiFiUDP::stopAllExcept(WiFiUDP * exC) {
for (WiFiUDP* it = _s_first; it; it = it->_next) {
if (it->_ctx != exC->_ctx) {
void WiFiUDP::stopAllExcept(WiFiUDP * exC)
{
for (WiFiUDP* it = _s_first; it; it = it->_next)
{
if (it->_ctx != exC->_ctx)
{
DEBUGV("%s %p %p\n", __func__, it, _s_first);
it->stop();
}