From 0681fc1f177f7c94b4e98bb0931a5efda50f32b0 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 26 Apr 2009 13:10:34 +0000 Subject: Adding write(str) and write(buf, size) methods to Print class and Ethernet library Client and Server classes. This allows sending a whole string or buffer at once, reducing the number of ethernet packets. --- libraries/Ethernet/Client.cpp | 9 +++++++++ libraries/Ethernet/Client.h | 2 ++ libraries/Ethernet/Server.cpp | 15 +++++++++++++-- libraries/Ethernet/Server.h | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'libraries/Ethernet') diff --git a/libraries/Ethernet/Client.cpp b/libraries/Ethernet/Client.cpp index c62e26c..51096db 100644 --- a/libraries/Ethernet/Client.cpp +++ b/libraries/Ethernet/Client.cpp @@ -2,6 +2,7 @@ extern "C" { #include "types.h" #include "w5100.h" #include "socket.h" + #include "string.h" } #include "Ethernet.h" @@ -50,6 +51,14 @@ void Client::write(uint8_t b) { send(_sock, &b, 1); } +void Client::write(const char *str) { + send(_sock, (const uint8_t *)str, strlen(str)); +} + +void Client::write(const uint8_t *buf, size_t size) { + send(_sock, buf, size); +} + int Client::available() { return getSn_RX_RSR(_sock); } diff --git a/libraries/Ethernet/Client.h b/libraries/Ethernet/Client.h index f269e9b..7c0ccdf 100644 --- a/libraries/Ethernet/Client.h +++ b/libraries/Ethernet/Client.h @@ -15,6 +15,8 @@ public: uint8_t status(); uint8_t connect(); virtual void write(uint8_t); + virtual void write(const char *str); + virtual void write(const uint8_t *buf, size_t size); int available(); int read(); void flush(); diff --git a/libraries/Ethernet/Server.cpp b/libraries/Ethernet/Server.cpp index 351f838..d17a5d3 100644 --- a/libraries/Ethernet/Server.cpp +++ b/libraries/Ethernet/Server.cpp @@ -2,6 +2,7 @@ extern "C" { #include "types.h" #include "w5100.h" #include "socket.h" + #include "string.h" } #include "Ethernet.h" @@ -66,6 +67,16 @@ Client Server::available() } void Server::write(uint8_t b) +{ + write(&b, 1); +} + +void Server::write(const char *str) +{ + write((const uint8_t *)str, strlen(str)); +} + +void Server::write(const uint8_t *buffer, size_t size) { accept(); @@ -74,7 +85,7 @@ void Server::write(uint8_t b) if (EthernetClass::_server_port[sock] == _port && client.status() == SOCK_ESTABLISHED) { - client.write(b); + client.write(buffer, size); } } -} \ No newline at end of file +} diff --git a/libraries/Ethernet/Server.h b/libraries/Ethernet/Server.h index d35e691..73d6a5e 100644 --- a/libraries/Ethernet/Server.h +++ b/libraries/Ethernet/Server.h @@ -18,6 +18,8 @@ public: Client available(); void begin(); virtual void write(uint8_t); + virtual void write(const char *str); + virtual void write(const uint8_t *buf, size_t size); }; #endif -- cgit v1.2.3-18-g5258