|
@@ -84,7 +84,7 @@ namespace SMBLibrary.Client
|
|
|
SessionPacket sessionResponsePacket = WaitForSessionResponsePacket();
|
|
|
if (!(sessionResponsePacket is PositiveSessionResponsePacket))
|
|
|
{
|
|
|
- m_clientSocket.Close();
|
|
|
+ m_clientSocket.Disconnect(false);
|
|
|
if (!ConnectSocket(serverAddress, port))
|
|
|
{
|
|
|
return false;
|
|
@@ -134,7 +134,7 @@ namespace SMBLibrary.Client
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- ConnectionState state = new ConnectionState();
|
|
|
+ ConnectionState state = new ConnectionState(m_clientSocket);
|
|
|
NBTConnectionReceiveBuffer buffer = state.ReceiveBuffer;
|
|
|
m_clientSocket.BeginReceive(buffer.Buffer, buffer.WriteOffset, buffer.AvailableLength, SocketFlags.None, new AsyncCallback(OnClientSocketReceive), state);
|
|
|
return true;
|
|
@@ -294,8 +294,9 @@ namespace SMBLibrary.Client
|
|
|
private void OnClientSocketReceive(IAsyncResult ar)
|
|
|
{
|
|
|
ConnectionState state = (ConnectionState)ar.AsyncState;
|
|
|
+ Socket clientSocket = state.ClientSocket;
|
|
|
|
|
|
- if (!m_clientSocket.Connected)
|
|
|
+ if (!clientSocket.Connected)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
@@ -303,7 +304,7 @@ namespace SMBLibrary.Client
|
|
|
int numberOfBytesReceived = 0;
|
|
|
try
|
|
|
{
|
|
|
- numberOfBytesReceived = m_clientSocket.EndReceive(ar);
|
|
|
+ numberOfBytesReceived = clientSocket.EndReceive(ar);
|
|
|
}
|
|
|
catch (ArgumentException) // The IAsyncResult object was not returned from the corresponding synchronous method on this class.
|
|
|
{
|
|
@@ -332,7 +333,7 @@ namespace SMBLibrary.Client
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- m_clientSocket.BeginReceive(buffer.Buffer, buffer.WriteOffset, buffer.AvailableLength, SocketFlags.None, new AsyncCallback(OnClientSocketReceive), state);
|
|
|
+ clientSocket.BeginReceive(buffer.Buffer, buffer.WriteOffset, buffer.AvailableLength, SocketFlags.None, new AsyncCallback(OnClientSocketReceive), state);
|
|
|
}
|
|
|
catch (ObjectDisposedException)
|
|
|
{
|
|
@@ -359,7 +360,7 @@ namespace SMBLibrary.Client
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
- m_clientSocket.Close();
|
|
|
+ state.ClientSocket.Close();
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -391,7 +392,7 @@ namespace SMBLibrary.Client
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Log("Invalid SMB2 response: " + ex.Message);
|
|
|
- m_clientSocket.Close();
|
|
|
+ state.ClientSocket.Close();
|
|
|
m_isConnected = false;
|
|
|
return;
|
|
|
}
|