private void OnConnect() { mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); mSocket.Connect(mIPAddress, mPort); mSocket.ReceiveTimeout = TimeOut; mSocket.SendTimeout = TimeOut; if (mBaseNetworkStream != null) { mBaseNetworkStream.Dispose(); } if (mSslStream != null) { mSslStream.Dispose(); } mBaseNetworkStream = new Buffers.PipeStream(ClientBufferPool.Pool, this.LittleEndian, this.Encoding); mBaseNetworkStream.Socket = mSocket; mBaseNetworkStream.Encoding = this.Encoding; mBaseNetworkStream.LittleEndian = this.LittleEndian; mBaseNetworkStream.FlashCompleted = OnWriterFlash; if (this.Packet != null) { this.Packet = this.Packet.Clone(); this.Packet.Completed = this.OnPacketCompleted; } if (SSL) { mSslStream = new SslStreamX(ClientBufferPool.Pool, this.Encoding, this.LittleEndian, mBaseNetworkStream, new RemoteCertificateValidationCallback(ValidateServerCertificate)); var task = mSslStream.AuthenticateAsClientAsync(SslServiceName); task.Wait(); } mConnected = true; }
public void DisConnect() { lock (this) { mConnected = false; try { OnDisconnected(); Token = null; if (mSocket != null) { TcpClient.CloseSocket(mSocket); mSocket = null; } mReceiveEventArgs.Dispose(); mReceiveEventArgs = null; mSendEventArgs.Dispose(); mSendEventArgs = null; mProperties.Clear(); if (mBaseNetworkStream != null) { mBaseNetworkStream.Dispose(); mBaseNetworkStream = null; } if (mSslStream != null) { mSslStream.Dispose(); mSslStream = null; } object item = DequeueSendMessage(); while (item != null) { if (item is IBuffer) { Buffers.Buffer.Free(((IBuffer)item)); } else if (item is IBuffer[]) { foreach (IBuffer b in (IBuffer[])item) { Buffers.Buffer.Free(b); } } item = DequeueSendMessage(); } } catch { } } if (awaitPipeStream.Pending) { awaitPipeStream.Error(new SocketException((int)SocketError.ConnectionAborted)); } if (mReadMessageAwait.Pending) { mReadMessageAwait.Error(new SocketException((int)SocketError.ConnectionAborted)); } }
internal virtual Task Disconnect() { lock (_lock) { try { _pipe?.WaitForPipeDrain(); } catch (Exception) { } try { _pipe?.Dispose(); } catch (Exception) { } _pipe = null; } return(Task.CompletedTask); }
private void OnConnect() { mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); if (LocalEndPoint != null) { mSocket.Bind(LocalEndPoint); } mSocket.Connect(mIPAddress, mPort); if (LocalEndPoint == null) { LocalEndPoint = mSocket.LocalEndPoint; } mSocket.ReceiveTimeout = TimeOut; mSocket.SendTimeout = TimeOut; if (mBaseNetworkStream != null) { mBaseNetworkStream.Dispose(); mBaseNetworkStream = null; } if (mSslStream != null) { mSslStream.Dispose(); mSslStream = null; } mBaseNetworkStream = new PipeStream(BufferPool, this.LittleEndian, this.Encoding) { Socket = mSocket, Encoding = this.Encoding, LittleEndian = this.LittleEndian, FlashCompleted = OnWriterFlash }; if (this.Packet != null) { this.Packet = this.Packet.Clone(); this.Packet.Completed = this.OnPacketCompleted; } if (SSL) { mBaseNetworkStream.SSL = true; mSslStream = new SslStreamX(BufferPool, this.Encoding, this.LittleEndian, mBaseNetworkStream, new RemoteCertificateValidationCallback(ValidateServerCertificate)); var task = mSslStream.AuthenticateAsClientAsync(SslServiceName); task.Wait(); mBaseNetworkStream.SSLConfirmed = true; mSslStream.SyncData(); } mConnected = true; if (mConnected) { this.Connected?.Invoke(this); } }
private async Task OnConnect() { var task = Task.Run(() => CreateSocket()); if (!task.Wait(ConnectTimeOut)) { mSocket?.Dispose(); throw new TimeoutException($"connect {mIPAddress}@{mPort} timeout! task status:{task.Status}"); } //if (LocalEndPoint == null) // LocalEndPoint = mSocket.LocalEndPoint; mSocket.ReceiveTimeout = TimeOut; mSocket.SendTimeout = TimeOut; if (mBaseNetworkStream != null) { mBaseNetworkStream.Dispose(); mBaseNetworkStream = null; } if (mSslStream != null) { mSslStream.Dispose(); mSslStream = null; } mBaseNetworkStream = new Buffers.PipeStream(BufferPool, this.LittleEndian, this.Encoding); mBaseNetworkStream.Socket = mSocket; mBaseNetworkStream.Encoding = this.Encoding; mBaseNetworkStream.LittleEndian = this.LittleEndian; mBaseNetworkStream.FlashCompleted = OnWriterFlash; if (this.Packet != null) { this.Packet = this.Packet.Clone(); this.Packet.Completed = this.OnPacketCompleted; } if (SSL) { mBaseNetworkStream.SSL = true; mSslStream = new SslStreamX(BufferPool, this.Encoding, this.LittleEndian, mBaseNetworkStream, new RemoteCertificateValidationCallback(ValidateServerCertificate)); //var task = mSslStream.AuthenticateAsClientAsync(SslServiceName); //task.Wait(); await OnSslAuthenticate(mSslStream); mBaseNetworkStream.SSLConfirmed = true; mSslStream.SyncData(null); } mConnected = true; if (mConnected) { this.Connected?.Invoke(this); } }
protected virtual void CleanUp(bool isDisposing) { if (isDisposing) { PipeStream.Dispose(); } }
public void Close() { pipeStream.WaitForPipeDrain(); pipeStream.Close(); pipeStream.Dispose(); pipeStream = null; }
public void Cleanup() { if (StreamOut != null) { StreamOut.Dispose(); } if (StreamIn != null) { StreamIn.Dispose(); } if (pipeOut != null) { pipeOut.Dispose(); } if (pipeIn != null) { pipeIn.Dispose(); } if (clientProcess != null) { try { clientProcess.Kill(); clientProcess.WaitForExit(); clientProcess.Close(); } catch (Exception) { } } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { ManualResetEvent ds = Interlocked.Exchange(ref _disposeSignal, null); if (ds != null) { ds.Set(); ds.Dispose(); } ManualResetEvent wc = Interlocked.Exchange(ref _writeCompleteSignal, null); if (wc != null) { wc.Set(); wc.Dispose(); } ManualResetEvent wr = Interlocked.Exchange(ref _writeRequiredSignal, null); if (wr != null) { wr.Dispose(); } PipeStream stream = Interlocked.Exchange(ref Stream, null); if (stream == null) { return; } stream.Dispose(); }
protected override void Dispose(bool disposing) { Try.Swallow(() => { pipe?.WaitForPipeDrain(); }); Try.Catch(() => { pipe?.Dispose(); }); Try.Catch(() => { pipeServer?.Dispose(); }); isDisposed = true; }
protected override void Dispose(bool disposing) { if (disposing) { _underlying.Dispose(); } }
private void Shutdown(Exception?shutdownReason) { lock (_shutdownLock) { if (_socketDisposed) { return; } // Make sure to close the connection only after the _aborted flag is set. // Without this, the RequestsCanBeAbortedMidRead test will sometimes fail when // a BadHttpRequestException is thrown instead of a TaskCanceledException. _socketDisposed = true; // shutdownReason should only be null if the output was completed gracefully, so no one should ever // ever observe the nondescript ConnectionAbortedException except for connection middleware attempting // to half close the connection which is currently unsupported. _shutdownReason = shutdownReason ?? new ConnectionAbortedException("The pipe transport's send loop completed gracefully."); _logger.LogInformation("Shutdown connection {0}: {1}", ConnectionId, _shutdownReason.Message); try { _stream.Close(); } catch { // Ignore any errors from _stream.Close() since we're tearing down the connection anyway. } _stream.Dispose(); } }
public void Close() { CloseConnection = true; PipeStream.Close(); PipeStream.Dispose(); }
public static unsafe void WriteUTF(Stream stream, Encoding encoding, string value, bool littleEndian) { PipeStream pipeStream = stream as PipeStream; if (pipeStream != null) { pipeStream.WriteUTF(value); } else { CreateByteCached(); int maxSubLength = mCachedLength / encoding.GetMaxByteCount(1); if (maxSubLength > value.Length) { int count = (int)encoding.GetBytes(value, 0, value.Length, mBytesCached, 0); if (!littleEndian) { count = BitHelper.SwapInt32(count); } byte[] lendata = BitConverter.GetBytes(count); stream.Write(lendata, 0, 4); stream.Write(mBytesCached, 0, count); } else { PipeStream pipetream = new PipeStream(BufferPoolGroup.DefaultGroup.Next(), littleEndian, encoding); pipetream.WriteUTF(value); Copy(pipeStream, stream); pipetream.Dispose(); } } }
public void Dispose() { _ready = false; npine?.Dispose(); _mutexc?.Close(); _mutexs?.Close(); }
private void FlushProxyStream(bool end) { IBuffer buffer = mProxyStream.GetWriteCacheBufers(); if (buffer != null) { if (Request.Session.SSL) { mProxyStream.Import(buffer); var length = (int)mProxyStream.Length; var data = System.Buffers.ArrayPool <byte> .Shared.Rent(length); mProxyStream.Read(data, 0, length); ProxyDataBuffer proxyData = new ProxyDataBuffer(new ArraySegment <byte>(data, 0, length)); Request.Session.Send(proxyData); } else { Request.Session.Send(buffer); } } if (end) { mProxyStream.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { _stream.Dispose(); _event.Dispose(); } }
public void Dispose() { if (readablePipe != null) { readablePipe.Dispose(); } writeablePipe.Dispose(); }
public override void Close() { if (_pipeStream != null) { _pipeStream.Dispose(); _pipeStream = null; RaiseDisconnectedEvent(); } }
/// <summary> /// Closing a stream /// </summary> public void Close() { if (pipeStream.IsConnected) { pipeStream.WaitForPipeDrain(); } pipeStream.Close(); pipeStream.Dispose(); pipeStream = null; }
/// <summary>Close the pipe</summary> public void Close() { if (_pipeStream?.IsConnected ?? false) { _pipeStream?.WaitForPipeDrain(); } _pipeStream?.Close(); _pipeStream?.Dispose(); _pipeStream = null; }
protected virtual void Dispose(bool disposing) { if (disposing) { _stream?.Dispose(); _stream = null; _speechEngine?.Dispose(); _speechEngine = null; } }
public void Stop() { if (_running) { _running = false; _eventAggregator.GetEvent <LogEvent>().Unsubscribe(ProcessLog); _cancellationToken.Cancel(true); _stream.Dispose(); _stream = null; } }
/// <summary> /// Called when a new named pipes client has connected. /// </summary> /// <param name="pipe">The pipe.</param> protected virtual void OnConnectionRequest(PipeStream pipe) { ConnectionRequest?.Invoke(this, new ResonanceListeningServerConnectionRequestEventArgs <NamedPipesAdapter>( () => { return(new NamedPipesAdapter(pipe)); }, () => { pipe.Dispose(); })); }
public void Cleanup() { _sslClient.Dispose(); _sslServer.Dispose(); _clientIPv4.Dispose(); _serverIPv4.Dispose(); _clientIPv6.Dispose(); _serverIPv6.Dispose(); _clientPipe.Dispose(); _serverPipe.Dispose(); }
public void Dispose() { try { readablePipe?.Dispose(); } finally { writeablePipe.Dispose(); } }
public void ReadOnDisposedReadablePipe_Span_Throws_ObjectDisposedException() { using (ServerClientPair pair = CreateServerClientPair()) { PipeStream pipe = pair.readablePipe; pipe.Dispose(); byte[] buffer = new byte[] { 0, 0, 0, 0 }; Assert.Throws <ObjectDisposedException>(() => pipe.Read(new Span <byte>(buffer))); Assert.Throws <ObjectDisposedException>(() => { pipe.ReadAsync(new Memory <byte>(buffer)); }); } }
public void Disconnect() { try { stream.Close(); } finally { stream.Dispose(); } this.Disconnected.RaiseEvent(this); }
/// <inheritdoc/> public void Dispose() { if (!isDisposed) { if (IsConnected) { WriteCommand(AADCommand.Disconnect, false); } stream.Dispose(); isDisposed = true; } }
public void DisConnect() { lock (this) { mConnected = false; try { if (mSocket != null) { TcpClient.CloseSocket(mSocket); mSocket = null; } mProperties.Clear(); if (mBaseNetworkStream != null) { mBaseNetworkStream.Dispose(); } object item = DequeueSendMessage(); while (item != null) { if (item is IBuffer) { Buffers.Buffer.Free(((IBuffer)item)); } else if (item is IBuffer[]) { foreach (IBuffer b in (IBuffer[])item) { Buffers.Buffer.Free(b); } } item = DequeueSendMessage(); } } catch { } } }