Changeset 507

Show
Ignore:
Timestamp:
04/06/07 20:02:45 (17 months ago)
Author:
hyriand
Message:

Auto-retry failed downloads a couple of times.

Location:
museek+/trunk/sources/Museek
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • museek+/trunk/sources/Museek/PeerConnection.cc

    r480 r507  
    345345                PARSE(PUploadFailed); 
    346346                DEBUG("got Upload Failed from %s, %s", mUser.c_str(), s.filename.c_str()); 
     347                Transfer *transfer = mPeer->download(mMuseek->recoder()->decode_user(mUser, s.filename)); 
     348                if(! transfer) { 
     349                        DEBUG("couldn't find transfer %s, %s", mUser.c_str(), s.filename.c_str()); 
     350                        break; 
     351                } if((transfer->state() != TS_Queued) || (! transfer->auto_retry())) 
     352                        transfer->set_error("Upload failed"); 
     353                else 
     354                        DEBUG("Retrying download"); 
    347355                break; 
    348356        } 
  • museek+/trunk/sources/Museek/TransferManager.cc

    r314 r507  
    233233Transfer::Transfer(TransferManager* manager, Direction direction, Peer* peer, const wstring& path, const wstring& local_path, const wstring& temp_path, off_t size) 
    234234         : mManager(manager), mDirection(direction), mTicketValid(false), mPeer(peer), mPath(path), mLocalPath(local_path), mTempPath(temp_path), 
    235            mState((direction == Download) ? TS_Offline : TS_Queued), mSize(size), mPos(0), mRate(0), mPlaceInQueue((uint32)-1), 
     235           mState((direction == Download) ? TS_Offline : TS_Queued), mSize(size), mPos(0), mRate(0), mPlaceInQueue((uint32)-1), mAutoRetries(0), 
    236236           mConnection(0), mFD(-1), mCollected(0) { 
    237237        CT("transfer %s, %s", peer->user().c_str(), path.c_str()); 
     
    278278        mPeer->remove_transfer(this); 
    279279        mPeer->add_transfer(this); 
     280} 
     281 
     282bool Transfer::auto_retry() { 
     283        if(mAutoRetries > 3) 
     284                return false; 
     285        ++mAutoRetries; 
     286        retry(); 
     287        return true; 
    280288} 
    281289 
     
    343351                if(mPeer->uploading() == this) 
    344352                        mPeer->set_uploading(0); 
    345  
     353                 
     354                break; 
     355         
     356        case TS_Transferring: 
     357                mAutoRetries = 0; 
     358                break; 
     359         
    346360        default: ; 
    347361        } 
     
    349363        mState = state; 
    350364        mManager->museek()->cb_transfer_update(this); 
     365 
     366        if(mDirection == Download && mState == TS_ConnectionClosed) 
     367        { 
     368                DEBUG("connection closed by peer, automatically retrying"); 
     369                auto_retry(); 
     370        } 
    351371} 
    352372 
  • museek+/trunk/sources/Museek/TransferManager.hh

    r2 r507  
    4747         
    4848        void retry(); 
     49        bool auto_retry(); 
    4950         
    5051        inline bool ticket_valid() const { return mTicketValid; }; 
     
    115116        uint32 mRate, mPlaceInQueue; 
    116117        std::vector<uint32> mRatePool; 
     118        int mAutoRetries; 
    117119         
    118120        BaseConnection* mConnection;