diff core/UdpServer.cpp @ 131:ff28e56e5b7e scope-refactoring

Updated Network files to match Udpioplugin 18:fb5a61b10223
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 26 Aug 2015 02:02:10 +0100
parents 719119fb2905
children e77e2e712fbc
line wrap: on
line diff
--- a/core/UdpServer.cpp	Tue Aug 25 11:14:25 2015 +0100
+++ b/core/UdpServer.cpp	Wed Aug 26 02:02:10 2015 +0100
@@ -82,7 +82,7 @@
 		return -1;
 	FD_ZERO(&stReadFDS);
 	FD_SET(inSocket, &stReadFDS);
-	int descriptorReady= select(inSocket+1, &stReadFDS, NULL, NULL, &stZeroTimeOut);
+	int descriptorReady= select(inSocket+1, &stReadFDS, NULL, NULL, &stZeroTimeOut); //TODO: this is not JUCE-compliant
 	if(descriptorReady<0){ //an error occurred
 		return -1;
 	}
@@ -100,24 +100,19 @@
 //	while (blockUntilSpecifiedAmountHasArrived && numberOfBytes==maxBytesToRead);
 	return numberOfBytes;
 }
-int UdpServer::emptySocket(){
-	return emptySocket(0);
+int UdpServer::empty(){
+	return empty(0);
 }
-int UdpServer::emptySocket(int maxBytes){//discards up to maxBytes from the socket. Returns the number of bytes discarded.
-	if(wasteBuffer==NULL)
-		return -1;
-	int numberOfBytes=0;
-	while(int n=read(wasteBuffer, wasteBufferSize, false)){// calls the read function until it does not return any more bytes (i.e.: socket is empty)
-		if(n>0)
-			numberOfBytes+=n;
-		if(n<0)
-			return -1;
-		if(maxBytes>0 && numberOfBytes>=maxBytes)
-			break;
-	};
-	return numberOfBytes;
+int UdpServer::empty(int maxCount){
+	int count=0;
+	int n;
+	do {
+		if(waitUntilReady(true, 0)==0)
+			return 0;
+		float waste;
+		n=read(&waste, sizeof(float), false);
+		count++;
+	} while (n>0 && (maxCount<=0 || maxCount<count));
+	printf("socket emptied with %d reads\n", count);
+	return count;
 }
-void* UdpServer::getWaste(){ //returns the last datagram retrieved by emptySocket()
-	return wasteBuffer;
-}
-