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
Revision 66:69072b3c5bca, committed 2014-05-13
- Comitter:
- mazgch
- Date:
- Tue May 13 15:56:28 2014 +0000
- Parent:
- 65:dd94f920a762
- Child:
- 67:ff9472d344d4
- Commit message:
- use a named constant for blocking timeout
Changed in this revision
--- a/MDM.cpp Tue May 13 14:41:03 2014 +0000
+++ b/MDM.cpp Tue May 13 15:56:28 2014 +0000
@@ -189,7 +189,8 @@
// relax a bit
WAIT_MS(10);
}
- while (timer.read_ms() < timeout_ms);
+ while ((timeout_ms == TIMEOUT_BLOCKING) ||
+ (timer.read_ms() < timeout_ms));
timer.stop();
timer.reset();
return WAIT;
@@ -706,7 +707,7 @@
// successfull
_sockets[socket].state = SOCK_CREATED;
_sockets[socket].pending = 0;
- _sockets[socket].timeout_ms = 0; // non blocking
+ _sockets[socket].timeout_ms = TIMEOUT_BLOCKING;
return socket;
}
@@ -735,7 +736,7 @@
return _sockets[socket].state == SOCK_CONNECTED;
}
-bool MDMParser::socketSetBlocking(int socket, unsigned int timeout_ms)
+bool MDMParser::socketSetBlocking(int socket, int timeout_ms)
{
TRACE("socketSetBlocking(%d,%d)\r\n", socket, timeout_ms);
if (!ISSOCKET(socket))
@@ -844,7 +845,7 @@
buf += blk;
_sockets[socket].pending -= blk;
} else if ((_sockets[socket].state == SOCK_CONNECTED) && (
- (_sockets[socket].timeout_ms == (unsigned int)-1 /* blocking */) ||
+ (_sockets[socket].timeout_ms == TIMEOUT_BLOCKING) ||
(timer.read_ms() < _sockets[socket].timeout_ms))){
// allow to receive unsolicited commands
waitFinalResp(NULL, NULL, 10);
@@ -900,7 +901,7 @@
cnt += blk;
buf += blk;
_sockets[socket].pending -= blk;
- } else if ((_sockets[socket].timeout_ms == (unsigned int)-1 /* blocking */) ||
+ } else if ((_sockets[socket].timeout_ms == TIMEOUT_BLOCKING) ||
(timer.read_ms() < _sockets[socket].timeout_ms)) {
// allow to receive unsolicited commands
waitFinalResp(NULL, NULL, 10);
--- a/MDM.h Tue May 13 14:41:03 2014 +0000
+++ b/MDM.h Tue May 13 15:56:28 2014 +0000
@@ -172,7 +172,7 @@
\param timeout_ms -1 blocking, else non blocking timeout in ms
\return 0 if successful or SOCKET_ERROR on failure
*/
- bool socketSetBlocking(int socket, unsigned int timeout_ms);
+ bool socketSetBlocking(int socket, int timeout_ms);
/** Write socket data
\param socket the socket handle
@@ -324,7 +324,10 @@
TYPE_NOANSWER = 0x260000,
TYPE_PROMPT = 0x300000,
TYPE_PLUS = 0x400000,
- TYPE_TEXT = 0x500000
+ TYPE_TEXT = 0x500000,
+
+ // special timout constant
+ TIMEOUT_BLOCKING = -1
};
/** Get a line from the physical interface. This function need
@@ -457,7 +460,7 @@
IP _ip; //!< assigned ip address
// management struture for sockets
typedef enum { SOCK_FREE, SOCK_CREATED, SOCK_CONNECTED } SockState;
- typedef struct { SockState state; int pending; unsigned int timeout_ms; } SockCtrl;
+ typedef struct { SockState state; int pending; int timeout_ms; } SockCtrl;
// LISA-C has 6 TCP and 6 UDP sockets starting at index 18
// LISA-U and SARA-G have 7 sockets starting at index 1
SockCtrl _sockets[32];
--- a/Socket/Socket.h Tue May 13 14:41:03 2014 +0000
+++ b/Socket/Socket.h Tue May 13 15:56:28 2014 +0000
@@ -9,12 +9,12 @@
public:
Socket() {
_socket = -1;
- _timeout = -1;
+ _timeout = MDMParser::TIMEOUT_BLOCKING;
_mdm = NULL;
}
void set_blocking(bool blocking, unsigned int timeout=1) {
- _timeout = blocking ? (unsigned int) -1 /* blocking */ : timeout;
+ _timeout = blocking ? MDMParser::TIMEOUT_BLOCKING : timeout;
if (_socket >= 0) {
_mdm->socketSetBlocking(_socket, _timeout);
}
@@ -27,6 +27,7 @@
ret = _mdm->socketClose(_socket);
_mdm->socketFree(_socket);
_socket = -1;
+ _timeout = MDMParser::TIMEOUT_BLOCKING;
}
return ret ? 0 : -1;
}
@@ -35,7 +36,7 @@
protected:
int _socket;
- int _timeout;
+ unsigned int _timeout;
MDMParser* _mdm;
};
