Adding Client::peek() in Ethernet library (issue #349).

This commit is contained in:
David A. Mellis 2010-09-16 01:11:19 +00:00
parent 76641d1a87
commit ea8a1182b8
6 changed files with 30 additions and 4 deletions

View File

@ -83,6 +83,14 @@ int Client::read() {
return b;
}
int Client::peek() {
uint8_t b;
if (!available())
return -1;
::peek(_sock, &b);
return b;
}
void Client::flush() {
while (available())
read();

View File

@ -17,6 +17,7 @@ public:
virtual void write(const uint8_t *buf, size_t size);
virtual int available();
virtual int read();
virtual int peek();
virtual void flush();
void stop();
uint8_t connected();

View File

@ -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.
* Unlike TCP transmission, The peer's destination address and the port is needed.

View File

@ -10,6 +10,7 @@ extern void disconnect(SOCKET s); // disconnect the 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 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 recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW)

View File

@ -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;
ptr = readSnRX_RD(s);
read_data(s, (uint8_t *)ptr, data, len);
ptr += len;
writeSnRX_RD(s, ptr);
if (!peek)
{
ptr += len;
writeSnRX_RD(s, ptr);
}
}
void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len)

View File

@ -155,7 +155,7 @@ public:
* 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.
*/
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 getGatewayIp(uint8_t *_addr);