예제 #1
0
        public void WriteData(byte[] data)
        {
            if (data != null && data.Length > 0)
            {
                //  DateTime d1 = DateTime.Now;
                Int32  len      = data.Length;
                byte[] lenBytes = BitConverter.GetBytes(len);

                byte[] sendBytes = new byte[lenBytes.Length + data.Length];
                Buffer.BlockCopy(lenBytes, 0, sendBytes, 0, lenBytes.Length);
                Buffer.BlockCopy(data, 0, sendBytes, lenBytes.Length, data.Length);
                //  Logger.Trace("耗时1:{0}", (DateTime.Now - d1).TotalMilliseconds);
                //   d1 = DateTime.Now;
                try
                {
                    IAsyncResult r = writeStream.BeginWrite(sendBytes, 0, sendBytes.Length,
                                                            new AsyncCallback((r1) =>
                    {
                        PipeStream ps = r1.AsyncState as PipeStream;
                        try
                        {
                            ps.EndWrite(r1);
                        }
                        catch { }
                    }), writeStream);
                    // Logger.Trace("耗时2:{0}", (DateTime.Now - d1).TotalMilliseconds);
                }
                catch { }
            }
        }
예제 #2
0
 /// <summary>
 /// Async callback for when this client was done sending a message.
 /// </summary>
 /// <param name="result">The result.</param>
 private void EndSendMessage(IAsyncResult result)
 {
     try
     {
         lock (_streamLock)
         {
             _stream.EndWrite(result);
             _stream.Flush();
             bool flushStateFlag = (bool)result.AsyncState;
             if (flushStateFlag)
             {
                 int newValue = Interlocked.Decrement(ref _messagesFlushedCounter);
                 if (newValue <= 0)
                 {
                     // setting the semaphore will make the WaitOne in Flush() continue.
                     _flushSemaphore.Set();
                     _isFlushing = false;
                 }
             }
         }
     }
     catch
     {
         this.Disconnect();
     }
 }
예제 #3
0
 private void EndSendMessage(IAsyncResult result)
 {
     lock (_InstanceLock)
     {
         _Stream.EndWrite(result);
         _Stream.Flush();
     }
 }
예제 #4
0
 private void EndSendMessage(IAsyncResult result)
 {
     lock (mNamedPipeLock)
     {
         mStream.EndWrite(result);
         mStream.Flush();
     }
 }
예제 #5
0
        private void BeginWrite(byte[] data, ManualResetEventSlim manualEvent)
        {
            PipeStream.BeginWrite(data, 0, data.Length, (result) =>
            {
                PipeStream.EndWrite(result);
                PipeStream.Flush();

                manualEvent.Set();
            }, null);
        }
예제 #6
0
        // complete writing response message to Named Pipes client
        private void OnAsyncWriteComplete(IAsyncResult result)
        {
            PipeStream pipe = (PipeStream)result.AsyncState;

            try {
                pipe.EndWrite(result);
            }
            catch
            {
                WriteToLog("Error while sending message, closing connection.");
            }
        }
예제 #7
0
파일: IPCBase.cs 프로젝트: egshels/Sources
 protected virtual void SendCallback(IAsyncResult result)
 {
     try
     {
         if (_pipeStream != null)
         {
             _pipeStream.EndWrite(result);
         }
     }
     catch (IOException ex)
     {
         _pipeBrokenFlag = true;
         WeGameHelper.WriteDebugString("SendCallback Exception, {0}", ex.Message);
     }
 }
예제 #8
0
 public void Write(byte[] buffer, int offset, int length)
 {
     if (!_conn.IsConnected)
     {
         return;
     }
     try
     {
         //doing syncronous writes (to an Asynchronous pipe) seems to be a bad thing
         _conn.BeginWrite(buffer, offset, length, (r) => { _conn.EndWrite(r); }, null);
     }
     catch (IOException)
     {
         Disconnect();
     }
 }
예제 #9
0
    private void OnAsyncWriteComplete(IAsyncResult result)
    {
        PipeStream pipe = (PipeStream)result.AsyncState;

        pipe.EndWrite(result);
    }
예제 #10
0
 public override void EndWrite(IAsyncResult asyncResult) => _underlying.EndWrite(asyncResult);
예제 #11
0
 private void OnWrite(IAsyncResult ar)
 {
     stream.EndWrite(ar);
 }