Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
Oblivion is currently offline  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..

}



[Updated on: Sun, 25 June 2017 22:13]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: THISBACK1 works well, how can i make it with lambda
Next Topic: THISBACK and inheritance
Goto Forum:
  


Current Time: Sat May 04 17:23:28 CEST 2024

Total time taken to generate the page: 0.02410 seconds