Home » U++ Library support » U++ Callbacks and Timers » About storing references and pointers to callbacks.
Re: About storing references and pointers to callbacks. [message #48355 is a reply to message #48353] |
Sun, 25 June 2017 21:43 |
Oblivion
Messages: 1093 Registered: August 2007
|
Senior Contributor |
|
|
Thank you for your quick reply!
Here is the actual code:
void SFtp::StartGet(Stream& out)
{
packet_length = 0;
Stream *io_stream = &out;
AddJob() << [=] {
Buffer<char> buffer(chunk_size);
int rc = libssh2_sftp_read(handle, buffer, chunk_size);
if(rc > 0) {
io_stream->Put(buffer, rc);
if(WhenRead(dir_entry.GetSize(), io_stream->GetSize()))
Error(-1, t_("File download aborted."));
return true;
}
else
if(rc == 0) {
LLOG(Format("++ SFTP: %ld of %ld bytes successfully read.", io_stream->GetSize(), dir_entry.GetSize()));
return false;
}
if(!WouldBlock())
Error();
return true;
};
}
This method is called by the user who wants to download a file from the server. It should be called before proceeding of a "job queue" (replicates the HttpRequest class' async interface but with callbacks).
This method stores a pointer to callback which is queued in a Vector<Function<bool(void)>>.
SFtp sftpclient;
FileOut file1, file2, file3;
sftpclient.StartGet(file1);
sftpclient.StartGet(file2);
sftpclient.StartGet(file3);
//...
// Then below,
// Something along these lines:
while(1) {
sftpclient.Do();
if(sftpClient.InProgress())
// do something
else
// do something else..
}
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: Sun, 25 June 2017 22:13] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 04 17:23:28 CEST 2024
Total time taken to generate the page: 0.02410 seconds
|