mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Fixes to UDP so that it no longer has socket 0 hardcoded - all part of issue #436. UdpClass::begin now finds the first available free socket, or fails if they're all in use. UdpClass::stop added to release the socket once it is no longer needed. The global Udp object has also been removed and the examples updated to provide their own instance. Finally, in testing I noticed that the UdpNtpClient didn't print leading 0s if the minute or second was a single-digit, so have taken the opportunity to provide a simple fix for it.
This commit is contained in:
@ -45,7 +45,8 @@ private:
|
||||
uint16_t _port; // local port to listen on
|
||||
|
||||
public:
|
||||
void begin(uint16_t); // initialize, start listening on specified port
|
||||
UdpClass() : _sock(MAX_SOCK_NUM) {};
|
||||
uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
int available(); // has data been received?
|
||||
|
||||
// C-style buffer-oriented functions
|
||||
@ -56,8 +57,8 @@ public:
|
||||
// readPacket that fills a character string buffer
|
||||
int readPacket(char *, uint16_t, uint8_t *, uint16_t &);
|
||||
|
||||
// Finish with the UDP socket
|
||||
void stop();
|
||||
};
|
||||
|
||||
extern UdpClass Udp;
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user