@@ -34,7 +34,6 @@ internal sealed class GdsConnection
3434
3535 #region Fields
3636
37- private Socket _socket ;
3837 private NetworkStream _networkStream ;
3938 private string _userID ;
4039 private string _password ;
@@ -113,16 +112,15 @@ public void Connect()
113112 IPAddress = GetIPAddress ( _dataSource , AddressFamily . InterNetwork ) ;
114113 var endPoint = new IPEndPoint ( IPAddress , _portNumber ) ;
115114
116- _socket = new Socket ( IPAddress . AddressFamily , SocketType . Stream , ProtocolType . Tcp ) ;
115+ var socket = new Socket ( IPAddress . AddressFamily , SocketType . Stream , ProtocolType . Tcp ) ;
116+ socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . ReceiveBuffer , _packetSize ) ;
117+ socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . SendBuffer , _packetSize ) ;
118+ socket . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . NoDelay , 1 ) ;
119+ socket . TrySetKeepAlive ( KeepAliveTime , KeepAliveInterval ) ;
120+ socket . TryEnableLoopbackFastPath ( ) ;
121+ socket . Connect ( endPoint ) ;
117122
118- _socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . ReceiveBuffer , _packetSize ) ;
119- _socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . SendBuffer , _packetSize ) ;
120- _socket . SetSocketOption ( SocketOptionLevel . Tcp , SocketOptionName . NoDelay , 1 ) ;
121- _socket . TrySetKeepAlive ( KeepAliveTime , KeepAliveInterval ) ;
122- _socket . TryEnableLoopbackFastPath ( ) ;
123-
124- _socket . Connect ( endPoint ) ;
125- _networkStream = new NetworkStream ( _socket , false ) ;
123+ _networkStream = new NetworkStream ( socket , true ) ;
126124 }
127125 catch ( SocketException ex )
128126 {
@@ -242,8 +240,6 @@ public void Disconnect()
242240 {
243241 _networkStream ? . Dispose ( ) ;
244242 _networkStream = null ;
245- _socket ? . Dispose ( ) ;
246- _socket = null ;
247243 }
248244
249245 #endregion
0 commit comments