Wait() public method

Wait for the transfer to complete, timeout, or get cancelled.
public Wait ( int &transferredCount ) : ErrorCode
transferredCount int The number of bytes transferred on .
return ErrorCode
Ejemplo n.º 1
0
        internal static ErrorCode SyncTransfer(UsbTransfer transferContext,
                                               IntPtr buffer,
                                               int offset,
                                               int length,
                                               int timeout,
                                               int isoPacketSize,
                                               out int transferLength)
        {
            if (ReferenceEquals(transferContext, null))
            {
                throw new NullReferenceException("Invalid transfer context.");
            }
            if (offset < 0)
            {
                throw new ArgumentException("must be >=0", "offset");
            }
            if (isoPacketSize == 0 && transferContext.EndpointBase.Type == EndpointType.Isochronous)
            {
                Info.UsbEndpointInfo endpointInfo = transferContext.EndpointBase.EndpointInfo;
                if (endpointInfo != null)
                {
                    isoPacketSize = endpointInfo.Descriptor.MaxPacketSize;
                }
            }
            lock (transferContext.mTransferLOCK)
            {
                transferLength = 0;

                int       transferred;
                ErrorCode ec;
                transferContext.Fill(buffer, offset, length, timeout, isoPacketSize);

                while (true)
                {
                    ec = transferContext.Submit();
                    if (ec != ErrorCode.Success)
                    {
                        return(ec);
                    }

                    ec = transferContext.Wait(out transferred);
                    if (ec != ErrorCode.Success)
                    {
                        return(ec);
                    }

                    transferLength += transferred;

                    if ((ec != ErrorCode.None || transferred != UsbEndpointBase.MaxReadWrite) ||
                        !transferContext.IncrementTransfer(transferred))
                    {
                        break;
                    }
                }

                return(ec);
            }
        }
Ejemplo n.º 2
0
        internal static ErrorCode SyncTransfer(UsbTransfer transferContext,
                                               IntPtr buffer,
                                               int offset,
                                               int length,
                                               int timeout,
                                               int isoPacketSize,
                                               out int transferLength)
        {
            if (ReferenceEquals(transferContext, null)) throw new NullReferenceException("Invalid transfer context.");
            if (offset < 0) throw new ArgumentException("must be >=0", "offset");
            if (isoPacketSize == 0 && transferContext.EndpointBase.Type == EndpointType.Isochronous)
            {
                Info.UsbEndpointInfo endpointInfo = transferContext.EndpointBase.EndpointInfo;
                if (endpointInfo!=null)
                    isoPacketSize = endpointInfo.Descriptor.MaxPacketSize;
            }
            lock (transferContext.mTransferLOCK)
            {
                transferLength = 0;

                int transferred;
                ErrorCode ec;
                transferContext.Fill(buffer, offset, length, timeout, isoPacketSize);

                while (true)
                {
                    ec = transferContext.Submit();
                    if (ec != ErrorCode.Success) return ec;

                    ec = transferContext.Wait(out transferred);
                    if (ec != ErrorCode.Success) return ec;

                    transferLength += transferred;

                    if ((ec != ErrorCode.None || transferred != UsbEndpointBase.MaxReadWrite) ||
                        !transferContext.IncrementTransfer(transferred))
                        break;
                }

                return ec;
            }
        }