Example #1
0
        static int _m_BeginWrite(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.Stream gen_to_be_invoked = (System.IO.Stream)translator.FastGetCSObj(L, 1);



                {
                    byte[] _buffer = LuaAPI.lua_tobytes(L, 2);
                    int    _offset = LuaAPI.xlua_tointeger(L, 3);
                    int    _count  = LuaAPI.xlua_tointeger(L, 4);
                    System.AsyncCallback _callback = translator.GetDelegate <System.AsyncCallback>(L, 5);
                    object _state = translator.GetObject(L, 6, typeof(object));

                    System.IAsyncResult gen_ret = gen_to_be_invoked.BeginWrite(
                        _buffer,
                        _offset,
                        _count,
                        _callback,
                        _state);
                    translator.PushAny(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Example #2
0
        public void Write(byte[] buffer, int offset, int count)
        {
            var async = _stream.BeginWrite(buffer, offset, count, null, null);

            _stream.EndWrite(async);
            async = null;
            //_stream.Write(buffer,offset,count);
        }
        void TransparentStreamWriteRequestMessageReceived(TransparentStreamMessageBase transparentStreamMessageBase)
        {
            TransparentStreamWriteRequestMessage request = (TransparentStreamWriteRequestMessage)transparentStreamMessageBase;
            Exception exception = null;

            try {
                baseStream.BeginWrite(request.Buffer, 0, request.Buffer.Length, (ar) => {
                    try {
                        baseStream.EndWrite(ar);
                    } catch (Exception ex) {
                        objectBusSession.SendMessage(new TransparentStreamWriteResponseMessage(streamID, request.ID, ex));
                    }
                }, request.Buffer);
            } catch (Exception ex) {
                exception = ex;
                objectBusSession.SendMessage(new TransparentStreamWriteResponseMessage(streamID, request.ID, exception));
            }
        }
 public override void write(byte[] buffer, int offset, int size,
                            ResultHandler rh)
 {
     if (mResponse != null)
     {
         throw new Exception("HTTP write");
     }
     if (mStream == null)
     {
         mRequest.BeginGetRequestStream(
             new AsyncCallback(delegate(IAsyncResult ar)
         {
             mStream = mRequest.EndGetRequestStream(ar);
             mStream.BeginWrite(buffer, offset, size,
                                new AsyncCallback(WriteCallback), rh);
         }), rh);
         return;
     }
     mStream.BeginWrite(buffer, offset, size,
                        new AsyncCallback(WriteCallback), rh);
 }
 public override void write(byte[] buffer, int offset, int size,
      ResultHandler rh)
 {
     if (mResponse != null)
         throw new Exception("HTTP write");
     if (mStream == null)
     {
         mRequest.BeginGetRequestStream(
             new AsyncCallback(delegate(IAsyncResult ar)
         {
             mStream = mRequest.EndGetRequestStream(ar);
             mStream.BeginWrite(buffer, offset, size,
                 new AsyncCallback(WriteCallback), rh);
         }), rh);
         return;
     }
     mStream.BeginWrite(buffer, offset, size,
         new AsyncCallback(WriteCallback), rh);
 }
Example #6
0
 public WriteTransaction(System.IO.Stream s, byte[] dest, int off, int len)
     : base(true, new System.AsyncCallback((iar) => s.BeginWrite(dest, off, len, new System.AsyncCallback((ia) => s.EndWrite(ia)), null)), null, null)
 {
 }
Example #7
0
 /// <inheritdoc/>
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     return(_underlyingStream.BeginWrite(buffer, offset, count, callback, state));
 }
Example #8
0
 /// <summary>
 /// Transfers an entire source stream to a target
 /// </summary>
 /// <param name="source">
 /// The stream to read
 /// </param>
 /// <param name="target">
 /// The stream to write
 /// </param>
 /// <returns>
 /// The total number of bytes transferred
 /// </returns>
 public Int32 Copy(Stream source, Stream target)
 {
     var copied = 0;
      var bufferIdx = 0;
      // start an initial dummy write to avoid
      // a null test within the copy loop
      var writer = target.BeginWrite(this.buffers[1], 0, 0, null, null);
      for (; ; )
      {
     // read into the current buffer
     var buffer = this.buffers[bufferIdx];
     var reader = source.BeginRead(buffer, 0, buffer.Length, null, null);
     // complete the previous write and the current read
     target.EndWrite(writer);
     var read = source.EndRead(reader);
     if (read == 0)
        break;
     copied += read;
     // start the next write for the completed read
     writer = target.BeginWrite(buffer, 0, read, null, null);
     // swap the buffer index for the next read
     bufferIdx = (bufferIdx + 1) % 2;
      }
      return copied;
 }