From: <arn...@us...> - 2006-10-10 10:16:41
|
Revision: 672 http://svn.sourceforge.net/dcplusplus/?rev=672&view=rev Author: arnetheduck Date: 2006-10-10 03:16:29 -0700 (Tue, 10 Oct 2006) Log Message: ----------- patches Modified Paths: -------------- dcplusplus/trunk/changelog.txt dcplusplus/trunk/client/DownloadManager.cpp dcplusplus/trunk/client/HashManager.cpp dcplusplus/trunk/client/HashManager.h dcplusplus/trunk/windows/HubFrame.cpp Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2006-10-10 08:45:25 UTC (rev 671) +++ dcplusplus/trunk/changelog.txt 2006-10-10 10:16:29 UTC (rev 672) @@ -14,6 +14,7 @@ * Fixed a few random crashes * [ADC] Removed obsolete DSC command * Fixed user list not being updated in some cases +* [bug 1071] Added fasthash for unix (thanks steven sheehy) -- 0.697 2006-09-29 -- * [ADC] Fixed a few protocol issues Modified: dcplusplus/trunk/client/DownloadManager.cpp =================================================================== --- dcplusplus/trunk/client/DownloadManager.cpp 2006-10-10 08:45:25 UTC (rev 671) +++ dcplusplus/trunk/client/DownloadManager.cpp 2006-10-10 10:16:29 UTC (rev 672) @@ -67,11 +67,11 @@ AdcCommand Download::getCommand(bool zlib) { AdcCommand cmd(AdcCommand::CMD_GET); if(isSet(FLAG_TREE_DOWNLOAD)) { - cmd.addParam("tthl"); + cmd.addParam(Transfer::TYPE_TTHL); } else if(isSet(FLAG_PARTIAL_LIST)) { - cmd.addParam("list"); + cmd.addParam(Transfer::TYPE_LIST); } else { - cmd.addParam("file"); + cmd.addParam(Transfer::TYPE_FILE); } if(isSet(FLAG_PARTIAL_LIST) || isSet(FLAG_USER_LIST)) { cmd.addParam(Util::toAdcFile(getSource())); @@ -436,8 +436,8 @@ const string& type = cmd.getParam(0); int64_t bytes = Util::toInt64(cmd.getParam(3)); - if(!(type == "file" || (type == "tthl" && aSource->getDownload()->isSet(Download::FLAG_TREE_DOWNLOAD)) || - (type == "list" && aSource->getDownload()->isSet(Download::FLAG_PARTIAL_LIST))) ) + if(!(type == Transfer::TYPE_FILE || (type == Transfer::TYPE_TTHL && aSource->getDownload()->isSet(Download::FLAG_TREE_DOWNLOAD)) || + (type == Transfer::TYPE_LIST && aSource->getDownload()->isSet(Download::FLAG_PARTIAL_LIST))) ) { // Uhh??? We didn't ask for this? aSource->disconnect(); Modified: dcplusplus/trunk/client/HashManager.cpp =================================================================== --- dcplusplus/trunk/client/HashManager.cpp 2006-10-10 08:45:25 UTC (rev 671) +++ dcplusplus/trunk/client/HashManager.cpp 2006-10-10 10:16:29 UTC (rev 672) @@ -27,6 +27,10 @@ #include "ZUtils.h" #include "SFVReader.h" +#ifndef _WIN32 +#include <sys/mman.h> // mmap, munmap, madvise +#endif + #define HASH_FILE_VERSION_STRING "2" static const uint32_t HASH_FILE_VERSION=2; const int64_t HashManager::MIN_BLOCK_SIZE = 64*1024; @@ -442,8 +446,6 @@ } } -#define BUF_SIZE (256*1024) - void HashManager::Hasher::hashFile(const string& fileName, int64_t size) { Lock l(cs); if(w.insert(make_pair(fileName, size)).second) { @@ -476,6 +478,8 @@ } #ifdef _WIN32 +#define BUF_SIZE (256*1024) + bool HashManager::Hasher::fastHash(const string& fname, uint8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32) { HANDLE h = INVALID_HANDLE_VALUE; DWORD x, y; @@ -580,8 +584,70 @@ ::CloseHandle(h); return ok; } -#endif +#else // !_WIN32 + +static const int64_t BUF_SIZE = 0x1000000 - (0x1000000 % getpagesize()); + +bool HashManager::Hasher::fastHash(const string& filename, u_int8_t* , TigerTree& tth, int64_t size, CRC32Filter* xcrc32) { + int fd = open(filename.c_str(), O_RDONLY); + if(fd == -1) + return false; + + int64_t size_left = size; + int64_t pos = 0; + int64_t size_read = 0; + void *buf = 0; + + u_int32_t lastRead = GET_TICK(); + while(pos <= size) { + if(size_left > 0) { + size_read = std::min(size_left, BUF_SIZE); + buf = mmap(0, size_read, PROT_READ, MAP_SHARED, fd, pos); + if(buf == MAP_FAILED) { + close(fd); + return false; + } + + madvise(buf, size_read, MADV_SEQUENTIAL | MADV_WILLNEED); + + if(SETTING(MAX_HASH_SPEED) > 0) { + u_int32_t now = GET_TICK(); + u_int32_t minTime = size_read * 1000LL / (SETTING(MAX_HASH_SPEED) * 1024LL * 1024LL); + if(lastRead + minTime > now) { + u_int32_t diff = now - lastRead; + Thread::sleep(minTime - diff); + } + lastRead = lastRead + minTime; + } else { + lastRead = GET_TICK(); + } + } else { + size_read = 0; + } + + tth.update(buf, size_read); + if(xcrc32) + (*xcrc32)(buf, size_read); + { + Lock l(cs); + currentSize = max(static_cast<u_int64_t>(currentSize - size_read), static_cast<u_int64_t>(0)); + } + + if(size_left <= 0) { + break; + } + + munmap(buf, size_read); + pos += size_read; + size_left -= size_read; + } + close(fd); + return true; +} + +#endif // !_WIN32 + int HashManager::Hasher::run() { setThreadPriority(Thread::IDLE); @@ -642,13 +708,15 @@ xcrc32 = &crc32; size_t n = 0; -#ifdef _WIN32 TigerTree fastTTH(bs); tth = &fastTTH; +#ifdef _WIN32 if(!virtualBuf || !BOOLSETTING(FAST_HASH) || !fastHash(fname, buf, fastTTH, size, xcrc32)) { +#else + if(!BOOLSETTING(FAST_HASH) || !fastHash(fname, 0, fastTTH, size, xcrc32)) { +#endif tth = &slowTTH; crc32 = CRC32Filter(); -#endif uint32_t lastRead = GET_TICK(); do { @@ -673,11 +741,10 @@ } sizeLeft -= n; } while (n > 0 && !stop); -#ifdef _WIN32 } else { sizeLeft = 0; } -#endif + f.close(); tth->finalize(); uint32_t end = GET_TICK(); @@ -706,7 +773,7 @@ VirtualFree(buf, 0, MEM_RELEASE); #endif } else { - delete buf; + delete [] buf; } buf = NULL; } Modified: dcplusplus/trunk/client/HashManager.h =================================================================== --- dcplusplus/trunk/client/HashManager.h 2006-10-10 08:45:25 UTC (rev 671) +++ dcplusplus/trunk/client/HashManager.h 2006-10-10 10:16:29 UTC (rev 672) @@ -113,9 +113,7 @@ void stopHashing(const string& baseDir); virtual int run(); -#ifdef _WIN32 bool fastHash(const string& fname, uint8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32); -#endif void getStats(string& curFile, int64_t& bytesLeft, size_t& filesLeft); void shutdown() { stop = true; s.signal(); } void scheduleRebuild() { rebuild = true; s.signal(); } Modified: dcplusplus/trunk/windows/HubFrame.cpp =================================================================== --- dcplusplus/trunk/windows/HubFrame.cpp 2006-10-10 08:45:25 UTC (rev 671) +++ dcplusplus/trunk/windows/HubFrame.cpp 2006-10-10 10:16:29 UTC (rev 672) @@ -481,7 +481,9 @@ TaskQueue::List t; tasks.get(t); - ctrlUsers.SetRedraw(FALSE); + if(t.size() > 2) { + ctrlUsers.SetRedraw(FALSE); + } for(TaskQueue::Iter i = t.begin(); i != t.end(); ++i) { if(i->first == UPDATE_USER) { @@ -575,7 +577,9 @@ resort = false; } - ctrlUsers.SetRedraw(TRUE); + if(t.size() > 2) { + ctrlUsers.SetRedraw(TRUE); + } return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |