Esempio n. 1
0
        private IAsyncResult StartInternalRead(Socket streamSocket, SocketStreamAsyncArgs readArgs, byte[] buffer, int offset, int size, AsyncCallback callback, object state)
        {
            IAsyncResult asyncResult;

            try
            {
                SocketStream.IoReq ioReq = new SocketStream.IoReq(state, callback);
                ioReq.RecordUserBuffer(buffer, offset, size);
                ioReq.InternalBuffer = readArgs.InternalBuffer;
                readArgs.SetBuffer(ioReq.InternalBuffer.Buffer, 0, size);
                readArgs.UserToken = ioReq;
                SocketStream.Tracer.TraceDebug((long)this.GetHashCode(), "ReceiveAsync called");
                if (!streamSocket.ReceiveAsync(readArgs))
                {
                    SocketStream.Tracer.TraceDebug((long)this.GetHashCode(), "ReceiveAsync sync completion");
                    this.IO_Completed(null, readArgs);
                }
                asyncResult = ioReq.AsyncResult;
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
                {
                    throw;
                }
                throw new IOException(ex.Message, ex);
            }
            return(asyncResult);
        }
Esempio n. 2
0
 private void BindArgsForUse(SimpleBuffer buf, SocketStreamAsyncArgs args)
 {
     args.InternalBuffer = buf;
     args.CompletionRtn  = new EventHandler <SocketAsyncEventArgs>(this.IO_Completed);
     args.Completed     += args.CompletionRtn;
     args.SetBuffer(buf.Buffer, 0, buf.Buffer.Length);
 }