summaryrefslogtreecommitdiffstats
path: root/src/UDPServer/UDPServer.cpp
diff options
context:
space:
mode:
authorTobias Frust <tobiasfrust@gmail.com>2016-10-13 10:27:01 +0200
committerGitHub <noreply@github.com>2016-10-13 10:27:01 +0200
commita38a5f1b646cdc992c3b602330a41036bc9bf7b1 (patch)
tree7fc93e5f5c3729d0fa013946fe60fa881a53579c /src/UDPServer/UDPServer.cpp
parent8af3d595e2856f81a46a91d67e96f53cb3b25d0f (diff)
parentcdab7a0b05f655a2f98f00f3fb8928e54b8c28d2 (diff)
downloadods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.tar.gz
ods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.tar.bz2
ods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.tar.xz
ods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.zip
Merge pull request #2 from tobiasfrust/master
Merge of the DetectorSimulator
Diffstat (limited to 'src/UDPServer/UDPServer.cpp')
-rw-r--r--src/UDPServer/UDPServer.cpp26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/UDPServer/UDPServer.cpp b/src/UDPServer/UDPServer.cpp
index 3a50d0c..8c9decf 100644
--- a/src/UDPServer/UDPServer.cpp
+++ b/src/UDPServer/UDPServer.cpp
@@ -168,31 +168,19 @@ int UDPServer::recv(char *msg, size_t max_size)
*
* \param[in] msg The buffer where the message will be saved.
* \param[in] max_size The size of the \p msg buffer in bytes.
- * \param[in] max_wait_ms The maximum number of milliseconds to wait for a message.
+ * \param[in] max_wait_s The maximum number of seconds to wait for a message.
*
* \return -1 if an error occurs or the function timed out, the number of bytes received otherwise.
*/
-int UDPServer::timed_recv(char *msg, size_t max_size, int max_wait_ms)
+int UDPServer::timed_recv(char *msg, size_t max_size, int max_wait_s)
{
fd_set s;
FD_ZERO(&s);
FD_SET(f_socket, &s);
struct timeval timeout;
- timeout.tv_sec = max_wait_ms / 1000;
- timeout.tv_usec = (max_wait_ms % 1000) * 1000;
- int retval = select(f_socket + 1, &s, &s, &s, &timeout);
- if(retval == -1)
- {
- // select() set errno accordingly
- return -1;
- }
- if(retval > 0)
- {
- // our socket has data
- return ::recv(f_socket, msg, max_size, 0);
- }
-
- // our socket has no data
- errno = EAGAIN;
- return -1;
+ timeout.tv_sec = max_wait_s;
+ timeout.tv_usec = 0;
+ setsockopt(f_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(struct timeval));
+ // our socket has data
+ return ::recv(f_socket, msg, max_size, 0);
}