Unverified Commit d2beb2da authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Add upsteam multicast compatibility APIs (#821)

Fixes #747 while remaining ESP8266 compatible
parent 7ef44d98
...@@ -38,7 +38,7 @@ template<> ...@@ -38,7 +38,7 @@ template<>
WiFiUDP* SList<WiFiUDP>::_s_first = 0; WiFiUDP* SList<WiFiUDP>::_s_first = 0;
/* Constructor */ /* Constructor */
WiFiUDP::WiFiUDP() : _ctx(0) { WiFiUDP::WiFiUDP() : _ctx(0), _multicast(false) {
WiFiUDP::_add(this); WiFiUDP::_add(this);
} }
...@@ -48,6 +48,7 @@ WiFiUDP::WiFiUDP(const WiFiUDP& other) { ...@@ -48,6 +48,7 @@ WiFiUDP::WiFiUDP(const WiFiUDP& other) {
_ctx->ref(); _ctx->ref();
} }
WiFiUDP::_add(this); WiFiUDP::_add(this);
_multicast = other._multicast;
} }
WiFiUDP& WiFiUDP::operator=(const WiFiUDP& rhs) { WiFiUDP& WiFiUDP::operator=(const WiFiUDP& rhs) {
...@@ -97,6 +98,12 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui ...@@ -97,6 +98,12 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
return 1; return 1;
} }
uint8_t WiFiUDP::beginMulticast(IPAddress addr, uint16_t port) {
auto ret = beginMulticast(IP_ADDR_ANY, addr, port);
_multicast = true;
return ret;
}
/* return number of bytes available in the current packet, /* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */ will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available() { int WiFiUDP::available() {
...@@ -137,7 +144,13 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) { ...@@ -137,7 +144,13 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) {
_ctx = new UdpContext; _ctx = new UdpContext;
_ctx->ref(); _ctx->ref();
} }
return (_ctx->connect(ip, port)) ? 1 : 0; auto ret = (_ctx->connect(ip, port)) ? 1 : 0;
if (_multicast) {
_ctx->setMulticastInterface(IP_ADDR_ANY);
_ctx->setMulticastTTL(255);
}
return ret;
} }
int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port, int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
......
...@@ -44,9 +44,12 @@ public: ...@@ -44,9 +44,12 @@ public:
// initialize, start listening on specified port. // initialize, start listening on specified port.
// Returns 1 if successful, 0 if there are no sockets available to use // Returns 1 if successful, 0 if there are no sockets available to use
uint8_t begin(uint16_t port) override; virtual uint8_t begin(uint16_t port) override;
// initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
virtual uint8_t beginMulticast(IPAddress, uint16_t) override;
// Finish with the UDP connection // Finish with the UDP connection
void stop() override; virtual void stop() override;
// join a multicast group and listen on the given port // join a multicast group and listen on the given port
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port); uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);
...@@ -110,4 +113,6 @@ public: ...@@ -110,4 +113,6 @@ public:
static void stopAll(); static void stopAll();
static void stopAllExcept(WiFiUDP * exC); static void stopAllExcept(WiFiUDP * exC);
private:
bool _multicast;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment