Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit 5f53e53

Browse files
committed
Use TcpListener.Stop to stop listening on the server
1 parent d85b6ba commit 5f53e53

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

RCONServerLib/RemoteConServer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,22 @@ public void StopListening()
151151
{
152152
if (!_listener.Server.IsBound)
153153
return;
154-
155-
_listener.Server.Shutdown(SocketShutdown.Both);
156-
_listener.Server.Close(0);
154+
155+
_listener.Stop();
157156
}
158157

159158
private void OnAccept(IAsyncResult result)
160159
{
161-
var tcpClient = _listener.EndAcceptTcpClient(result);
160+
TcpClient tcpClient;
161+
try
162+
{
163+
tcpClient = _listener.EndAcceptTcpClient(result);
164+
}
165+
catch (ObjectDisposedException)
166+
{
167+
LogDebug("Socket was closed");
168+
return;
169+
}
162170

163171
var ip = ((IPEndPoint) tcpClient.Client.RemoteEndPoint).Address;
164172

RCONServerLib/RemoteConTcpClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Net;
55
using System.Net.Sockets;
6+
using System.Threading;
67
using RCONServerLib.Utils;
78

89
namespace RCONServerLib
@@ -183,6 +184,11 @@ private void OnPacket(IAsyncResult result)
183184
_remoteConServer.LogDebug(((IPEndPoint) _tcp.Client.RemoteEndPoint).Address + " lost connection.");
184185
CloseConnection();
185186
}
187+
catch (ThreadAbortException)
188+
{
189+
_remoteConServer.LogDebug(((IPEndPoint) _tcp.Client.RemoteEndPoint).Address + " socket closed.");
190+
CloseConnection();
191+
}
186192
catch (RconServerException)
187193
{
188194
throw;

0 commit comments

Comments
 (0)