mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-07 01:54:26 +01:00
Adding Client::peek() in Ethernet library (issue #349).
This commit is contained in:
parent
76641d1a87
commit
ea8a1182b8
@ -83,6 +83,14 @@ int Client::read() {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Client::peek() {
|
||||||
|
uint8_t b;
|
||||||
|
if (!available())
|
||||||
|
return -1;
|
||||||
|
::peek(_sock, &b);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
void Client::flush() {
|
void Client::flush() {
|
||||||
while (available())
|
while (available())
|
||||||
read();
|
read();
|
||||||
|
@ -17,6 +17,7 @@ public:
|
|||||||
virtual void write(const uint8_t *buf, size_t size);
|
virtual void write(const uint8_t *buf, size_t size);
|
||||||
virtual int available();
|
virtual int available();
|
||||||
virtual int read();
|
virtual int read();
|
||||||
|
virtual int peek();
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
void stop();
|
void stop();
|
||||||
uint8_t connected();
|
uint8_t connected();
|
||||||
|
@ -158,6 +158,19 @@ uint16_t recv(SOCKET s, uint8_t *buf, uint16_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the first byte in the receive queue (no checking)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
uint16_t peek(SOCKET s, uint8_t *buf)
|
||||||
|
{
|
||||||
|
W5100.recv_data_processing(s, buf, 1, 1);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is an application I/F function which is used to send the data for other then TCP mode.
|
* @brief This function is an application I/F function which is used to send the data for other then TCP mode.
|
||||||
* Unlike TCP transmission, The peer's destination address and the port is needed.
|
* Unlike TCP transmission, The peer's destination address and the port is needed.
|
||||||
|
@ -10,6 +10,7 @@ extern void disconnect(SOCKET s); // disconnect the connection
|
|||||||
extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection)
|
extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection)
|
||||||
extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP)
|
extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP)
|
||||||
extern uint16_t recv(SOCKET s, uint8_t * buf, uint16_t len); // Receive data (TCP)
|
extern uint16_t recv(SOCKET s, uint8_t * buf, uint16_t len); // Receive data (TCP)
|
||||||
|
extern uint16_t peek(SOCKET s, uint8_t *buf);
|
||||||
extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW)
|
extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW)
|
||||||
extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW)
|
extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW)
|
||||||
|
|
||||||
|
@ -88,13 +88,16 @@ void W5100Class::send_data_processing(SOCKET s, uint8_t *data, uint16_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len)
|
void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek)
|
||||||
{
|
{
|
||||||
uint16_t ptr;
|
uint16_t ptr;
|
||||||
ptr = readSnRX_RD(s);
|
ptr = readSnRX_RD(s);
|
||||||
read_data(s, (uint8_t *)ptr, data, len);
|
read_data(s, (uint8_t *)ptr, data, len);
|
||||||
ptr += len;
|
if (!peek)
|
||||||
writeSnRX_RD(s, ptr);
|
{
|
||||||
|
ptr += len;
|
||||||
|
writeSnRX_RD(s, ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len)
|
void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len)
|
||||||
|
@ -155,7 +155,7 @@ public:
|
|||||||
* and after copy the data from receive buffer update the Rx write pointer register.
|
* and after copy the data from receive buffer update the Rx write pointer register.
|
||||||
* User should read upper byte first and lower byte later to get proper value.
|
* User should read upper byte first and lower byte later to get proper value.
|
||||||
*/
|
*/
|
||||||
void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len);
|
void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek = 0);
|
||||||
|
|
||||||
inline void setGatewayIp(uint8_t *_addr);
|
inline void setGatewayIp(uint8_t *_addr);
|
||||||
inline void getGatewayIp(uint8_t *_addr);
|
inline void getGatewayIp(uint8_t *_addr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user