public static long write(object nd, FileDescriptor fd, ByteBuffer[] bufs, int offset, int length) { #if FIRST_PASS return(0); #else ByteBuffer[] altBufs = null; List <ArraySegment <byte> > list = new List <ArraySegment <byte> >(length); for (int i = 0; i < length; i++) { ByteBuffer bb = bufs[i + offset]; if (!bb.hasArray()) { if (altBufs == null) { altBufs = new ByteBuffer[bufs.Length]; } ByteBuffer abb = ByteBuffer.allocate(bb.remaining()); int pos = bb.position(); abb.put(bb); bb.position(pos); abb.flip(); bb = altBufs[i + offset] = abb; } list.Add(new ArraySegment <byte>(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining())); } int count; try { count = fd.getSocket().Send(list); } catch (System.Net.Sockets.SocketException x) { if (x.ErrorCode == global::java.net.SocketUtil.WSAEWOULDBLOCK) { count = 0; } else { throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x); } } catch (ObjectDisposedException) { throw new global::java.net.SocketException("Socket is closed"); } int total = count; for (int i = 0; total > 0 && i < length; i++) { ByteBuffer bb = bufs[i + offset]; int consumed = Math.Min(total, bb.remaining()); bb.position(bb.position() + consumed); total -= consumed; } return(count); #endif }
public static void BlockCopy(ByteBuffer src, int srcPos, ByteBuffer dst, int dstPos, int length) { if (src.hasArray() && dst.hasArray()) { java.lang.System.arraycopy(src.array(), src.arrayOffset() + srcPos, dst.array(), dst.arrayOffset() + dstPos, length); } else { if (src.limit() - srcPos < length || dst.limit() - dstPos < length) { throw new java.lang.IndexOutOfBoundsException(); } for (int i = 0; i < length; i++) { // TODO: ByteBuffer.put is polymorphic, and might be slow here dst.put(dstPos++, src.get(srcPos++)); } } }