private void AsyncReadCallback(IAsyncResult asyncResult)
        {
            SendAndReceiveContext context = (SendAndReceiveContext)asyncResult.AsyncState;

            try {
                NetworkStream stream = context.stream;
                int           n      = stream.EndRead(asyncResult);
                if (n > 0)
                {
                    context.offset += n;
                    context.length -= n;
                    if (context.offset < context.buf.Length)
                    {
                        stream.BeginRead(context.buf, context.offset, context.length, new AsyncCallback(AsyncReadCallback), context);
                        return;
                    }
                }
                if (context.offset < context.buf.Length)
                {
                    context.e = new HproseException("Unexpected EOF");
                    context.callback(asyncResult);
                    return;
                }
                context.readCallback(asyncResult);
            }
            catch (Exception e) {
                context.e = e;
                context.callback(asyncResult);
            }
        }
        private void WritePartCallback(IAsyncResult asyncResult)
        {
            SendAndReceiveContext context = (SendAndReceiveContext)asyncResult.AsyncState;

            try {
                NetworkStream stream = context.stream;
                stream.EndWrite(asyncResult);
                stream.BeginWrite(context.buf, context.offset, context.length, new AsyncCallback(WriteFullCallback), context);
            }
            catch (Exception e) {
                context.e = e;
                context.callback(asyncResult);
            }
        }
        private void WriteFullCallback(IAsyncResult asyncResult)
        {
            SendAndReceiveContext context = (SendAndReceiveContext)asyncResult.AsyncState;

            try {
                NetworkStream stream = context.stream;
                stream.EndWrite(asyncResult);
                NonBlockingHandle(context);
            }
            catch (Exception e) {
                context.e = e;
                context.callback(asyncResult);
            }
        }
Exemplo n.º 4
0
        private void WriteFullCallback(IAsyncResult asyncResult)
        {
            SendAndReceiveContext context = (SendAndReceiveContext)asyncResult.AsyncState;

            try {
                NetworkStream stream = context.entry.conn.stream;
                stream.EndWrite(asyncResult);
                context.readCallback = new AsyncCallback(ReadHeadCallback);
                context.buf          = new byte[4];
                context.offset       = 0;
                context.length       = 4;
                stream.BeginRead(context.buf, context.offset, context.length, new AsyncCallback(AsyncReadCallback), context);
            }
            catch (Exception e) {
                context.e = e;
                context.callback(asyncResult);
            }
        }