Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 130:da1c61aa97ea | 131:ff28e56e5b7e |
|---|---|
| 80 { | 80 { |
| 81 if(enabled==false) | 81 if(enabled==false) |
| 82 return -1; | 82 return -1; |
| 83 FD_ZERO(&stReadFDS); | 83 FD_ZERO(&stReadFDS); |
| 84 FD_SET(inSocket, &stReadFDS); | 84 FD_SET(inSocket, &stReadFDS); |
| 85 int descriptorReady= select(inSocket+1, &stReadFDS, NULL, NULL, &stZeroTimeOut); | 85 int descriptorReady= select(inSocket+1, &stReadFDS, NULL, NULL, &stZeroTimeOut); //TODO: this is not JUCE-compliant |
| 86 if(descriptorReady<0){ //an error occurred | 86 if(descriptorReady<0){ //an error occurred |
| 87 return -1; | 87 return -1; |
| 88 } | 88 } |
| 89 int numberOfBytes=0; | 89 int numberOfBytes=0; |
| 90 // do | 90 // do |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 // while (blockUntilSpecifiedAmountHasArrived && numberOfBytes==maxBytesToRead); | 100 // while (blockUntilSpecifiedAmountHasArrived && numberOfBytes==maxBytesToRead); |
| 101 return numberOfBytes; | 101 return numberOfBytes; |
| 102 } | 102 } |
| 103 int UdpServer::emptySocket(){ | 103 int UdpServer::empty(){ |
| 104 return emptySocket(0); | 104 return empty(0); |
| 105 } | 105 } |
| 106 int UdpServer::emptySocket(int maxBytes){//discards up to maxBytes from the socket. Returns the number of bytes discarded. | 106 int UdpServer::empty(int maxCount){ |
| 107 if(wasteBuffer==NULL) | 107 int count=0; |
| 108 return -1; | 108 int n; |
| 109 int numberOfBytes=0; | 109 do { |
| 110 while(int n=read(wasteBuffer, wasteBufferSize, false)){// calls the read function until it does not return any more bytes (i.e.: socket is empty) | 110 if(waitUntilReady(true, 0)==0) |
| 111 if(n>0) | 111 return 0; |
| 112 numberOfBytes+=n; | 112 float waste; |
| 113 if(n<0) | 113 n=read(&waste, sizeof(float), false); |
| 114 return -1; | 114 count++; |
| 115 if(maxBytes>0 && numberOfBytes>=maxBytes) | 115 } while (n>0 && (maxCount<=0 || maxCount<count)); |
| 116 break; | 116 printf("socket emptied with %d reads\n", count); |
| 117 }; | 117 return count; |
| 118 return numberOfBytes; | |
| 119 } | 118 } |
| 120 void* UdpServer::getWaste(){ //returns the last datagram retrieved by emptySocket() | |
| 121 return wasteBuffer; | |
| 122 } | |
| 123 |
