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.
Dependents: EthernetInterface EthernetInterface_RSF EthernetInterface EthernetInterface ... more
Diff: Socket.cpp
- Revision:
- 6:cd2e5559786d
- Parent:
- 5:300e7ad2dc1d
- Child:
- 10:d24738f4ef99
diff -r 300e7ad2dc1d -r cd2e5559786d Socket.cpp
--- a/Socket.cpp Thu Jul 26 15:07:32 2012 +0000
+++ b/Socket.cpp Fri Jul 27 13:58:53 2012 +0000
@@ -36,29 +36,27 @@
return 0;
}
-
-void Socket::set_timeout(int timeout) {
- _timeout.tv_sec = timeout / 1000;
- _timeout.tv_usec = (timeout - (_timeout.tv_sec * 1000)) * 1000;
-}
-
-int Socket::select(fd_set* readset, fd_set* writeset) {
- if ((_timeout.tv_sec == 0) && (_timeout.tv_usec == 0))
+int Socket::select(struct timeval *timeout, bool read, bool write) {
+ if ((timeout->tv_sec == 0) && (timeout->tv_usec == 0))
return 0;
- FD_ZERO(&_fdSet);
- FD_SET(_sock_fd, &_fdSet);
+ fd_set fdSet;
+ FD_ZERO(&fdSet);
+ FD_SET(_sock_fd, &fdSet);
- int ret = lwip_select(FD_SETSIZE, readset, writeset, NULL, &_timeout);
- return (ret <= 0 || !FD_ISSET(_sock_fd, &_fdSet)) ? (-1) : (0);
+ fd_set* readset = (read ) ? (&fdSet) : (NULL);
+ fd_set* writeset = (write) ? (&fdSet) : (NULL);
+
+ int ret = lwip_select(FD_SETSIZE, readset, writeset, NULL, timeout);
+ return (ret <= 0 || !FD_ISSET(_sock_fd, &fdSet)) ? (-1) : (0);
}
-int Socket::wait_readable(void) {
- return select(&_fdSet, NULL);
+int Socket::wait_readable(TimeInterval& timeout) {
+ return select(&timeout._time, true, false);
}
-int Socket::wait_writable(void) {
- return select(NULL, &_fdSet);
+int Socket::wait_writable(TimeInterval& timeout) {
+ return select(&timeout._time, false, true);
}
int Socket::close() {
@@ -70,3 +68,8 @@
return 0;
}
+
+TimeInterval::TimeInterval(int ms) {
+ _time.tv_sec = ms / 1000;
+ _time.tv_usec = (ms - (_time.tv_sec * 1000)) * 1000;
+}
