From: <arn...@us...> - 2007-12-15 22:26:25
|
Revision: 945 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=945&view=rev Author: arnetheduck Date: 2007-12-15 14:26:23 -0800 (Sat, 15 Dec 2007) Log Message: ----------- Remove silly sharedfile Modified Paths: -------------- dcplusplus/trunk/dcpp/Download.cpp dcplusplus/trunk/dcpp/Download.h dcplusplus/trunk/dcpp/File.cpp dcplusplus/trunk/dcpp/File.h dcplusplus/trunk/dcpp/QueueManager.cpp dcplusplus/trunk/dcpp/forward.h Removed Paths: ------------- dcplusplus/trunk/dcpp/SharedFile.cpp dcplusplus/trunk/dcpp/SharedFile.h Modified: dcplusplus/trunk/dcpp/Download.cpp =================================================================== --- dcplusplus/trunk/dcpp/Download.cpp 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/Download.cpp 2007-12-15 22:26:23 UTC (rev 945) @@ -23,7 +23,6 @@ #include "UserConnection.h" #include "QueueItem.h" -#include "SharedFile.h" #include "HashManager.h" namespace dcpp { @@ -120,8 +119,4 @@ params["sfv"] = Util::toString(isSet(Download::FLAG_CRC32_OK) ? 1 : 0); } -void Download::setSharedFile(SharedFile* f) { - file = sharedFile = f; -} - } // namespace dcpp Modified: dcplusplus/trunk/dcpp/Download.h =================================================================== --- dcplusplus/trunk/dcpp/Download.h 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/Download.h 2007-12-15 22:26:23 UTC (rev 945) @@ -52,9 +52,6 @@ /** @internal */ AdcCommand getCommand(bool zlib); - const SharedFile* getSharedFile() const{ return sharedFile; } - void setSharedFile(SharedFile* f); - GETSET(string, tempTarget, TempTarget); GETSET(OutputStream*, file, File); GETSET(bool, treeValid, TreeValid); @@ -64,7 +61,6 @@ TigerTree tt; string pfs; - SharedFile* sharedFile; }; } // namespace dcpp Modified: dcplusplus/trunk/dcpp/File.cpp =================================================================== --- dcplusplus/trunk/dcpp/File.cpp 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/File.cpp 2007-12-15 22:26:23 UTC (rev 945) @@ -41,9 +41,10 @@ dcassert(0); } } + DWORD shared = FILE_SHARE_READ | (mode & SHARED ? FILE_SHARE_WRITE : 0); + + h = ::CreateFile(Text::toT(aFileName).c_str(), access, shared, NULL, m, FILE_FLAG_SEQUENTIAL_SCAN, NULL); - h = ::CreateFile(Text::toT(aFileName).c_str(), access, FILE_SHARE_READ, NULL, m, FILE_FLAG_SEQUENTIAL_SCAN, NULL); - if(h == INVALID_HANDLE_VALUE) { throw FileException(Util::translateError(GetLastError())); } Modified: dcplusplus/trunk/dcpp/File.h =================================================================== --- dcplusplus/trunk/dcpp/File.h 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/File.h 2007-12-15 22:26:23 UTC (rev 945) @@ -46,7 +46,8 @@ enum { OPEN = 0x01, CREATE = 0x02, - TRUNCATE = 0x04 + TRUNCATE = 0x04, + SHARED = 0x08 }; #ifdef _WIN32 Modified: dcplusplus/trunk/dcpp/QueueManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/QueueManager.cpp 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/QueueManager.cpp 2007-12-15 22:26:23 UTC (rev 945) @@ -31,7 +31,6 @@ #include "ResourceManager.h" #include "SearchManager.h" #include "ShareManager.h" -#include "SharedFile.h" #include "SimpleXML.h" #include "StringTokenizer.h" #include "Transfer.h" @@ -733,19 +732,11 @@ throw QueueException(STRING(TARGET_REMOVED)); } - for(DownloadList::const_iterator i = qi->getDownloads().begin(); i != qi->getDownloads().end(); ++i) { - const Download* d2 = *i; - if(d2->getFile()) { - // Already downloading, reuse same file - d->setSharedFile(new SharedFile(*d2->getSharedFile(), d->getSegment())); - return; - } - } - string target = d->getDownloadTarget(); File::ensureDirectory(target); - - d->setSharedFile(new SharedFile(target, d->getSegment(), qi->getSize())); + File* f = new File(target, File::WRITE, File::OPEN | File::CREATE | File::SHARED); + f->setPos(d->getSegment().getStart()); + d->setFile(f); } else if(d->getType() == Transfer::TYPE_FULL_LIST) { string target = d->getDownloadTarget(); File::ensureDirectory(target); Deleted: dcplusplus/trunk/dcpp/SharedFile.cpp =================================================================== --- dcplusplus/trunk/dcpp/SharedFile.cpp 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/SharedFile.cpp 2007-12-15 22:26:23 UTC (rev 945) @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2001-2007 Jacek Sieka, arnetheduck on gmail point com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "stdinc.h" -#include "DCPlusPlus.h" - -#include "SharedFile.h" - -namespace dcpp { - -SharedFile::FileData::FileData(const string& filename) : f(filename, File::RW, File::OPEN | File::CREATE) { - -} - -SharedFile::SharedFile(const string& filename, const Segment& segment_, int64_t totalSize) : segment(segment_), pos(0) { - file = FileDataPtr(new FileData(filename)); - if(totalSize != -1) { - file->f.setSize(totalSize); - } -} - -size_t SharedFile::write(const void* buf, size_t len) throw(Exception) { - Lock l(file->cs); - file->f.setPos(segment.getStart() + pos); - size_t n = file->f.write(buf, len); - pos += n; - return n; -} - -size_t SharedFile::read(void* buf, size_t& len) throw(Exception) { - Lock l(file->cs); - file->f.setPos(segment.getStart() + pos); - size_t n = file->f.read(buf, len); - pos += n; - return n; -} - -size_t SharedFile::flush() throw(Exception) { - Lock l(file->cs); - return file->f.flush(); -} - -} Deleted: dcplusplus/trunk/dcpp/SharedFile.h =================================================================== --- dcplusplus/trunk/dcpp/SharedFile.h 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/SharedFile.h 2007-12-15 22:26:23 UTC (rev 945) @@ -1,41 +0,0 @@ -#ifndef DCPLUSPLUS_DCPP_SHAREDFILE_H_ -#define DCPLUSPLUS_DCPP_SHAREDFILE_H_ - -#include "File.h" -#include "CriticalSection.h" -#include "Segment.h" - -namespace dcpp { - -/** A file used by multiple writers */ -class SharedFile : public IOStream { -public: - SharedFile(const string& filename, const Segment& segment, int64_t totalSize); - - SharedFile(const SharedFile& sf, const Segment& segment_) : file(sf.file), segment(segment_), pos(0) { } - - using OutputStream::write; - virtual size_t write(const void* buf, size_t len) throw(Exception); - virtual size_t read(void* buf, size_t& len) throw(Exception); - - virtual size_t flush() throw(Exception); -private: - struct FileData { - FileData(const string& filename); - File f; - CriticalSection cs; - }; - - typedef std::tr1::shared_ptr<FileData> FileDataPtr; - - FileDataPtr file; - - Segment segment; - - /** Bytes written so far */ - size_t pos; - -}; - -} -#endif /*SHAREDFILE_H_*/ Modified: dcplusplus/trunk/dcpp/forward.h =================================================================== --- dcplusplus/trunk/dcpp/forward.h 2007-12-14 19:50:32 UTC (rev 944) +++ dcplusplus/trunk/dcpp/forward.h 2007-12-15 22:26:23 UTC (rev 945) @@ -72,8 +72,6 @@ class ServerSocket; -class SharedFile; - class Socket; class SocketException; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |