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 { } } }
/// <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(); } }
private void EndSendMessage(IAsyncResult result) { lock (_InstanceLock) { _Stream.EndWrite(result); _Stream.Flush(); } }
private void EndSendMessage(IAsyncResult result) { lock (mNamedPipeLock) { mStream.EndWrite(result); mStream.Flush(); } }
private void BeginWrite(byte[] data, ManualResetEventSlim manualEvent) { PipeStream.BeginWrite(data, 0, data.Length, (result) => { PipeStream.EndWrite(result); PipeStream.Flush(); manualEvent.Set(); }, null); }
// 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."); } }
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); } }
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(); } }
private void OnAsyncWriteComplete(IAsyncResult result) { PipeStream pipe = (PipeStream)result.AsyncState; pipe.EndWrite(result); }
public override void EndWrite(IAsyncResult asyncResult) => _underlying.EndWrite(asyncResult);
private void OnWrite(IAsyncResult ar) { stream.EndWrite(ar); }