When i debug code contain SocketChannel write in Android, i got IllegalArgumentException, but the same code in windows no this exception, is there difference between Android and windows in SocketChannel write ?
UPDATE : (the code is part of open source project frostwire-android(this file in github), and this part is the same as vuze 4.5, i just add a try{} )
private int channelWrite(ByteBuffer buf) throws IOException
{
int written = 0;
while(remainingBytesToScatter > 0 && buf.remaining() > 0)
{
int currentWritten = 0;
try{
currentWritten = channel.write((ByteBuffer)(buf.slice().limit(Math.min(50+rnd.nextInt(100),buf.remaining()))));
}catch( Exception e ) {
if(e instanceof IOException) {
Log.d("", "chanel write IOException " + e.getMessage());
}else if(e instanceof IOException) {
Log.d("", "chanel write AsynchronousCloseException " + e.getMessage());
}else if(e instanceof ClosedByInterruptException) {
Log.d("", "chanel write ClosedByInterruptException " + e.getMessage());
}else if(e instanceof ClosedChannelException) {
Log.d("", "chanel write ClosedChannelException " + e.getMessage());
}else if(e instanceof NotYetConnectedException) {
Log.d("", "chanel write ClosedChannelException " + e.getMessage());
}else {
// while in second time, reach here
Log.d("", "chanel write unknown " + e.getMessage());
}
}
if(currentWritten == 0)
break;
buf.position(buf.position()+currentWritten);
remainingBytesToScatter -= currentWritten;
if(remainingBytesToScatter <= 0)
{
remainingBytesToScatter = 0;
try
{
channel.socket().setTcpNoDelay(false);
} catch (SocketException e)
{
Debug.printStackTrace(e);
}
}
written += currentWritten;
}
if(buf.remaining() > 0)
written += channel.write(buf);
return written;
}