Review Request 122183: [KUnitConversion] Currency: Fetch the currency file properly

Vishesh Handa me at vhanda.in
Thu Jan 22 14:07:13 UTC 2015



> On Jan. 22, 2015, 12:45 p.m., David Faure wrote:
> > src/currency.cpp, line 672
> > <https://git.reviewboard.kde.org/r/122183/diff/1/?file=343932#file343932line672>
> >
> >     Ouch.
> >     
> >     Hello unexpected reentrancy.
> >     
> >     If this code is async, it should provide a Job API instead of masquerading under a sync API with a nasty nested event loop.
> >     
> >     Or is this running in a separate thread?

It isn't running in a separate thread.

Hmm. This is strange. The previous code is as follows -
    QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(URL)));
    QFile cacheFile(m_cache);
    cacheFile.open(QFile::WriteOnly);
    while (!reply->error() && !reply->atEnd()) {
        if (reply->bytesAvailable()>0 || reply->waitForReadyRead(500)) {
            cacheFile.write(reply->readAll());
        }
    }

QNetworkReply::waitForReadyRead is not implemented, so it uses QIODeivce::waitForReadyRead which just returns false. So this code basicallly keeps looping until we get a reply.

Possible ways to fix this -
1. Event Loop but only process some events
2. A loop as before
3. Async code where we fetch the currency rates in the background and for this result we convert it with the previous rates.

I think (3) would be the best option. Opinions?


- Vishesh


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/122183/#review74534
-----------------------------------------------------------


On Jan. 21, 2015, 2:47 p.m., Vishesh Handa wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/122183/
> -----------------------------------------------------------
> 
> (Updated Jan. 21, 2015, 2:47 p.m.)
> 
> 
> Review request for KDE Frameworks.
> 
> 
> Bugs: 340819
>     https://bugs.kde.org/show_bug.cgi?id=340819
> 
> 
> Repository: kunitconversion
> 
> 
> Description
> -------
> 
> Currency: Fetch the currency file properly
> 
> Properly run an event loop and wait for the file to be fetched.
> 
> Also add a test to make sure currency conversion is working.
> 
> This patch also contains -
> * https://git.reviewboard.kde.org/r/122182/
> * https://git.reviewboard.kde.org/r/122181/
> * https://git.reviewboard.kde.org/r/122180/
> 
> This is because reviewboard refuses to upload only a part of the diff. Please only look at currency.cpp w.r.t the EventLoop.
> 
> 
> Diffs
> -----
> 
>   autotests/convertertest.h 8129a48 
>   autotests/convertertest.cpp ae4298e 
>   src/currency.cpp 715233c 
>   src/unit.cpp 013b5d7 
>   src/unitcategory.cpp c34217e 
> 
> Diff: https://git.reviewboard.kde.org/r/122183/diff/
> 
> 
> Testing
> -------
> 
> Test now passes.
> 
> 
> Thanks,
> 
> Vishesh Handa
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20150122/3d946839/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list