Home » U++ Library support » U++ MT-multithreading and servers » SSH package for U++ (A feature-rich ilbssh2 wrapper for Ultimate++)
Re: SSH package for U++ [message #50150 is a reply to message #50149] |
Wed, 08 August 2018 14:16 |
Oblivion
Messages: 1093 Registered: August 2007
|
Senior Contributor |
|
|
Is there any real-world example where you would need this kind of nonblocking behaviour?
All I can came up is some code that communicates with thousands of ssh servers at once. Looks very unlikely to me....
I use it in an app and for a limited number of ssh channels (usually 10-20).
But frankly, that code remains before the the CoWork improvements and the arrival of AsyncWork.
Nowadays in most such cases I use the async methods.
A short technical info:
- Ssh-based classes use a single callable target queue (FIFO), relying on deferred execution.
- Call to the queue elements are protected by a single static mutex (using INTERLOCKED).
- This allows easy maintenance but has a negative impact on the asynchronicity (it is not really possible to achieve %100 asynchronous operations with the design of libssh2 anyway. Yet the performance gains can be up to %30 in MT mode)
- Queue is populated by two interrelated methods: Cmd/ComplexCmd.
Cmd: Adds a single ananymous function to the callable target queue. In blocking mode it executes the function immediately. In non-blocking mode it defers the execution.
ComplexCmd: Firs and foremos,t this method acts as a nest for other Cmds. and other nests. This way it is possible to execute command chains in a consistent way (as if they are a single CMD).
Certainly you are not comfortable with the current implementation. (Besides, I haven't tested it yet bu as far as I can see your Get() implementation in svn won't work in non-blocking mode)
I have a new proposal: What if I get rid of queue mechanism and rewrite the package with only blocking mode and optional async transfer methods(using AsyncWork, and naming them agein SFtp::Asyncxxx)?
It won't take more than a week for me to come up with a working SSH package and the existing public API wont change much (only the NB helpers will be gone).
Besides its SC will be lot cleaner.
In fact, I had a working prototype of this (was using my Job class) I ditched in favour of the existing version.
As to your Get implementation:
int SFtp::Get(SFtpHandle handle, void *ptr_, int size0)
{
int done = 0; // <- Can't be used in non-blocking mode.
char *ptr = (char *)ptr_;
Cmd(SFTP_START, [=, &done]() mutable {
int size = size0;
if(OpCode() == SFTP_START) {
if(FStat(HANDLE(handle), *sftp->finfo, false) <= 0) OpCode() = SFTP_GET; // <- This is for higher-level api. should be removed.
else return false;
}
while(size) {
int rc = libssh2_sftp_read(HANDLE(handle), ptr, min(size, ssh->chunk_size));
if(rc < 0) {
if(!WouldBlock(rc))
SetError(rc);
return false;
}
else {
if(rc == 0)
break;
size -= rc;
done += rc;
if(WhenProgress(done, size0))
SetError(-1, "Read aborted.");
ssh->start_time = msecs();
}
}
LLOG(Format("%d of %d bytes successfully read.", done, size0));
return true;
});
return done;
}
I haven't tested this yet, but it shouldn't work in non-blocking mode. (because the execution will be deferred (Get will immediately return) and there is a local variable ("done") )
Quote:
Are they documented to be the same?
Nope, its my fault.
Best regards,
Oblivion.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 08 August 2018 21:48] Report message to a moderator
|
|
|
|
|
SSH package for U++
By: Oblivion on Tue, 14 November 2017 21:59
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 17 November 2017 22:15
|
|
|
Re: SSH package for U++
By: Oblivion on Sat, 18 November 2017 15:57
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 19 November 2017 18:21
|
|
|
Re: SSH package for U++
By: Oblivion on Tue, 21 November 2017 00:38
|
|
|
Re: SSH package for U++
By: koldo on Thu, 23 November 2017 09:07
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 24 November 2017 21:03
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 26 November 2017 09:59
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 01 December 2017 14:35
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: Oblivion on Sat, 02 December 2017 10:44
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: Oblivion on Mon, 04 December 2017 22:46
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: Oblivion on Tue, 19 December 2017 14:27
|
|
|
Re: SSH package for U++
By: Oblivion on Tue, 19 December 2017 14:44
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 07 January 2018 22:09
|
|
|
Re: SSH package for U++
By: koldo on Mon, 08 January 2018 08:27
|
|
|
Re: SSH package for U++
By: Oblivion on Tue, 09 January 2018 23:15
|
|
|
Re: SSH package for U++
By: koldo on Wed, 10 January 2018 08:53
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 19 January 2018 14:18
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 21 January 2018 12:18
|
|
|
Re: SSH package for U++
By: koldo on Sun, 21 January 2018 16:53
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 28 January 2018 12:13
|
|
|
Re: SSH package for U++
By: Oblivion on Mon, 02 April 2018 23:27
|
|
|
Re: SSH package for U++
By: Oblivion on Sat, 07 April 2018 16:25
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 15 April 2018 00:39
|
|
|
Re: SSH package for U++
By: Oblivion on Sat, 21 April 2018 08:12
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: mirek on Tue, 10 July 2018 14:37
|
|
|
Re: SSH package for U++
By: mirek on Tue, 10 July 2018 15:38
|
|
|
Re: SSH package for U++
By: mirek on Tue, 10 July 2018 15:42
|
|
|
Re: SSH package for U++
|
|
|
Re: SSH package for U++
By: mirek on Tue, 31 July 2018 11:07
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 03 August 2018 17:34
|
|
|
Re: SSH package for U++
By: mirek on Fri, 03 August 2018 18:03
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 03 August 2018 18:44
|
|
|
Re: SSH package for U++
By: Oblivion on Tue, 07 August 2018 23:32
|
|
|
Re: SSH package for U++
By: mirek on Wed, 08 August 2018 10:56
|
|
|
Re: SSH package for U++
By: Oblivion on Wed, 08 August 2018 11:22
|
|
|
Re: SSH package for U++
By: mirek on Wed, 08 August 2018 13:28
|
|
|
Re: SSH package for U++
By: Oblivion on Wed, 08 August 2018 14:16
|
|
|
Re: SSH package for U++
By: mirek on Thu, 09 August 2018 11:54
|
|
|
Re: SSH package for U++
By: mirek on Thu, 09 August 2018 12:00
|
|
|
Re: SSH package for U++
By: Oblivion on Thu, 09 August 2018 16:24
|
|
|
Re: SSH package for U++
By: mirek on Thu, 09 August 2018 16:49
|
|
|
Re: SSH package for U++
By: Oblivion on Thu, 09 August 2018 17:03
|
|
|
Re: SSH package for U++
By: Oblivion on Thu, 09 August 2018 17:59
|
|
|
Re: SSH package for U++
By: mirek on Thu, 09 August 2018 18:35
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 12 August 2018 12:51
|
|
|
Re: SSH package for U++
By: Oblivion on Thu, 30 August 2018 07:27
|
|
|
Re: SSH package for U++
By: mirek on Thu, 30 August 2018 09:04
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 31 August 2018 00:12
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 02 September 2018 21:59
|
|
|
Re: SSH package for U++
By: Oblivion on Wed, 31 October 2018 11:00
|
|
|
Re: SSH package for U++
By: Oblivion on Sun, 04 November 2018 19:55
|
|
|
Re: SSH package for U++
By: Oblivion on Fri, 22 March 2019 17:39
|
Goto Forum:
Current Time: Sat May 04 06:34:46 CEST 2024
Total time taken to generate the page: 0.01784 seconds
|