Skip to content

Commit 536f9bd

Browse files
committed
Use Socket.IsConnected() extension method.
1 parent 9e8ce4a commit 536f9bd

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/Renci.SshNet/Channels/ChannelDirectTcpip.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void ShutdownSocket(SocketShutdown how)
129129

130130
lock (_socketLock)
131131
{
132-
if (_socket == null || !_socket.Connected)
132+
if (!_socket.IsConnected())
133133
return;
134134

135135
_socket.Shutdown(how);
@@ -169,11 +169,11 @@ protected override void OnData(byte[] data)
169169
{
170170
base.OnData(data);
171171

172-
if (_socket != null && _socket.Connected)
172+
if (_socket != null)
173173
{
174174
lock (_socketLock)
175175
{
176-
if (_socket != null && _socket.Connected)
176+
if (_socket.IsConnected())
177177
{
178178
SocketAbstraction.Send(_socket, data, 0, data.Length);
179179
}

src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ private void ForwardedPort_Closing(object sender, EventArgs eventArgs)
107107
/// <param name="how">One of the <see cref="SocketShutdown"/> values that specifies the operation that will no longer be allowed.</param>
108108
private void ShutdownSocket(SocketShutdown how)
109109
{
110-
if (_socket == null || !_socket.Connected)
110+
if (_socket == null)
111111
return;
112112

113113
lock (_socketShutdownAndCloseLock)
114114
{
115115
var socket = _socket;
116-
if (socket == null || !socket.Connected)
116+
if (!socket.IsConnected())
117117
return;
118118

119119
socket.Shutdown(how);
@@ -133,10 +133,8 @@ private void CloseSocket()
133133
var socket = _socket;
134134
if (socket != null)
135135
{
136-
// closing a socket actually disposes the socket, so we can safely dereference
137-
// the field to avoid entering the lock again later
138-
socket.Dispose();
139136
_socket = null;
137+
socket.Dispose();
140138
}
141139
}
142140
}
@@ -175,7 +173,7 @@ protected override void OnData(byte[] data)
175173
base.OnData(data);
176174

177175
var socket = _socket;
178-
if (socket != null && socket.Connected)
176+
if (socket.IsConnected())
179177
{
180178
SocketAbstraction.Send(socket, data, 0, data.Length);
181179
}

0 commit comments

Comments
 (0)