Skip to content

Commit 4f79a97

Browse files
committed
updated socket listenner loop try and catch block.
1 parent daae796 commit 4f79a97

4 files changed

Lines changed: 35 additions & 35 deletions

File tree

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup Condition="'$(AssemblyName)'=='GodSharp.Socket'">
33
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
4-
<Version>1.0.2-preview4</Version>
4+
<Version>1.0.2-preview5</Version>
55
</PropertyGroup>
66
</Project>

src/GodSharp.Socket/Tcp/Client/SocketClient.Async.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ public partial class SocketClient
77
/// <summary>
88
/// Connects this instance.
99
/// </summary>
10-
public void ConnectAsync(SocketAsyncEventArgs e)
11-
{
12-
if (Connected)
13-
{
14-
return;
15-
}
10+
//public void ConnectAsync(SocketAsyncEventArgs e)
11+
//{
12+
// if (Connected)
13+
// {
14+
// return;
15+
// }
1616

17-
socket.ConnectAsync(e);
17+
// socket.ConnectAsync(e);
1818

19-
SetOnConnectedFun();
20-
}
19+
// SetOnConnectedFun();
20+
//}
2121
}
2222
}

src/GodSharp.Socket/Tcp/Listener/TcpListener.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ private void Loop()
174174
int length;
175175
while (Running && Connected)
176176
{
177-
if (Socket.Poll(-1, SelectMode.SelectRead))
177+
try
178178
{
179-
try
179+
if (Socket.Poll(-1, SelectMode.SelectRead))
180180
{
181-
data = new byte[1024];
181+
data = new byte[Socket.ReceiveBufferSize];
182182
length = -1;
183183
length = Socket.Receive(data);
184184

@@ -192,43 +192,43 @@ private void Loop()
192192

193193
parent.OnData?.Invoke(Sender, tmp);
194194
}
195-
catch (SocketException ex)
196-
{
195+
}
196+
catch (SocketException ex)
197+
{
197198
#if DEBUG
198-
Console.WriteLine(ex.Message);
199+
Console.WriteLine(ex.Message);
199200
#endif
200-
if (ex.SocketErrorCode == SocketError.ConnectionReset || ex.SocketErrorCode == SocketError.ConnectionAborted)
201-
{
201+
if (ex.SocketErrorCode == SocketError.ConnectionReset || ex.SocketErrorCode == SocketError.ConnectionAborted)
202+
{
202203
#if DEBUG
203-
Console.WriteLine($"Server {RemoteEndPoint} offline by {(SocketError)ex.SocketErrorCode}.");
204+
Console.WriteLine($"Server {RemoteEndPoint} offline by {(SocketError)ex.SocketErrorCode}.");
204205
#endif
205-
break;
206-
}
207-
else
208-
{
209-
parent.OnException?.Invoke(Sender, ex);
210-
}
206+
break;
211207
}
212-
catch (Exception ex)
208+
else
213209
{
214-
#if DEBUG
215-
Console.WriteLine(ex.Message);
216-
#endif
217210
parent.OnException?.Invoke(Sender, ex);
218-
continue;
219211
}
220-
221-
Thread.Sleep(10);
222212
}
213+
catch (Exception ex)
214+
{
215+
#if DEBUG
216+
Console.WriteLine(ex.Message);
217+
#endif
218+
parent.OnException?.Invoke(Sender, ex);
219+
continue;
220+
}
221+
222+
Thread.Sleep(10);
223223
}
224224

225225
Running = false;
226226

227-
if (Socket?.Connected==true)
227+
if (Socket?.Connected == true)
228228
{
229229
Socket.Shutdown(SocketShutdown.Both);
230230
Socket.Disconnect(true);
231-
Socket.Close();
231+
Socket.Close();
232232
}
233233

234234
#if DEBUG

src/GodSharp.Socket/Tcp/Server/SocketServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public SocketServer(int port) : this()
9393
}
9494

9595
/// <summary>
96-
/// Initializes a new instance of the <see cref="Client"/> class.
96+
/// Initializes a new instance of the <see cref="SocketServer"/> class.
9797
/// </summary>
9898
/// <param name="host">The host.</param>
9999
/// <param name="port">The port.</param>

0 commit comments

Comments
 (0)