Skip to content

Commit

Permalink
plc: implemented shutdown of the socket correctly (Issue #29).
Browse files Browse the repository at this point in the history
Signed-off-by: Michele Cattafesta <michele.cattafesta@mesta-automation.com>
  • Loading branch information
mesta1 committed Aug 26, 2016
1 parent 83e45e3 commit 78bb5ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion S7.Net.Core/SocketClient.cs
Expand Up @@ -143,11 +143,15 @@ public int Receive(byte[] buffer, int size, SocketFlags socketFlag)
return response;
}

public void Shutdown(SocketShutdown how)
{
_socket.Shutdown(how);
}

public void Close()
{
if (_socket != null)
{
_socket.Shutdown(SocketShutdown.Both);
_socket.Dispose();
_socket = null;
}
Expand Down
2 changes: 2 additions & 0 deletions S7.Net/PLC.cs
Expand Up @@ -242,6 +242,7 @@ public void Close()
{
if (_mSocket != null && _mSocket.Connected)
{
_mSocket.Shutdown(SocketShutdown.Both);
_mSocket.Close();
}
}
Expand Down Expand Up @@ -1096,6 +1097,7 @@ public void Dispose()
if (_mSocket.Connected)
{
//Close() performs a Dispose on the socket.
_mSocket.Shutdown(SocketShutdown.Both);
_mSocket.Close();
}
//((IDisposable)_mSocket).Dispose();
Expand Down

0 comments on commit 78bb5ea

Please sign in to comment.