Skip to content

Commit ece85e8

Browse files
authored
sync Udp.h with ESP8266
Apply update from ESP8266: add: - public `virtual ~UDP() {};` - protected `const uint8_t* rawIPAddress(const IPAddress& addr) {…}`
1 parent c8c514c commit ece85e8

File tree

1 file changed

+50
-42
lines changed

1 file changed

+50
-42
lines changed

Diff for: cores/arduino/Udp.h

+50-42
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,60 @@
3838
#include <Stream.h>
3939
#include <IPAddress.h>
4040

41-
class UDP : public Stream {
41+
class UDP: public Stream {
4242

43-
public:
44-
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
45-
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
46-
virtual void stop() =0; // Finish with the UDP socket
43+
public:
44+
virtual ~UDP() {};
45+
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
46+
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
47+
virtual void stop() =0; // Finish with the UDP socket
4748

48-
// Sending UDP packets
49-
50-
// Start building up a packet to send to the remote host specific in ip and port
51-
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
52-
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
53-
// Start building up a packet to send to the remote host specific in host and port
54-
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
55-
virtual int beginPacket(const char *host, uint16_t port) =0;
56-
// Finish off this packet and send it
57-
// Returns 1 if the packet was sent successfully, 0 if there was an error
58-
virtual int endPacket() =0;
59-
// Write a single byte into the packet
60-
virtual size_t write(uint8_t) =0;
61-
// Write size bytes from buffer into the packet
62-
virtual size_t write(const uint8_t *buffer, size_t size) =0;
49+
// Sending UDP packets
6350

64-
// Start processing the next available incoming packet
65-
// Returns the size of the packet in bytes, or 0 if no packets are available
66-
virtual int parsePacket() =0;
67-
// Number of bytes remaining in the current packet
68-
virtual int available() =0;
69-
// Read a single byte from the current packet
70-
virtual int read() =0;
71-
// Read up to len bytes from the current packet and place them into buffer
72-
// Returns the number of bytes read, or 0 if none are available
73-
virtual int read(unsigned char* buffer, size_t len) =0;
74-
// Read up to len characters from the current packet and place them into buffer
75-
// Returns the number of characters read, or 0 if none are available
76-
virtual int read(char* buffer, size_t len) =0;
77-
// Return the next byte from the current packet without moving on to the next byte
78-
virtual int peek() =0;
79-
virtual void flush() =0; // Finish reading the current packet
51+
// Start building up a packet to send to the remote host specific in ip and port
52+
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
53+
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
54+
// Start building up a packet to send to the remote host specific in host and port
55+
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
56+
virtual int beginPacket(const char *host, uint16_t port) =0;
57+
// Finish off this packet and send it
58+
// Returns 1 if the packet was sent successfully, 0 if there was an error
59+
virtual int endPacket() =0;
60+
// Write a single byte into the packet
61+
virtual size_t write(uint8_t) =0;
62+
// Write size bytes from buffer into the packet
63+
virtual size_t write(const uint8_t *buffer, size_t size) =0;
8064

81-
// Return the IP address of the host who sent the current incoming packet
82-
virtual IPAddress remoteIP() =0;
83-
// Return the port of the host who sent the current incoming packet
84-
virtual uint16_t remotePort() =0;
85-
protected:
86-
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
65+
// Start processing the next available incoming packet
66+
// Returns the size of the packet in bytes, or 0 if no packets are available
67+
virtual int parsePacket() =0;
68+
// Number of bytes remaining in the current packet
69+
virtual int available() =0;
70+
// Read a single byte from the current packet
71+
virtual int read() =0;
72+
// Read up to len bytes from the current packet and place them into buffer
73+
// Returns the number of bytes read, or 0 if none are available
74+
virtual int read(unsigned char* buffer, size_t len) =0;
75+
// Read up to len characters from the current packet and place them into buffer
76+
// Returns the number of characters read, or 0 if none are available
77+
virtual int read(char* buffer, size_t len) =0;
78+
// Return the next byte from the current packet without moving on to the next byte
79+
virtual int peek() =0;
80+
virtual void flush() =0; // Finish reading the current packet
81+
82+
// Return the IP address of the host who sent the current incoming packet
83+
virtual IPAddress remoteIP() =0;
84+
// Return the port of the host who sent the current incoming packet
85+
virtual uint16_t remotePort() =0;
86+
protected:
87+
88+
uint8_t* rawIPAddress(IPAddress& addr) {
89+
return addr.raw_address();
90+
}
91+
92+
const uint8_t* rawIPAddress(const IPAddress& addr) {
93+
return addr.raw_address();
94+
}
8795
};
8896

8997
#endif

0 commit comments

Comments
 (0)