? build ? linuxdcpp Index: client/HashManager.cpp =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/client/HashManager.cpp,v retrieving revision 1.8 diff -u -r1.8 HashManager.cpp --- client/HashManager.cpp 23 Jun 2006 19:51:48 -0000 1.8 +++ client/HashManager.cpp 9 Sep 2006 22:58:50 -0000 @@ -27,6 +27,10 @@ #include "ZUtils.h" #include "SFVReader.h" +#ifndef _WIN32 +#include // mmap, munmap, madvise +#endif + #define HASH_FILE_VERSION_STRING "2" static const u_int32_t HASH_FILE_VERSION=2; const int64_t HashManager::MIN_BLOCK_SIZE = 64*1024; @@ -438,9 +442,9 @@ } } +#ifdef _WIN32 #define BUF_SIZE (256*1024) -#ifdef _WIN32 bool HashManager::Hasher::fastHash(const string& fname, u_int8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32) { HANDLE h = INVALID_HANDLE_VALUE; DWORD x, y; @@ -545,7 +549,59 @@ ::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 | O_LARGEFILE); + 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) { + 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(); + } + + tth.update(buf, size_read); + if(xcrc32) + (*xcrc32)(buf, size_read); + munmap(buf, size_read); + { + Lock l(cs); + currentSize = max(currentSize - size_read, _LL(0)); + } + pos += size_read; + size_left -= size_read; + } + return true; +} + +#endif // _WIN32 int HashManager::Hasher::run() { setThreadPriority(Thread::IDLE); @@ -607,13 +663,15 @@ xcrc32 = &crc32; size_t n = 0; -#ifdef _WIN32 TigerTree fastTTH(bs); tth = &fastTTH; +#ifdef _WIN32 if(!virtualBuf || !fastHash(fname, buf, fastTTH, size, xcrc32)) { +#else + if(!BOOLSETTING(FAST_HASHING) || !fastHash(fname, 0, fastTTH, size, xcrc32)) { +#endif tth = &slowTTH; crc32 = CRC32Filter(); -#endif u_int32_t lastRead = GET_TICK(); do { @@ -638,11 +696,9 @@ } sizeLeft -= n; } while (n > 0 && !stop); -#ifdef _WIN32 } else { sizeLeft = 0; } -#endif f.close(); tth->finalize(); u_int32_t end = GET_TICK(); Index: client/HashManager.h =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/client/HashManager.h,v retrieving revision 1.5 diff -u -r1.5 HashManager.h --- client/HashManager.h 15 Jun 2006 18:30:50 -0000 1.5 +++ client/HashManager.h 9 Sep 2006 22:58:51 -0000 @@ -139,9 +139,7 @@ } virtual int run(); -#ifdef _WIN32 bool fastHash(const string& fname, u_int8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32); -#endif void getStats(string& curFile, int64_t& bytesLeft, size_t& filesLeft) { Lock l(cs); curFile = currentFile; Index: client/SettingsManager.cpp =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/client/SettingsManager.cpp,v retrieving revision 1.5 diff -u -r1.5 SettingsManager.cpp --- client/SettingsManager.cpp 15 Jun 2006 18:30:50 -0000 1.5 +++ client/SettingsManager.cpp 9 Sep 2006 22:58:51 -0000 @@ -73,7 +73,7 @@ "NoIpOverride", "SearchOnlyFreeSlots", "LastSearchType", "BoldFinishedDownloads", "BoldFinishedUploads", "BoldQueue", "BoldHub", "BoldPm", "BoldSearch", "SocketInBuffer", "SocketOutBuffer", "OnlyDlTthFiles", "OpenWaitingUsers", "BoldWaitingUsers", "OpenSystemLog", "BoldSystemLog", "AutoRefreshTime", - "UseSsl", "AutoSearchLimit", "AltSortOrder", "AutoKickNoFavs", "PromptPassword", + "UseSsl", "AutoSearchLimit", "AltSortOrder", "AutoKickNoFavs", "PromptPassword", "FastHashing", "SENTRY", // Int64 "TotalUpload", "TotalDownload", @@ -257,6 +257,7 @@ setDefault(ALT_SORT_ORDER, false); setDefault(AUTO_KICK_NO_FAVS, false); setDefault(PROMPT_PASSWORD, false); + setDefault(FAST_HASHING, true); #ifdef _WIN32 setDefault(MAIN_WINDOW_STATE, SW_SHOWNORMAL); Index: client/SettingsManager.h =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/client/SettingsManager.h,v retrieving revision 1.5 diff -u -r1.5 SettingsManager.h --- client/SettingsManager.h 15 Jun 2006 18:30:50 -0000 1.5 +++ client/SettingsManager.h 9 Sep 2006 22:58:51 -0000 @@ -89,7 +89,7 @@ NO_IP_OVERRIDE, SEARCH_ONLY_FREE_SLOTS, LAST_SEARCH_TYPE, BOLD_FINISHED_DOWNLOADS, BOLD_FINISHED_UPLOADS, BOLD_QUEUE, BOLD_HUB, BOLD_PM, BOLD_SEARCH, SOCKET_IN_BUFFER, SOCKET_OUT_BUFFER, ONLY_DL_TTH_FILES, OPEN_WAITING_USERS, BOLD_WAITING_USERS, OPEN_SYSTEM_LOG, BOLD_SYSTEM_LOG, AUTO_REFRESH_TIME, - USE_SSL, AUTO_SEARCH_LIMIT, ALT_SORT_ORDER, AUTO_KICK_NO_FAVS, PROMPT_PASSWORD, + USE_SSL, AUTO_SEARCH_LIMIT, ALT_SORT_ORDER, AUTO_KICK_NO_FAVS, PROMPT_PASSWORD, FAST_HASHING, INT_LAST }; enum Int64Setting { INT64_FIRST = INT_LAST + 1, Index: glade/settingsdialog.glade =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/glade/settingsdialog.glade,v retrieving revision 1.17 diff -u -r1.17 settingsdialog.glade --- glade/settingsdialog.glade 1 Sep 2006 15:05:56 -0000 1.17 +++ glade/settingsdialog.glade 9 Sep 2006 22:58:51 -0000 @@ -5052,6 +5052,31 @@ False + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + 0 @@ -5198,6 +5223,25 @@ False + + + + True + True + fast hashing + True + GTK_RELIEF_NORMAL + True + True + False + True + + + 0 + False + False + + 0 @@ -5386,6 +5430,31 @@ False + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + 0 @@ -5574,6 +5643,31 @@ False + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + 0 @@ -5720,6 +5814,31 @@ False + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + 0 @@ -5908,6 +6027,31 @@ False + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + 0 Index: linux/settingsdialog.cc =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/linux/settingsdialog.cc,v retrieving revision 1.33 diff -u -r1.33 settingsdialog.cc --- linux/settingsdialog.cc 1 Sep 2006 15:05:57 -0000 1.33 +++ linux/settingsdialog.cc 9 Sep 2006 22:58:51 -0000 @@ -274,6 +274,7 @@ sm->set(SettingsManager::SOCKET_IN_BUFFER, Util::toString(gtk_spin_button_get_value(GTK_SPIN_BUTTON(getWidget("socketReadSpinButton"))))); sm->set(SettingsManager::SOCKET_OUT_BUFFER, Util::toString(gtk_spin_button_get_value(GTK_SPIN_BUTTON(getWidget("socketWriteSpinButton"))))); WSET("default-charset", Text::acpToUtf8(string(gtk_entry_get_text(GTK_ENTRY(getWidget("encodingEntry")))))); + sm->set(SettingsManager::FAST_HASHING, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(getWidget("fastHashingCheckButton")))); } sm->save(); @@ -746,6 +747,7 @@ gtk_spin_button_set_value(GTK_SPIN_BUTTON(getWidget("socketReadSpinButton")), (double)SETTING(SOCKET_IN_BUFFER)); gtk_spin_button_set_value(GTK_SPIN_BUTTON(getWidget("socketWriteSpinButton")), (double)SETTING(SOCKET_OUT_BUFFER)); gtk_entry_set_text(GTK_ENTRY(getWidget("encodingEntry")), WGETS("default-charset").c_str()); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(getWidget("fastHashingCheckButton")), SETTING(FAST_HASHING)); } }