File tree Expand file tree Collapse file tree
NetSdrClientApp/Networking Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public TcpClientWrapper(string host, int port)
3030 _port = port ;
3131 }
3232
33+ [ ExcludeFromCodeCoverage ]
3334 public void Connect ( )
3435 {
3536 if ( Connected )
@@ -42,7 +43,10 @@ public void Connect()
4243
4344 try
4445 {
46+ // якщо вже існує попередній токен — звільняємо його перед створенням нового
47+ _cts ? . Dispose ( ) ;
4548 _cts = new CancellationTokenSource ( ) ;
49+
4650 _tcpClient . Connect ( _host , _port ) ;
4751 _stream = _tcpClient . GetStream ( ) ;
4852 Console . WriteLine ( $ "Connected to { _host } :{ _port } ") ;
@@ -51,9 +55,11 @@ public void Connect()
5155 catch ( Exception ex )
5256 {
5357 Console . WriteLine ( $ "Failed to connect: { ex . Message } ") ;
58+ _cts ? . Dispose ( ) ; // звільняємо ресурс у випадку помилки
5459 }
5560 }
5661
62+ [ ExcludeFromCodeCoverage ]
5763 public void Disconnect ( )
5864 {
5965 if ( Connected )
@@ -73,7 +79,6 @@ public void Disconnect()
7379 }
7480 }
7581
76- [ ExcludeFromCodeCoverage ]
7782 public async Task SendMessageAsync ( byte [ ] data )
7883 {
7984 await SendDataAsync ( data ) ;
@@ -100,6 +105,7 @@ private async Task SendDataAsync(byte[] data)
100105 }
101106 }
102107
108+ [ ExcludeFromCodeCoverage ]
103109 private async Task StartListeningAsync ( )
104110 {
105111 if ( Connected && _stream != null && _stream . CanRead )
You can’t perform that action at this time.
0 commit comments