diff include/UdpServer.h @ 121:2197435e8fb4 scope-refactoring

UdpServer : read and waitUntilReady are now somehow Juce-compliant
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 22 Aug 2015 01:20:35 +0100
parents f5b5c648cd5d
children 719119fb2905
line wrap: on
line diff
--- a/include/UdpServer.h	Fri Aug 21 15:52:37 2015 +0100
+++ b/include/UdpServer.h	Sat Aug 22 01:20:35 2015 +0100
@@ -25,6 +25,7 @@
 		int inSocket;
 		struct sockaddr_in server;
 		struct timeval stTimeOut;
+		struct timeval stZeroTimeOut;
 		fd_set stReadFDS;
 		int size;
 		void *wasteBuffer;
@@ -39,11 +40,28 @@
 		bool init(int aPort);
 		bool bindToPort(int aPort);
 		int getBoundPort() const;
-		int read(void *destBuffer,
-				int maxBytesToRead);
+		/*
+		 * Reads bytes from the socket.
+		 *
+		 * Drop-in replacement for JUCE DatagramSocket::read()
+		 *
+			If blockUntilSpecifiedAmountHasArrived is true, the method will block until maxBytesToRead
+			bytes have been read, (or until an error occurs). If this flag is false, the method will
+			return as much data as is currently available without blocking.
+		 */
+		int read(void* destBuffer, int maxBytesToRead, bool blockUntilSpecifiedAmountHasArrived);
 		int emptySocket();
 		int emptySocket(int maxBytes);
 		void *getWaste();
+		/*
+		 * Waits until the socket is ready for reading or writing.
+		 *
+			Drop-in replacement for JUCE DatagramSocket::waitUntilReady.
+			If readyForReading is true, it will wait until the socket is ready for reading; if false, it will wait until it's ready for writing.
+			If the timeout is < 0, it will wait forever, or else will give up after the specified time.
+			If the socket is ready on return, this returns 1. If it times-out before the socket becomes ready, it returns 0. If an error occurs, it returns -1.
+		 */
+		int waitUntilReady(bool readyForReading, int timeoutMsecs);
 };