Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: m2x-demo-all M2X_MTS_ACCEL_DEMO M2X_MTS_Accel M2X_K64F_ACCEL ... more
Diff: Client.cpp
- Revision:
- 0:f479e4f4db0e
- Child:
- 12:debf4b2f7960
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Client.cpp Wed Feb 12 19:43:34 2014 +0000
@@ -0,0 +1,60 @@
+#include "Client.h"
+#include "mbed.h"
+
+#include <stdint.h>
+
+Client::Client() : _len(0), _sock() {
+}
+
+Client::~Client() {
+}
+
+int Client::connect(const char *host, uint16_t port) {
+ return _sock.connect(host, port) == 0;
+}
+
+size_t Client::write(uint8_t b) {
+ return write(&b, 1);
+}
+
+size_t Client::write(const uint8_t *buf, size_t size) {
+ _sock.set_blocking(false, 15000);
+ // NOTE: we know it's dangerous to cast from (const uint8_t *) to (char *),
+ // but we are trying to maintain a stable interface between the Arduino
+ // one and the mbed one. What's more, while TCPSocketConnection has no
+ // intention of modifying the data here, it requires us to send a (char *)
+ // typed data. So we belive it's safe to do the cast here.
+ return _sock.send_all(const_cast<char*>((const char*) buf), size);
+}
+
+int Client::available() {
+ if (_len > 0) { return 1; }
+ int ret = read(_buf, 1);
+ if (ret <= 0) { return 0; }
+ _len = ret;
+ return 1;
+}
+
+int Client::read() {
+ if (_len > 0) {
+ _len = 0;
+ return _buf[0];
+ }
+ return -1;
+}
+
+int Client::read(uint8_t *buf, size_t size) {
+ return _sock.receive_all((char*) buf, size);
+}
+
+void Client::flush() {
+ // does nothing, TCP stack takes care of this
+}
+
+void Client::stop() {
+ _sock.close();
+}
+
+uint8_t Client::connected() {
+ return _sock.is_connected();
+}
AT&T M2X