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 C027_Support by
Socket/Socket.h@139:b9a7b3f44734, 2016-09-10 (annotated)
- Committer:
- simonpfeifhofer
- Date:
- Sat Sep 10 10:12:25 2016 +0000
- Revision:
- 139:b9a7b3f44734
- Parent:
- 67:ff9472d344d4
* fix parameter name
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mazgch | 44:9d12223b78ff | 1 | #ifndef SOCKET_H_ |
| mazgch | 44:9d12223b78ff | 2 | #define SOCKET_H_ |
| mazgch | 44:9d12223b78ff | 3 | |
| mazgch | 44:9d12223b78ff | 4 | #include "MDM.h" |
| mazgch | 44:9d12223b78ff | 5 | |
| mazgch | 44:9d12223b78ff | 6 | /** Socket file descriptor and select wrapper |
| mazgch | 44:9d12223b78ff | 7 | */ |
| mazgch | 44:9d12223b78ff | 8 | class Socket { |
| mazgch | 44:9d12223b78ff | 9 | public: |
| mazgch | 44:9d12223b78ff | 10 | Socket() { |
| mazgch | 54:7ba8e4c218e2 | 11 | _socket = -1; |
| mazgch | 67:ff9472d344d4 | 12 | _timeout_ms = MDMParser::TIMEOUT_BLOCKING; |
| mazgch | 54:7ba8e4c218e2 | 13 | _mdm = NULL; |
| mazgch | 44:9d12223b78ff | 14 | } |
| mazgch | 44:9d12223b78ff | 15 | |
| mazgch | 67:ff9472d344d4 | 16 | void set_blocking(bool blocking, unsigned int timeout = 1500) { |
| mazgch | 67:ff9472d344d4 | 17 | _timeout_ms = blocking ? MDMParser::TIMEOUT_BLOCKING : (int)timeout; |
| mazgch | 54:7ba8e4c218e2 | 18 | if (_socket >= 0) { |
| mazgch | 67:ff9472d344d4 | 19 | _mdm->socketSetBlocking(_socket, _timeout_ms); |
| mazgch | 54:7ba8e4c218e2 | 20 | } |
| mazgch | 44:9d12223b78ff | 21 | } |
| mazgch | 44:9d12223b78ff | 22 | |
| mazgch | 44:9d12223b78ff | 23 | int close() { |
| mazgch | 44:9d12223b78ff | 24 | bool ret = false; |
| mazgch | 44:9d12223b78ff | 25 | if (_socket >= 0) |
| mazgch | 44:9d12223b78ff | 26 | { |
| mazgch | 44:9d12223b78ff | 27 | ret = _mdm->socketClose(_socket); |
| mazgch | 44:9d12223b78ff | 28 | _mdm->socketFree(_socket); |
| mazgch | 44:9d12223b78ff | 29 | _socket = -1; |
| mazgch | 67:ff9472d344d4 | 30 | _timeout_ms = MDMParser::TIMEOUT_BLOCKING; |
| mazgch | 44:9d12223b78ff | 31 | } |
| mazgch | 44:9d12223b78ff | 32 | return ret ? 0 : -1; |
| mazgch | 44:9d12223b78ff | 33 | } |
| mazgch | 44:9d12223b78ff | 34 | |
| mazgch | 49:8175b2b72d6b | 35 | ~Socket() { close(); } |
| mazgch | 44:9d12223b78ff | 36 | |
| mazgch | 44:9d12223b78ff | 37 | protected: |
| mazgch | 44:9d12223b78ff | 38 | int _socket; |
| mazgch | 67:ff9472d344d4 | 39 | int _timeout_ms; |
| mazgch | 44:9d12223b78ff | 40 | MDMParser* _mdm; |
| mazgch | 44:9d12223b78ff | 41 | }; |
| mazgch | 44:9d12223b78ff | 42 | |
| mazgch | 44:9d12223b78ff | 43 | |
| mazgch | 44:9d12223b78ff | 44 | #endif /* SOCKET_H_ */ |
