Commit Graph

311 Commits

Author SHA1 Message Date
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
drieseng 5916656d66 Introduce specialized GlobalRequestMessage classes for tcpip-forward and cancel-tcpip-forward. 2016-08-15 12:48:40 +02:00
drieseng 7fce6e0b03 When receiving SSH_MSG_GLOBAL_REQUEST, only read data that is not message specific. Fixes issue #58. 2016-08-15 12:47:22 +02:00
drieseng 8a97fecddd Improve exception message when attempting to read more bytes than available. 2016-08-15 12:41:04 +02:00
drieseng 13cc56304a Prepare for stable release. 2016-08-01 21:05:02 +02:00
drieseng f4f6708f46 Give in to Resharper's urge to save "migrated" settings. 2016-07-31 11:45:57 +02:00
drieseng c5d51b9d9d Harden against "leaking" message registration.
Fixes issue #55.
2016-07-31 11:45:31 +02:00
drieseng 7e2836a7a7 Modify TryAuthenticate to static. 2016-07-31 11:39:26 +02:00
drieseng 07c2a6001f Code formatting. 2016-07-31 11:38:58 +02:00
drieseng 75d982bb09 Remove references to EncoderFallbackException and DecoderFallbackException. 2016-07-27 14:03:22 +02:00
drieseng f4a634f1d3 Minor (slash)doc improvements. 2016-07-27 13:52:31 +02:00
drieseng 76fdf58581 Improve slashdocs. 2016-07-27 12:52:50 +02:00
drieseng 563349d15a When the port is closing, first shutdown the send part of the socket.
Subsequently close/dispose the socket to ensure the blocking receive is interrupted.
2016-07-26 22:11:23 +02:00
drieseng 1e63a813cc Improved and corrected the slashdocs.
Fixed some typos.
2016-07-26 22:09:50 +02:00