Add a bunch of APNs
Fork of C027_Support by
Socket/Socket.h@44:9d12223b78ff, 2014-04-17 (annotated)
- Committer:
- mazgch
- Date:
- Thu Apr 17 20:41:30 2014 +0000
- Revision:
- 44:9d12223b78ff
- Child:
- 47:9a89e5195721
adding mbed style (tcp)socket api
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 | 44:9d12223b78ff | 11 | _socket = -1; |
mazgch | 44:9d12223b78ff | 12 | _mdm = MDMParser::getInstance(); |
mazgch | 44:9d12223b78ff | 13 | if (_mdm == NULL) { |
mazgch | 44:9d12223b78ff | 14 | error("Socket constructor error: no modem instance available!\r\n"); |
mazgch | 44:9d12223b78ff | 15 | } |
mazgch | 44:9d12223b78ff | 16 | } |
mazgch | 44:9d12223b78ff | 17 | |
mazgch | 44:9d12223b78ff | 18 | void set_blocking(bool blocking, unsigned int timeout=1) { |
mazgch | 44:9d12223b78ff | 19 | _mdm->socketSetBlocking(_socket, blocking ? (unsigned int) -1 /* blocking */ : timeout); |
mazgch | 44:9d12223b78ff | 20 | } |
mazgch | 44:9d12223b78ff | 21 | |
mazgch | 44:9d12223b78ff | 22 | int close() { |
mazgch | 44:9d12223b78ff | 23 | bool ret = false; |
mazgch | 44:9d12223b78ff | 24 | if (_socket >= 0) |
mazgch | 44:9d12223b78ff | 25 | { |
mazgch | 44:9d12223b78ff | 26 | ret = _mdm->socketClose(_socket); |
mazgch | 44:9d12223b78ff | 27 | _mdm->socketFree(_socket); |
mazgch | 44:9d12223b78ff | 28 | _socket = -1; |
mazgch | 44:9d12223b78ff | 29 | } |
mazgch | 44:9d12223b78ff | 30 | return ret ? 0 : -1; |
mazgch | 44:9d12223b78ff | 31 | } |
mazgch | 44:9d12223b78ff | 32 | |
mazgch | 44:9d12223b78ff | 33 | ~Socket() { close(); } |
mazgch | 44:9d12223b78ff | 34 | |
mazgch | 44:9d12223b78ff | 35 | protected: |
mazgch | 44:9d12223b78ff | 36 | int _socket; |
mazgch | 44:9d12223b78ff | 37 | MDMParser* _mdm; |
mazgch | 44:9d12223b78ff | 38 | }; |
mazgch | 44:9d12223b78ff | 39 | |
mazgch | 44:9d12223b78ff | 40 | |
mazgch | 44:9d12223b78ff | 41 | #endif /* SOCKET_H_ */ |