internal static ErrorCode SyncTransfer(TransferContextBase transferContext, IntPtr buffer, int offset, int length, int timeout, out int transferLength) { if (ReferenceEquals(transferContext, null)) { throw new NullReferenceException("Invalid transfer context."); } if (offset < 0) { throw new ArgumentException("must be >=0", "offset"); } lock (transferContext) { transferLength = 0; int transferred; ErrorCode ec; transferContext.Fill(buffer, offset, length, timeout); while (true) { ec = transferContext.Submit(); if (ec == ErrorCode.IoEndpointGlobalCancelRedo) { continue; } if (ec != ErrorCode.Success) { return(ec); } ec = transferContext.Wait(out transferred); if (ec == ErrorCode.IoEndpointGlobalCancelRedo) { continue; } if (ec != ErrorCode.Success) { return(ec); } transferLength += transferred; if ((ec != ErrorCode.None || transferred != UsbEndpointBase.MaxReadWrite) || !transferContext.IncrementTransfer(transferred)) { break; } } return(ec); } }
internal static ErrorCode SyncTransfer(TransferContextBase transferContext, IntPtr buffer, int offset, int length, int timeout, out int transferLength) { if (ReferenceEquals(transferContext, null)) throw new NullReferenceException("Invalid transfer context."); if (offset < 0) throw new ArgumentException("must be >=0", "offset"); lock (transferContext) { transferLength = 0; int transferred; ErrorCode ec; transferContext.Fill(buffer, offset, length, timeout); while (true) { ec = transferContext.Submit(); if (ec == ErrorCode.IoEndpointGlobalCancelRedo) continue; if (ec != ErrorCode.Success) return ec; ec = transferContext.Wait(out transferred); if (ec == ErrorCode.IoEndpointGlobalCancelRedo) continue; if (ec != ErrorCode.Success) return ec; transferLength += transferred; if ((ec != ErrorCode.None || transferred != UsbEndpointBase.MaxReadWrite) || !transferContext.IncrementTransfer(transferred)) break; } return ec; } }