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.
Fork of MQTT by
MQTTSocket.h@49:08571008b958, 2017-09-07 (annotated)
- Committer:
- Jan Jongboom
- Date:
- Thu Sep 07 09:55:54 2017 +0100
- Revision:
- 49:08571008b958
- Parent:
- 43:21da1f744243
- Child:
- 54:ff9e5c4b52d0
Add is_connected function to MQTTSocket
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| icraggs | 31:a51dd239b78e | 1 | #if !defined(MQTTSOCKET_H) |
| icraggs | 31:a51dd239b78e | 2 | #define MQTTSOCKET_H |
| icraggs | 31:a51dd239b78e | 3 | |
| icraggs | 43:21da1f744243 | 4 | #include "MQTTmbed.h" |
| icraggs | 31:a51dd239b78e | 5 | #include "TCPSocketConnection.h" |
| icraggs | 31:a51dd239b78e | 6 | |
| icraggs | 31:a51dd239b78e | 7 | class MQTTSocket |
| icraggs | 31:a51dd239b78e | 8 | { |
| Jan Jongboom |
49:08571008b958 | 9 | public: |
| icraggs | 31:a51dd239b78e | 10 | int connect(char* hostname, int port, int timeout=1000) |
| icraggs | 31:a51dd239b78e | 11 | { |
| Jan Jongboom |
49:08571008b958 | 12 | mysock.set_blocking(false, timeout); // 1 second Timeout |
| icraggs | 31:a51dd239b78e | 13 | return mysock.connect(hostname, port); |
| icraggs | 31:a51dd239b78e | 14 | } |
| icraggs | 31:a51dd239b78e | 15 | |
| icraggs | 36:2f1ada427e56 | 16 | int read(unsigned char* buffer, int len, int timeout) |
| icraggs | 31:a51dd239b78e | 17 | { |
| Jan Jongboom |
49:08571008b958 | 18 | mysock.set_blocking(false, timeout); |
| icraggs | 36:2f1ada427e56 | 19 | return mysock.receive((char*)buffer, len); |
| icraggs | 31:a51dd239b78e | 20 | } |
| Jan Jongboom |
49:08571008b958 | 21 | |
| icraggs | 36:2f1ada427e56 | 22 | int write(unsigned char* buffer, int len, int timeout) |
| icraggs | 31:a51dd239b78e | 23 | { |
| Jan Jongboom |
49:08571008b958 | 24 | mysock.set_blocking(false, timeout); |
| icraggs | 36:2f1ada427e56 | 25 | return mysock.send((char*)buffer, len); |
| icraggs | 31:a51dd239b78e | 26 | } |
| Jan Jongboom |
49:08571008b958 | 27 | |
| icraggs | 31:a51dd239b78e | 28 | int disconnect() |
| icraggs | 31:a51dd239b78e | 29 | { |
| icraggs | 31:a51dd239b78e | 30 | return mysock.close(); |
| icraggs | 31:a51dd239b78e | 31 | } |
| Jan Jongboom |
49:08571008b958 | 32 | |
| Jan Jongboom |
49:08571008b958 | 33 | bool is_connected() |
| Jan Jongboom |
49:08571008b958 | 34 | { |
| Jan Jongboom |
49:08571008b958 | 35 | return mysock.is_connected(); |
| Jan Jongboom |
49:08571008b958 | 36 | } |
| Jan Jongboom |
49:08571008b958 | 37 | |
| icraggs | 31:a51dd239b78e | 38 | private: |
| icraggs | 31:a51dd239b78e | 39 | |
| Jan Jongboom |
49:08571008b958 | 40 | TCPSocketConnection mysock; |
| Jan Jongboom |
49:08571008b958 | 41 | |
| icraggs | 31:a51dd239b78e | 42 | }; |
| icraggs | 31:a51dd239b78e | 43 | |
| icraggs | 31:a51dd239b78e | 44 | #endif |
