Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror

Comment Re:So when... (Score 3, Informative) 575

Hi,

With Windows sockets, it is imperative to look at the error returned by send() if it fails. If the error is WSAENOBUFS, then it means that the packet you are trying to send is too large and must therefore be reduced. It is possible that the Java implementation doesn't do this.

Here is a snippet of code that is NECESSARY to be able to transfer data reliably on Windows. Please note that while just a single send() will work most of the time, there is no garantee that it will. Try, for example, sending chunks of 1MB, 8MB, 64MB, 128MB and 256MB and see at what point you get WSAENOBUFS. You may be surprised.

while (cbBuffer > 0)
{
for (cbToSend = cbBuffer;;)
{
cbSent = send(Socket,Buffer,cbToSend,0);
if (cbSent >= 0)
{
Buffer += cbSent;
cbBuffer -= cbSent;
break;
}
else if ((WSAGetLastError() != WSAENOBUFS) || ((cbToSend >>= 1) == 0)) return FALSE;
}
}

Note that on UNIX you should check errno for ENOBUFS as well, just in case.

Slashdot Top Deals

Klein bottle for rent -- inquire within.

Working...