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++ MT-multithreading and servers » [SOLVED][FeatureRequests]Use HttpRequest to upload large file
Re: [FeatureRequests]Use HttpRequest to upload large file [message #43381 is a reply to message #43373] Wed, 16 July 2014 07:39 Go to previous messageGo to previous message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
Add some error handling to prevent the program from crashing.

bool HttpRequest::SendingStream() {
	Upp::FileIn in( postdataName );
	in.Seek( postdataPos );

	int readingSize = 0;
	Upp::String dataPadding = data;
	if( dataPadding.GetLength() & 2047 ) {
		int bufferSize = 2048 - (dataPadding.GetLength() & 2047);

		Upp::StringBuffer buffer( bufferSize );
		readingSize = in.Get( buffer, bufferSize );
		dataPadding << Upp::String( ~buffer, readingSize );
	}
	int64 postdataSize = in.GetSize() - postdataPos - readingSize;

	if( count == 0 ) {
		for(;;) {
			int n = min(2048, dataPadding.GetLength() - (int)count);
			n = TcpSocket::Put(~dataPadding + count, n);
			if(n == 0)
				break;
			count += n;
		}

		if( (count == dataPadding.GetLength()) && postdataSize ) {
			Upp::StringBuffer buffer( 2048 );
			for(;;) {
				int n = min((int64)2048, (int64)dataPadding.GetLength() + postdataSize - (int64)count);
				int readingSize = in.Get(buffer, n);
				n = TcpSocket::Put(~buffer, readingSize);
				if(n == 0)
					break;
				count += n;
			}
		}
	}
	else {
		if( count < dataPadding.GetLength() ) {
			for(;;) {
				int n = min(2048, dataPadding.GetLength() - (int)count);
				n = TcpSocket::Put(~dataPadding + count, n);
				if(n == 0)
					break;
				count += n;
			}
		}
		if( (count >= dataPadding.GetLength()) && postdataSize ) {
			Upp::StringBuffer buffer( 2048 );
			in.Seek( postdataPos + readingSize + (count - dataPadding.GetLength()) );
			for(;;) {
				int n = min((int64)2048, (int64)dataPadding.GetLength() + postdataSize - (int64)count);
				int readingSize = in.Get(buffer, n);
				n = TcpSocket::Put(~buffer, readingSize);
				if(n == 0)
					break;
				count += n;
			}
		}
	}
	return count < dataPadding.GetLength() + postdataSize;
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: MT and variables simple question
Next Topic: [SOLVED]Use multiple HttpRequest instance (>32) to upload files will stuck
Goto Forum:
  


Current Time: Thu May 09 16:41:06 CEST 2024

Total time taken to generate the page: 0.02240 seconds