diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 53f0e7de7..5573bf458 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -5,6 +5,7 @@ ARDUINO 1.5.5 BETA * avr: Fixed buffer overflow in File::doBuffer() (dreggy) * avr: Fixed timeout in Bridge::transfer() * sam: Fixed SPI initialization (when using extended API and multiple CS) +* avr: Fixed behavior of EthernetClient::flush() ARDUINO 1.5.4 BETA 2013.09.10 diff --git a/libraries/Ethernet/arch/avr/utility/socket.cpp b/libraries/Ethernet/arch/avr/utility/socket.cpp index 154ba9895..5332981d2 100644 --- a/libraries/Ethernet/arch/avr/utility/socket.cpp +++ b/libraries/Ethernet/arch/avr/utility/socket.cpp @@ -256,7 +256,7 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t switch (W5100.readSnMR(s) & 0x07) { case SnMR::UDP : - W5100.read_data(s, (uint8_t *)ptr, head, 0x08); + W5100.read_data(s, ptr, head, 0x08); ptr += 8; // read peer's IP address, port number. addr[0] = head[0]; @@ -268,14 +268,14 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t data_len = head[6]; data_len = (data_len << 8) + head[7]; - W5100.read_data(s, (uint8_t *)ptr, buf, data_len); // data copy. + W5100.read_data(s, ptr, buf, data_len); // data copy. ptr += data_len; W5100.writeSnRX_RD(s, ptr); break; case SnMR::IPRAW : - W5100.read_data(s, (uint8_t *)ptr, head, 0x06); + W5100.read_data(s, ptr, head, 0x06); ptr += 6; addr[0] = head[0]; @@ -285,19 +285,19 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t data_len = head[4]; data_len = (data_len << 8) + head[5]; - W5100.read_data(s, (uint8_t *)ptr, buf, data_len); // data copy. + W5100.read_data(s, ptr, buf, data_len); // data copy. ptr += data_len; W5100.writeSnRX_RD(s, ptr); break; case SnMR::MACRAW: - W5100.read_data(s,(uint8_t*)ptr,head,2); + W5100.read_data(s, ptr, head, 2); ptr+=2; data_len = head[0]; data_len = (data_len<<8) + head[1] - 2; - W5100.read_data(s,(uint8_t*) ptr,buf,data_len); + W5100.read_data(s, ptr, buf, data_len); ptr += data_len; W5100.writeSnRX_RD(s, ptr); break; @@ -310,6 +310,12 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t return data_len; } +/** + * @brief Wait for buffered transmission to complete. + */ +void flush(SOCKET s) { + // TODO +} uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len) { diff --git a/libraries/Ethernet/arch/avr/utility/w5100.cpp b/libraries/Ethernet/arch/avr/utility/w5100.cpp index ad09b2251..5f8bdc850 100644 --- a/libraries/Ethernet/arch/avr/utility/w5100.cpp +++ b/libraries/Ethernet/arch/avr/utility/w5100.cpp @@ -98,7 +98,7 @@ void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uin { uint16_t ptr; ptr = readSnRX_RD(s); - read_data(s, (uint8_t *)ptr, data, len); + read_data(s, ptr, data, len); if (!peek) { ptr += len; @@ -106,13 +106,13 @@ void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uin } } -void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len) +void W5100Class::read_data(SOCKET s, volatile uint16_t src, volatile uint8_t *dst, uint16_t len) { uint16_t size; uint16_t src_mask; uint16_t src_ptr; - src_mask = (uint16_t)src & RMASK; + src_mask = src & RMASK; src_ptr = RBASE[s] + src_mask; if( (src_mask + len) > RSIZE ) diff --git a/libraries/Ethernet/arch/avr/utility/w5100.h b/libraries/Ethernet/arch/avr/utility/w5100.h index 8dccd9f29..f5644833e 100644 --- a/libraries/Ethernet/arch/avr/utility/w5100.h +++ b/libraries/Ethernet/arch/avr/utility/w5100.h @@ -138,7 +138,7 @@ public: * the data from Receive buffer. Here also take care of the condition while it exceed * the Rx memory uper-bound of socket. */ - void read_data(SOCKET s, volatile uint8_t * src, volatile uint8_t * dst, uint16_t len); + void read_data(SOCKET s, volatile uint16_t src, volatile uint8_t * dst, uint16_t len); /** * @brief This function is being called by send() and sendto() function also. diff --git a/libraries/Ethernet/arch/sam/utility/socket.cpp b/libraries/Ethernet/arch/sam/utility/socket.cpp index a9afb761c..5332981d2 100644 --- a/libraries/Ethernet/arch/sam/utility/socket.cpp +++ b/libraries/Ethernet/arch/sam/utility/socket.cpp @@ -310,6 +310,12 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t return data_len; } +/** + * @brief Wait for buffered transmission to complete. + */ +void flush(SOCKET s) { + // TODO +} uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len) { diff --git a/libraries/Ethernet/src/EthernetClient.cpp b/libraries/Ethernet/src/EthernetClient.cpp index b5911c5ee..3a88d15f8 100644 --- a/libraries/Ethernet/src/EthernetClient.cpp +++ b/libraries/Ethernet/src/EthernetClient.cpp @@ -120,8 +120,7 @@ int EthernetClient::peek() { } void EthernetClient::flush() { - while (available()) - read(); + ::flush(_sock); } void EthernetClient::stop() { diff --git a/libraries/Ethernet/src/utility/socket.h b/libraries/Ethernet/src/utility/socket.h index 17f89c7af..682e84709 100644 --- a/libraries/Ethernet/src/utility/socket.h +++ b/libraries/Ethernet/src/utility/socket.h @@ -13,6 +13,7 @@ extern int16_t recv(SOCKET s, uint8_t * buf, int16_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) +extern void flush(SOCKET s); // Wait for transmission to complete extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len);