On Thu, Oct 23, 2008 at 11:05 PM, Viet Le <viet.aikidorb@gmail.com> wrote:

To be honest, this is the first time I learn and do work with multi-threading. I've appended fully working source code. Please kindly advise if you have time. Thank you very much!


Unfortunately I do not have time to study your example. What I can offer is a "quick 'n' dirty" modification of HTTPForm sample ( http://poco.svn.sourceforge.net/viewvc/poco/poco/trunk/Net/samples/HTTPFormServer/src/HTTPFormServer.cpp?view=markup ).

1) Add following class definition before MyPartHandler class definition:

class MySizeCounter : public Runnable
    MySizeCounter(CountingInputStream& istr): _istr(istr), _done(false) { }
    void run() { while (!_done) std::cout << _istr.chars() << "\r"; }
    void done() { _done = true; }
    CountingInputStream& _istr;
    bool _done;

2) Modify MyPartHandler::handlePart ("// added" comments denote added lines):

void handlePart(const MessageHeader& header, std::istream& stream)
    // ... irrelevant code skipped
    CountingInputStream istr(stream);
    MySizeCounter sc(istr); // added
    Thread t; t.start(sc); // added
    NullOutputStream ostr;
    StreamCopier::copyStream(istr, ostr);
    _length = istr.chars();
    sc.done(); t.join(); // added

3) Start file upload from the web page and observe the size being updated on the console.