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@48:205fe4c5a6d6, 2018-02-14 (annotated)
- Committer:
- sheralikhan
- Date:
- Wed Feb 14 06:03:43 2018 +0000
- Revision:
- 48:205fe4c5a6d6
- Parent:
- 45:b7cebc104c6c
kjhgtfrew
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 | { |
| bangbh | 45:b7cebc104c6c | 9 | public: |
| bangbh | 45:b7cebc104c6c | 10 | ~MQTTSocket() |
| bangbh | 45:b7cebc104c6c | 11 | { |
| bangbh | 45:b7cebc104c6c | 12 | if(mysock) |
| bangbh | 45:b7cebc104c6c | 13 | delete mysock; |
| bangbh | 45:b7cebc104c6c | 14 | } |
| bangbh | 45:b7cebc104c6c | 15 | |
| icraggs | 31:a51dd239b78e | 16 | int connect(char* hostname, int port, int timeout=1000) |
| icraggs | 31:a51dd239b78e | 17 | { |
| bangbh | 45:b7cebc104c6c | 18 | mysock->set_blocking(false, timeout); // 1 second Timeout |
| bangbh | 45:b7cebc104c6c | 19 | return mysock->connect(hostname, port); |
| icraggs | 31:a51dd239b78e | 20 | } |
| icraggs | 31:a51dd239b78e | 21 | |
| icraggs | 36:2f1ada427e56 | 22 | int read(unsigned char* buffer, int len, int timeout) |
| icraggs | 31:a51dd239b78e | 23 | { |
| bangbh | 45:b7cebc104c6c | 24 | mysock->set_blocking(false, timeout); |
| bangbh | 45:b7cebc104c6c | 25 | return mysock->receive((char*)buffer, len); |
| icraggs | 31:a51dd239b78e | 26 | } |
| icraggs | 31:a51dd239b78e | 27 | |
| icraggs | 36:2f1ada427e56 | 28 | int write(unsigned char* buffer, int len, int timeout) |
| icraggs | 31:a51dd239b78e | 29 | { |
| bangbh | 45:b7cebc104c6c | 30 | mysock->set_blocking(false, timeout); |
| bangbh | 45:b7cebc104c6c | 31 | return mysock->send((char*)buffer, len); |
| icraggs | 31:a51dd239b78e | 32 | } |
| icraggs | 31:a51dd239b78e | 33 | |
| icraggs | 31:a51dd239b78e | 34 | int disconnect() |
| icraggs | 31:a51dd239b78e | 35 | { |
| bangbh | 45:b7cebc104c6c | 36 | return mysock->close(); |
| icraggs | 31:a51dd239b78e | 37 | } |
| bangbh | 45:b7cebc104c6c | 38 | |
| bangbh | 45:b7cebc104c6c | 39 | protected: |
| bangbh | 45:b7cebc104c6c | 40 | void createSocket() { mysock = new TCPSocketConnection(); } |
| icraggs | 31:a51dd239b78e | 41 | private: |
| icraggs | 31:a51dd239b78e | 42 | |
| bangbh | 45:b7cebc104c6c | 43 | TCPSocketConnection *mysock; |
| icraggs | 31:a51dd239b78e | 44 | |
| icraggs | 31:a51dd239b78e | 45 | }; |
| icraggs | 31:a51dd239b78e | 46 | |
| icraggs | 31:a51dd239b78e | 47 | |
| icraggs | 31:a51dd239b78e | 48 | |
| icraggs | 31:a51dd239b78e | 49 | #endif |
