mbed.org implementation of the abstract SmartREST library for the Cumulocity Platform SmartREST protocol.
Dependents: MbedSmartRestMain MbedSmartRestMain
Diff: MbedDataSource.cpp
- Revision:
- 11:e1bee9a77652
- Parent:
- 0:099f76422485
--- a/MbedDataSource.cpp Thu Oct 23 14:41:58 2014 +0200 +++ b/MbedDataSource.cpp Sat Nov 15 11:21:01 2014 +0100 @@ -29,10 +29,12 @@ #include "MbedDataSource.h" #include "stdio.h" -MbedDataSource::MbedDataSource(TCPSocketConnection& sock) : _sock(sock) +MbedDataSource::MbedDataSource(TCPSocketConnection& sock) : + _sock(sock), + _timeout(0), + _isTimedOut(false) { _offset = _len = 0; - _timeout = false; } MbedDataSource::~MbedDataSource() @@ -54,12 +56,17 @@ if (!_sock.is_connected()) return DS_STATUS_CLOSED; - if (_timeout) + if (_isTimedOut) return DS_STATUS_TIMEOUT; return DS_STATUS_OK; } +void MbedDataSource::setTimeout(size_t timeout) +{ + _timeout = timeout; +} + bool MbedDataSource::receive() { int ret; @@ -67,11 +74,11 @@ if (status() != DS_STATUS_OK) return false; - _sock.set_blocking(true, 60000); + _sock.set_blocking(true, _timeout); ret = _sock.receive(_buf, MBED_SOURCE_BUFFER_SIZE); if (ret < 0) { - _timeout = true; + _isTimedOut = true; return false; } @@ -84,5 +91,5 @@ void MbedDataSource::reset() { _len = _offset = 0; - _timeout = false; + _isTimedOut = false; }