From 8f57dd84b3d5a362ce456d7aa3ccbbe271dd1f5a Mon Sep 17 00:00:00 2001 From: Michael Iedema Date: Wed, 6 Jul 2016 12:19:56 -0700 Subject: [PATCH] revert cbb5d790e535aacd295e7df2325ea6edf971525d --- Sockets.cpp | 22 +++++++++++++--------- Sockets.h | 4 ++-- SocketsTest.cpp | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Sockets.cpp b/Sockets.cpp index 6880c3e..bb00e9f 100644 --- a/Sockets.cpp +++ b/Sockets.cpp @@ -199,21 +199,25 @@ int DatagramSocket::send(const struct sockaddr* dest, const char * message) return send(dest,message,length); } -int DatagramSocket::read(char* buffer, size_t length) -{ - socklen_t addr_len = sizeof(mSource); - int rd_length = recvfrom(mSocketFD, (void *) buffer, length, 0, - (struct sockaddr*) &mSource, &addr_len); - if ((rd_length==-1) && (errno!=EAGAIN)) { + + + +int DatagramSocket::read(char* buffer) +{ + socklen_t temp_len = sizeof(mSource); + int length = recvfrom(mSocketFD, (void*)buffer, MAX_UDP_LENGTH, 0, + (struct sockaddr*)&mSource,&temp_len); + if ((length==-1) && (errno!=EAGAIN)) { perror("DatagramSocket::read() failed"); devassert(0); throw SocketError(); } - return rd_length; + return length; } -int DatagramSocket::read(char* buffer, size_t length, unsigned timeout) + +int DatagramSocket::read(char* buffer, unsigned timeout) { fd_set fds; FD_ZERO(&fds); @@ -228,7 +232,7 @@ int DatagramSocket::read(char* buffer, size_t length, unsigned timeout) throw SocketError(); } if (sel==0) return -1; - if (FD_ISSET(mSocketFD,&fds)) return read(buffer, length); + if (FD_ISSET(mSocketFD,&fds)) return read(buffer); return -1; } diff --git a/Sockets.h b/Sockets.h index 365b745..213fcb7 100644 --- a/Sockets.h +++ b/Sockets.h @@ -110,7 +110,7 @@ public: @param buffer A char[MAX_UDP_LENGTH] procured by the caller. @return The number of bytes received or -1 on non-blocking pass. */ - int read(char* buffer, size_t length); + int read(char* buffer); /** Receive a packet with a timeout. @@ -118,7 +118,7 @@ public: @param maximum wait time in milliseconds @return The number of bytes received or -1 on timeout. */ - int read(char* buffer, size_t length, unsigned timeout); + int read(char* buffer, unsigned timeout); /** Send a packet to a given destination, other than the default. */ diff --git a/SocketsTest.cpp b/SocketsTest.cpp index 7ed2744..ef2fddf 100644 --- a/SocketsTest.cpp +++ b/SocketsTest.cpp @@ -45,7 +45,7 @@ void *testReaderIP(void *) int rc = 0; while (rc0) { COUT("read: " << buf); rc++; @@ -65,7 +65,7 @@ void *testReaderUnix(void *) int rc = 0; while (rc0) { COUT("read: " << buf); rc++;