1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Moving write errors out of return value into separate API methods.

write(), print(), println() now return size_t (and don't use negative values to signal errors).
Print adds writeError() for checking for write errors, clearWriteError() to reset the flag to false, and a protected setWriteError() for signalling errors.

http://code.google.com/p/arduino/issues/detail?id=598
This commit is contained in:
David A. Mellis
2011-08-26 16:08:14 -04:00
parent 929597375b
commit b73cf39d94
23 changed files with 184 additions and 173 deletions

View File

@ -70,17 +70,23 @@ int Client::connect(IPAddress ip, uint16_t port) {
return 1;
}
ssize_t Client::write(uint8_t b) {
size_t Client::write(uint8_t b) {
return write(&b, 1);
}
ssize_t Client::write(const char *str) {
size_t Client::write(const char *str) {
return write((const uint8_t *) str, strlen(str));
}
ssize_t Client::write(const uint8_t *buf, size_t size) {
if (_sock == MAX_SOCK_NUM) return -1;
if (!send(_sock, buf, size)) return -2;
size_t Client::write(const uint8_t *buf, size_t size) {
if (_sock == MAX_SOCK_NUM) {
setWriteError();
return 0;
}
if (!send(_sock, buf, size)) {
setWriteError();
return 0;
}
return size;
}