[Qt-interest] QHttp upload won't stream?

Info info at misafe.com
Thu Oct 8 15:31:03 CEST 2009


Thanks for your input on this.

I have something working as expected now, just one final problem  
that's causing issues.

To maintain the progress at the same level as what's been sent on the  
network rather than what's in the buffer, I'm calling  
waitForBytesWritten() in the bytesWritten() slot whenever the  
encryptedBytesToWrite() is above 0, now I understand this is probably  
not a good thing to be doing as it does sometimes completely freeze  
the event loop while waiting on waitForBytesWritten(), so do yo have  
any advise on what I should do to prevent my app from writing data to  
the buffer when there is still data to be sent?

Thanks.




On 7 Oct 2009, at 15:18, Jason H wrote:

> Flush should only be called at the end of the transfer, I don't know  
> the internals of SSL, but I doubt it is written to handle partial  
> blocks mid-stream.
>
> I've numbered your steps below. I don't know why you'd have to  
> construct a second header in 4. (Are you doing MIME?)
> Given a POST is:
> '''
> POST /path/script.cgi HTTP/1.0
> From: frog at jmarshall.com
> User-Agent: HTTPTool/1.0
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 32
>
> home=Cosby&favorite+flavor=flies
> '''
>
> You should send one header in 2.
> then have a loop of
> MySslSocket::write(data)
> while (bytesSent<data.length())
> {
>    thisChunkLength=qMin(data.length()-bytesSent, 4096)
>    sslSocket.write(data.mid(bytesSent, thisChunkLength)
>    bytesSent+=thisChunkLength()
>    emit bytesWritten(bytesSent)
> }
>
> It seems that you'll need to subclass QSslSocket to provide a proper  
> bytesWritten implementation, based  loosely on the code above,  
> maintaining your own count. Sorry for my bad advice before. I looked  
> at my app and it seems I never implemented a progressBar and https  
> at the same time!
>
>
>
> ________________________________
> From: Info <info at misafe.com>
> To: Jason H <scorp1us at yahoo.com>
> Cc: qt-interest at trolltech.com
> Sent: Wed, October 7, 2009 9:54:42 AM
> Subject: Re: [Qt-interest] QHttp upload won't stream?
>
>
> I've taken your advise and started writing a test using QSslSocket  
> and handling it myself. I am running into the same problem though so  
> perhaps I am doing something wrong...
>
> 1 I startup a connection using QSslSocket::connectToHostEncrpyted()
> 2 When the encrypted() signal is fired, I send my HTTP request headers
> 3 I read in the data in the readyRead() slot until I have the header  
> and all following data for the response.
> 4 I then construct a new header to send the POST data to the server  
> and send that.
> 5 When the bytesWritten() signal is fired, I send the next block of  
> data using QSslSocket::write()
>
> The problem I'm having is that I get exactly the same behaviour as  
> before, the data all gets sent immediately (obviously being buffered  
> by QSslSocket) and my progress jumps right to the end as before. Is  
> there something I should be doing differently here?
>
> I have tried adding a flush() after the write() but that stops  
> transmission all together.
>
> Thanks.
>
>
> On 7 Oct 2009, at 00:35, Jason H wrote:
>
> You have to scan for the \r\n\r\n and feed everything up to the  
> first \r\n that to QHttpRequestHeader, then you have to parse the  
> data this means, if you have base64 content encoding or chuncked  
> encoding you have to account for that. Be aware that the layering  
> works out to be that SSL is first (and should be relatively  
> transparent to you, then chunking, then base64, if applied. I used a  
> QIODevice to do the base64 decoding, and manually parsed the content.
>>
>> I was writing a server though.
>>
>>
>>
>>
>>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com




More information about the Qt-interest-old mailing list