Update TcpServicesSocket.vb

code style improvements of the serivces handler
This commit is contained in:
xieguigang 2019-08-03 21:27:17 +08:00
parent 3e14b89429
commit 9abe05ab5e
1 changed files with 28 additions and 20 deletions

View File

@ -178,6 +178,33 @@ Namespace Net.Tcp
''' </summary>
''' <remarks></remarks>
Public Function Run(localEndPoint As TcpEndPoint) As Integer Implements IServicesSocket.Run
Dim callback As AsyncCallback
Call startSocket(localEndPoint)
While Not Me.disposedValue
If _threadEndAccept Then
_threadEndAccept = False
callback = New AsyncCallback(AddressOf AcceptCallback)
Try
' Free 之后可能会出现空引用错误则忽略掉这个错误退出线程
Call _servicesSocket.BeginAccept(callback, _servicesSocket)
Catch ex As Exception
Call App.LogException(ex)
End Try
End If
Call Thread.Sleep(1)
End While
_Running = False
Return 0
End Function
Private Sub startSocket(localEndPoint As TcpEndPoint)
_LocalPort = localEndPoint.Port
' Create a TCP/IP socket.
_servicesSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
@ -204,26 +231,7 @@ Namespace Net.Tcp
_threadEndAccept = True
_Running = True
While Not Me.disposedValue
If _threadEndAccept Then
_threadEndAccept = False
Dim callback As New AsyncCallback(AddressOf AcceptCallback)
Try
Call _servicesSocket.BeginAccept(callback, _servicesSocket) ' Free 之后可能会出现空引用错误则忽略掉这个错误退出线程
Catch ex As Exception
Call App.LogException(ex)
End Try
End If
Call Thread.Sleep(1)
End While
_Running = False
Return 0
End Function
End Sub
Public ReadOnly Property Running As Boolean = False Implements IServicesSocket.IsRunning