Own fork of C027_Support

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of C027_Support by u-blox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Socket.h Source File

Socket.h

00001 #ifndef SOCKET_H_
00002 #define SOCKET_H_
00003 
00004 #include "MDM.h"
00005 
00006 /** Socket file descriptor and select wrapper
00007   */
00008 class Socket {
00009 public:
00010     Socket() {
00011         _socket  = -1;
00012         _timeout_ms = MDMParser::TIMEOUT_BLOCKING;
00013         _mdm     = NULL;
00014     }
00015     
00016     void set_blocking(bool blocking, unsigned int timeout = 1500) {
00017         _timeout_ms = blocking ? MDMParser::TIMEOUT_BLOCKING : (int)timeout;
00018         if (_socket >= 0) {
00019             _mdm->socketSetBlocking(_socket, _timeout_ms); 
00020         }
00021     }
00022     
00023     int close() {
00024         bool ret = false;
00025         if (_socket >= 0)
00026         {
00027             ret = _mdm->socketClose(_socket);
00028             _mdm->socketFree(_socket);
00029             _socket = -1;
00030             _timeout_ms = MDMParser::TIMEOUT_BLOCKING;
00031         }
00032         return ret ? 0 : -1;
00033     }
00034     
00035     ~Socket() { close(); }
00036     
00037 protected:
00038     int _socket;
00039     int _timeout_ms;
00040     MDMParser* _mdm;
00041 };
00042 
00043 
00044 #endif /* SOCKET_H_ */