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 #50156 is a reply to message #50152] |
Thu, 09 August 2018 16:24 |
Oblivion
Messages: 1094 Registered: August 2007
|
Senior Contributor |
|
|
Hello Mirek,
Quote:
Sure, as I said that was the point where I decided that fully non-blocking mode is "blocking" this kind of interface.
I'm sorry but I really don't understand this one.
Here is the snippet of the working version of the same method (bot in blocking and non-blocking mode) from the now-cancelled-update:
int SFtp::Read(SFtpHandle handle, Event<const void*, int>&& consumer, int size) // Data read engine.
{
int sz = min(size, ssh->chunksize)
Buffer<char> buffer(sz);
int rc = libssh2_sftp_read(HANDLE(handle), buffer, sz);
if(!WouldBlock(rc) && rc < 0)
SetError(rc);
if(rc > 0) {
consumer(buffer, rc);
sftp->done += rc;
if(WhenProgress(sftp->done, size))
SetError(-1, "Read aborted.");
ssh->start_time = msecs();
}
return rc;
}
int SFtp::Get(SFtpHandle* handle, void* buffer, int size)
{
Clear();
Cmd(SFTP_GET, [=]() mutable {
int rc = Read(
handle,
[=](const void* p, int sz)
{
if(!buffer)
SetError(-1, "Invalid pointer to read buffer");
memcpy((char*)(buffer + sftp->done), (char*)p, sz);
},
size
);
if(rc >= 0)
sftp->value = sftp->done;
return rc == 0 || sftp->done == size;
});
return sftp->done;
}
This works as expected. Note that for any kind of get method all you have to do is simply wrap the "engine" to suit your needs.
Quote:
I think there is a race condition here - two threads can obtain this lock simultaneously. Now I am not sure whether is this supposed to be MT safe, but if not, why atomic, right?
Yep. You see, an ssh shell is a complex environment. You cannot initalize multiple shells, and/or exec channels at once (I don't want to go into details here). This is a limitation of the libssh2. Their initialization have to be in some way serialized. These so-called Lock/Unlock methods handle that serialization when multiple shells or execs were started while maintaining a single threaded non-blocking and/or multithreaded asynchronous initalization. This is what makes multiple shells or exec channels at once (and the SshShellGUI example, for that matter) possible. I added the lock for NB and started to convert it into a thread-safe version. But the idea was yet to be finalized. In the end (in the now-cancelled-update) I decided to go with a RWMutex instead.
Quote:
I am also pretty ambivalent about all those static AsyncWork methods. I think these are better left to client code. Especially if we abandon the non-blocking mode.
Ok, this is not something I would object. Once the new SSH package is done I'll write a small complementary package with a handful of MT convenience functions only and maintain it in my git repo.
To sum up:
If you find it reasonable, I'll rewrite the SSH package with only blocking mode in mind (but with neceasary thread safety, and add its components gradually).
But as I already wrote in my previous messages, let us not change the "single session-multiple channels model" and not exclude any components.
When you start working in environments that rely on ssh ecosystem, as I do, you eventually end up working with ssh tunnesl, exec, and shells.
Besides the current shell implementation we have is AFAIK one of its kind. I don't know any other open source shell component that does what Upp::SshShell does.
Hence it has educational and advertorial value. I mean, If you look up on stackoverflow or other relevant sites you'll see that even a barebone practical ssh shell implementation with libssh2, and also libssh is a mystery to people, let alone a shell that can have running multiple instances at the same time and that even works under Windows dumb-console. We can use this to promote U++, by writing a tutorial, demonstrating the shell in, say, codeproject.
Is this OK?
If so, I'll start writing the new code and commit the changed package within next week.
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: Thu, 09 August 2018 17:03] 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: Mon Jun 10 19:43:23 CEST 2024
Total time taken to generate the page: 0.02507 seconds
|