Following Bruce's suggestion, I got something working. Subclassing DatagramSocket didn't work, but copying it into a new class and renaming it did :)
It is full of apocryphal code that I need to read up about to properly understand, for the moment I got a solution working that is not very pretty, but does the job for me...
As it is a hack it its current state I would not suggest to anyone that it be included in Juce, for example I've only edited the code for Windows (I don't have a mac).
But I paste it here regardless in case someone else wants to use it.
The below is in place of readSocket in SocketHelpers:
#include <winsock2.h> // this must come first to prevent errors with MSVC7
#include <WS2tcpip.h>
(...)
static int readFromSocket ( const SocketHandle handle,
void* const destBuffer, const int maxBytesToRead,
bool volatile& connected,
String& ipAddress,
const bool blockUntilSpecifiedAmountHasArrived) noexcept
{
int bytesRead = 0;
while (bytesRead < maxBytesToRead)
{
int bytesThisTime;
#if JUCE_WINDOWS
struct sockaddr_storage address;
juce_socklen_t len = sizeof (address);
bytesThisTime = recvfrom ( handle,
static_cast<char*> (destBuffer) + bytesRead,
maxBytesToRead - bytesRead,
0,
(struct sockaddr*) &address,
&len);
ipAddress = String(inet_ntoa (((struct sockaddr_in*) &address)->sin_addr));
//bytesThisTime = recv (handle, static_cast<char*> (destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
#else
while ((bytesThisTime = (int) ::read (handle, addBytesToPointer (destBuffer, bytesRead), (size_t) (maxBytesToRead - bytesRead))) < 0
&& errno == EINTR
&& connected)
{
}
#endif
if (bytesThisTime <= 0 || ! connected)
{
if (bytesRead == 0)
bytesRead = -1;
break;
}
bytesRead += bytesThisTime;
if (! blockUntilSpecifiedAmountHasArrived)
break;
}
return bytesRead;
}
And then in the XXXDatagramSocket class:
int XXXDatagramSocket::readFrom (void* destBuffer, const int maxBytesToRead, String& ipAddress, const bool blockUntilSpecifiedAmountHasArrived)
{
return connected ? IliasSocketHelpers::readFromSocket (handle, destBuffer, maxBytesToRead, connected, ipAddress, blockUntilSpecifiedAmountHasArrived)
: -1;
}