Commit Graph

958 Commits

Author SHA1 Message Date
drieseng ee9f0f748a SocketExceptions that are thrown during shut down of the socket should not bubble up.
Fixes PR #86.
2016-09-18 19:17:04 +02:00
drieseng f9773a6786 Refactor out use of dynamic types, and reflection for processing received SSH messages. 2016-09-18 19:08:12 +02:00
drieseng 97ed0ddb1c Dereference socket instance field before disposing it. 2016-09-18 11:16:44 +02:00
drieseng 3e0100272c Dereference waithandle instance field before disposing it. 2016-09-18 11:16:10 +02:00
drieseng 9f67d3d7eb Log raised exception. 2016-09-17 09:39:38 +02:00
drieseng 6237dd4982 Move IsSocketConnected to Session.cs.
Move HandleMessageCore to Session.cs, and use FEATURE_DYNAMIC_TYPE conditional compilation symbol to use dynamic code.
2016-09-15 21:23:58 +02:00
drieseng 536f9bd2a4 Use Socket.IsConnected() extension method. 2016-09-15 21:21:56 +02:00
drieseng 9e8ce4a868 Modify ReceiveMessage to return null when connection is closed.
Added TrySocketRead method that returns 0 (zeo) when connection is closed.
Remove SocketRead(int length) overload.

Added IsConnected extension method to Socket.
Modify MessageListener() to use this extension method as condition for the message loop.
Do not bother checking readSockets as the connected check of the socket allows us to combine both the connection closed and socket disposed conditions.
2016-09-13 21:26:49 +02:00
drieseng b3d24ef8bd Harden dispose. 2016-09-13 21:19:23 +02:00
drieseng 7f2edeb55f Fix "randomness". 2016-09-12 21:40:28 +02:00
drieseng 33c834ddec Sync .NET 3.5 test project file with .NET 4.0 test project. 2016-09-12 21:18:52 +02:00
drieseng ad596e83c0 Remove clearing of buffer. 2016-09-11 21:29:30 +02:00
drieseng edde414ef3 Since Dispose now also invokes Disconnect, we no longer need to explicitly invoke Disconnect. 2016-09-11 21:09:50 +02:00
drieseng 3bd1b4eec0 Modify tests to take into account fact that we no longer explicitly disconnect the SftpSession, but instead immediately dispose it. 2016-09-11 20:46:54 +02:00
drieseng 35c9ecfd56 Revert to previous code as its a little more clear. 2016-09-11 20:45:51 +02:00
drieseng 3cf6979943 Avoid NRE when disconnecting or disposing. 2016-09-11 20:21:27 +02:00
drieseng 76fdef9d72 Avoid NRE when disposing. 2016-09-11 20:20:55 +02:00
drieseng b2d95d2b7f Dereference _channel first. 2016-09-11 20:20:20 +02:00
drieseng 800fd3fe99 Use c# type keywords. 2016-09-10 21:15:33 +02:00
drieseng ba59196821 Minor improvements. 2016-09-10 21:11:40 +02:00
drieseng 3808aae801 Avoid extra IsOpen invocation when attempting to open channel session. 2016-09-10 19:40:09 +02:00
drieseng bb968f5550 Minor doc corrections. 2016-09-10 19:38:57 +02:00
drieseng 1d6177fceb Send SSH_MSG_CHANNEL_EOF and SSH_MSG_CHANNEL_CLOSE in synchronized block.
Fixes issue #84.

Eliminate public Close() method and its use within SSH.NET.
Remove wait bool from protected Close(bool) method.
The protected Close() method will now always wait for a  SSH_MSG_CHANNEL_CLOSE if the client initiated closing the channel.
2016-09-10 18:55:03 +02:00
drieseng b413970148 Added more tracing, and break receive loop when we start disconnecting. 2016-09-08 21:45:47 +02:00
drieseng 4632a33e43 Increase timeout waiting for buffered read data. 2016-09-08 21:45:06 +02:00
drieseng 1bab13b78d Add comment. 2016-09-07 21:40:03 +02:00
drieseng e9807ef3f8 Fix doc to correspond with new implementation. 2016-09-07 21:34:36 +02:00
drieseng 77e7bc8c04 Do not catching exceptions while clearing read buffer of socket.
Leave this up to the caller.
2016-09-07 21:34:12 +02:00
drieseng c274f1f9b5 Catch and log SocketException that is thrown while shutting down the socket or clearing its read buffer.
Always log raised exception, even if we're disconnecting.
2016-09-07 21:33:41 +02:00
drieseng 879c39badd Rename SendDisconnect to TrySendDisconnect. 2016-09-07 20:10:45 +02:00
drieseng f2a8d0ff75 Fix test after refactoring. 2016-09-06 19:57:32 +02:00
drieseng 395bbe70d6 Only use Socket.Poll, Socket.Select and read lock when FEATURE_SOCKET_POLL is defined.
Added test for SSH server shutdown while we're reading the packet.
2016-09-05 23:10:34 +02:00
drieseng f9ad89384f Rename Read(int length) to SocketRead(int length)
Introduce dispose lock to resolve race condition in IsConnected/IsSocketConnected.
Rename _socketLock to _socketWriteLock
Eliminate extra allocations in ReceiveMessage, and combine two socket reads.
Use separate lock to eliminate race condition in IsSocketConnected between Poll and checking the Available property.
Modify SocketRead(int length, byte[] buffer) to also take offset.
Modify MessageListener to use Select instead of blocking Receive.

Fixes issue #80.
2016-09-04 21:20:19 +02:00
drieseng 6a1859c500 Added Decrypt overload taking offset and length. 2016-09-04 20:57:15 +02:00
drieseng ad3de364fd Added Pad overloads taking offset and length. 2016-09-04 20:52:23 +02:00
drieseng 344e6e52c0 Use a very short timeout when clearing the read buffer. 2016-09-04 20:04:07 +02:00
drieseng 1e802c795e Update tests as we now load data from an offset as not to include the packet length and/or message type. 2016-09-03 00:02:29 +02:00
drieseng 5529efcab8 Do not send SSH_MSG_DISCONNECT when the server is closing the session by sending a SSH_MSG_DISCONNECT.
Reduces - but does not eliminate - likelyhood of race condition when remote server and client attempt to disconnect at the same time.

Currently this leads to a NRE or ObjectDisposedException in  Session.IsSocketConnected(ref bool isConnected) when one thread is attempting to check whether the socket is still connected, and the other thread is disposing the socket.

This commit just reduces the likelyhood as the message loop thread that handes the SSH_MSG_DISCONNECT sent by the server will no longer attempt to send a SSH_MSG_DISCONNECT to the server, and as such will not check whether the socket is still connected.
2016-09-03 00:01:21 +02:00
drieseng c141c7d4a7 Ignore data of SSH_MSG_IGNORE when its specified length is greater than the actual available bytes.
Fixes issue #41.
2016-09-02 23:50:57 +02:00
drieseng 76a92cfb0a SshData.cs:
- Remove ZeroReaderIndex from SshData; offset should instead be specified when instance is created/loaded.
- LoadBytes is now private, and is always invoked when a message is loaded.
- Eliminate ResetReader().
SshDataStream.cs:
- Added overload taking buffer, offset and count.
KeyExchange*Message.cs:
- Remove ResetReader() calls.
Message.cs:
- Remove ZeroReaderIndex override.
SftpMessage.cs:
- Pass offset and count to Load overload to allow skipping byte representing the message type.
- Remove ZeroReaderIndex override.
SftpSession.cs:
- Avoid buffering when packet contains full SFTP response message.
Session.cs:
- Pass offset and count to Load overload to allow skipping offset bytes.
General:
- Temporarily add (too) verbose tracing.
2016-09-01 21:54:57 +02:00
drieseng bd2fa5d16f Use the managed thread id as identifier in our trace messages. 2016-08-23 18:26:43 +02:00
drieseng 31b2019fe4 Temporarily introduce extra verbose tracing. 2016-08-23 18:25:52 +02:00
drieseng 5260f1b73d Number of bytes in read buffer can never be negative. 2016-08-21 18:46:31 +02:00
drieseng ad56cc9bdf Take into account the offset in SftpFileStream.Write(byte[] buffer, int offset, int count) when not writing to the buffer. Fixes issue #70. 2016-08-21 18:14:03 +02:00
drieseng fb9fe50bc0 Fixed some tests after recent GlobalRequestMessage changes. 2016-08-15 21:36:37 +02:00
drieseng 546caedc94 Include session id in (some) trace messages. 2016-08-15 21:36:13 +02:00
drieseng 4442b88419 Removed unused import. 2016-08-15 12:56:50 +02:00
drieseng 5deccd0c0e Use ASCIIEncoding GetString overload that is supported on all target frameworks. 2016-08-15 12:55:23 +02:00
drieseng 820ed146cf Added new classes to all projects used in VS 2015 solution. 2016-08-15 12:54:52 +02:00
drieseng 96160b3c74 Added extra debug/trace output. 2016-08-15 12:49:31 +02:00