mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-26 02:38:15 +02:00
Client: Improve disconnection detection
This commit is contained in:
parent
3a7e36b6d1
commit
660442e778
4 changed files with 18 additions and 6 deletions
|
@ -688,14 +688,14 @@ namespace SMBLibrary.Client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TrySendMessage(Socket socket, SMB1Message message)
|
private void TrySendMessage(Socket socket, SMB1Message message)
|
||||||
{
|
{
|
||||||
SessionMessagePacket packet = new SessionMessagePacket();
|
SessionMessagePacket packet = new SessionMessagePacket();
|
||||||
packet.Trailer = message.GetBytes();
|
packet.Trailer = message.GetBytes();
|
||||||
TrySendPacket(socket, packet);
|
TrySendPacket(socket, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TrySendPacket(Socket socket, SessionPacket packet)
|
private void TrySendPacket(Socket socket, SessionPacket packet)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -704,9 +704,11 @@ namespace SMBLibrary.Client
|
||||||
}
|
}
|
||||||
catch (SocketException)
|
catch (SocketException)
|
||||||
{
|
{
|
||||||
|
m_isConnected = false;
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException)
|
catch (ObjectDisposedException)
|
||||||
{
|
{
|
||||||
|
m_isConnected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2014-2019 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2014-2023 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
*
|
*
|
||||||
* You can redistribute this program and/or modify it under the terms of
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -560,6 +560,10 @@ namespace SMBLibrary.Client
|
||||||
|
|
||||||
private void TrySendMessage(SMB1Command request)
|
private void TrySendMessage(SMB1Command request)
|
||||||
{
|
{
|
||||||
|
if (!m_client.IsConnected)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("The client is no longer connected");
|
||||||
|
}
|
||||||
m_client.TrySendMessage(request, m_treeID);
|
m_client.TrySendMessage(request, m_treeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -640,7 +640,7 @@ namespace SMBLibrary.Client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TrySendCommand(Socket socket, SMB2Command request, byte[] encryptionKey)
|
private void TrySendCommand(Socket socket, SMB2Command request, byte[] encryptionKey)
|
||||||
{
|
{
|
||||||
SessionMessagePacket packet = new SessionMessagePacket();
|
SessionMessagePacket packet = new SessionMessagePacket();
|
||||||
if (encryptionKey != null)
|
if (encryptionKey != null)
|
||||||
|
@ -655,7 +655,7 @@ namespace SMBLibrary.Client
|
||||||
TrySendPacket(socket, packet);
|
TrySendPacket(socket, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TrySendPacket(Socket socket, SessionPacket packet)
|
private void TrySendPacket(Socket socket, SessionPacket packet)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -664,9 +664,11 @@ namespace SMBLibrary.Client
|
||||||
}
|
}
|
||||||
catch (SocketException)
|
catch (SocketException)
|
||||||
{
|
{
|
||||||
|
m_isConnected = false;
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException)
|
catch (ObjectDisposedException)
|
||||||
{
|
{
|
||||||
|
m_isConnected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2017-2021 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
/* Copyright (C) 2017-2023 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
*
|
*
|
||||||
* You can redistribute this program and/or modify it under the terms of
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
@ -335,6 +335,10 @@ namespace SMBLibrary.Client
|
||||||
private void TrySendCommand(SMB2Command request)
|
private void TrySendCommand(SMB2Command request)
|
||||||
{
|
{
|
||||||
request.Header.TreeID = m_treeID;
|
request.Header.TreeID = m_treeID;
|
||||||
|
if (!m_client.IsConnected)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("The client is no longer connected");
|
||||||
|
}
|
||||||
m_client.TrySendCommand(request, m_encryptShareData);
|
m_client.TrySendCommand(request, m_encryptShareData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue