Replies: 1 comment
-
This is a sample script one might use with Node.JS... it connects and makes a shell and gets and sends some data to it, tests some failure conditions too. The delayed nature of libssh2 fits into Promises in JS, where there's a resolve and reject (have data, have error) sort of condition. That's where where my callback API went, it's a little superfluous for other C libraries to use I suppose... but this was actually an inbetween ground to some C++ code to interface with V8 Javascript engine with Promises and callbacks... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
recv and send callbacks - interesting. but libssh2 really still wants a socket socket that's given in the handshake, there's no current api to just use libssh2 as a memory pipe that takes data and generates events. There are some callbacks, but additional callbacks should be added; I've mangled my version pretty good it's not currently suitable for any sort of PR.
Channels have events for data, eof, and close. Listeners have a connect, but once connected are basically a channel for remote forwarded TCP connections. I didn't do anything with the client side forwarding... I also have a thin callback layer that tracks the state of what it's currently doing - sort of an async event dispatch instead of blocking calls. they generate callbacks for any call that might otherwise block by the receive callback returning EAGAIN. (DId take a little while to figure out I needed to return -EAGAIN instead of LIBSSH2_WOULD_BLOCK from the receive callback... which again lends merit to 'expects a socket'.
I also needed a way to send data into transport.c. Not that it came from a read, but everything was already in state for what it needed to do with the data, but I had the data to write, since it was already read from the network, instead of coming in on the actual recv path...
SFTP is something I've actually never used, it looks a lot like FTP, but then there's few files programs that would use a library would want to do too - was wondering what sort of thin API that's SFTP-like but not nesssecarily exactly the commands of SFTP might look like to you(or anyone else) is it just a file system abstraction? should I maybe mount it like a file system (what that means to me is probably not what it means to you, https://github.com/d3x0r/SACK/blob/master/include/filesys.h#L107-L139 this sort of file system interface/mount... for virtual file systems - that would actually be a good place to put it)
But that sort of thing is platform specific, and wouldn't help a lot of people, so probably would just stay a module in SACK (My system abstraction component kit that makes every platform the same platform in as direct of a way as I can).
https://github.com/d3x0r/SACK/blob/master/include/sack_ssh.h This is the C Callback API I implemented (up to SFTP, forwarding a remote connection, remote listeners work, and channels basically work with shells etc ) .
Beta Was this translation helpful? Give feedback.
All reactions