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 #48360 is a reply to message #48355] Mon, 26 June 2017 09:26 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
Oblivion wrote on Sun, 25 June 2017 21:43
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..

}



I am confused. What are these 3 FileOut files in the example? What is supposed to go to them? 3 separate files? (but then I would expect some url as partof startget). Or parts of single file? That would be bad...

Other than that, the lowest level you have is "buffer" and "chunk_size". I think that lowest level of sftp should reflect that.

e.g.

void SFtp::StartGet(Event<void *ptr, int size>)
 
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: Sun Jun 08 17:13:39 CEST 2025

Total time taken to generate the page: 0.04377 seconds