make string type argument const string& where possible

pull/1/head
Tatsuhiro Tsujikawa 2006-04-19 17:49:03 +00:00
parent 1457d7f660
commit b1d46227d4
41 changed files with 69 additions and 74 deletions

View File

@ -59,7 +59,7 @@ void AbstractDiskWriter::closeFile() {
} }
} }
void AbstractDiskWriter::openExistingFile(string filename) { void AbstractDiskWriter::openExistingFile(const string& filename) {
File f(filename); File f(filename);
if(!f.isFile()) { if(!f.isFile()) {
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), "file not found"); throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), "file not found");
@ -70,7 +70,7 @@ void AbstractDiskWriter::openExistingFile(string filename) {
} }
} }
void AbstractDiskWriter::createFile(string filename, int addFlags) { void AbstractDiskWriter::createFile(const string& filename, int addFlags) {
// TODO proper filename handling needed // TODO proper filename handling needed
assert(filename.size()); assert(filename.size());
// if(filename.empty()) { // if(filename.empty()) {

View File

@ -35,7 +35,7 @@ protected:
MessageDigestContext ctx; MessageDigestContext ctx;
#endif // ENABLE_SHA1DIGEST #endif // ENABLE_SHA1DIGEST
void createFile(string filename, int addFlags = 0); void createFile(const string& filename, int addFlags = 0);
void writeDataInternal(const char* data, int len); void writeDataInternal(const char* data, int len);
int readDataInternal(char* data, int len); int readDataInternal(char* data, int len);
@ -50,7 +50,7 @@ public:
void closeFile(); void closeFile();
void openExistingFile(string filename); void openExistingFile(const string& filename);
string sha1Sum(long long int offset, long long int length); string sha1Sum(long long int offset, long long int length);

View File

@ -60,8 +60,9 @@ string Base64::part_encode(const string& subplain)
return crypted; return crypted;
} }
string Base64::encode(string plain) string Base64::encode(const string& plainSrc)
{ {
string plain = plainSrc;
int remainder = plain.size() % 3; int remainder = plain.size() % 3;
if( remainder ) remainder = 3-remainder; if( remainder ) remainder = 3-remainder;
for(int i = 0; i < remainder; ++i) plain += (char)0; for(int i = 0; i < remainder; ++i) plain += (char)0;
@ -112,7 +113,7 @@ string Base64::part_decode(const string& subCrypted)
return plain; return plain;
} }
string Base64::decode(string crypted) string Base64::decode(const string& crypted)
{ {
string plain; string plain;
int sIndex = 0; int sIndex = 0;

View File

@ -32,8 +32,8 @@ private:
static string part_decode(const string& subCrypted); static string part_decode(const string& subCrypted);
static char getValue(char ch); static char getValue(char ch);
public: public:
static string encode(string plain); static string encode(const string& plain);
static string decode(string crypted); static string decode(const string& crypted);
}; };
#endif // _BASE64_H_ #endif // _BASE64_H_

View File

@ -42,12 +42,7 @@ void ByteArrayDiskWriter::init() {
bufLength = 0; bufLength = 0;
} }
void ByteArrayDiskWriter::reset() { void ByteArrayDiskWriter::initAndOpenFile(const string& filename) {
clear();
init();
}
void ByteArrayDiskWriter::initAndOpenFile(string filename) {
openFile(filename); openFile(filename);
} }
@ -60,7 +55,7 @@ void ByteArrayDiskWriter::closeFile() {
clear(); clear();
} }
void ByteArrayDiskWriter::openExistingFile(string filename) { void ByteArrayDiskWriter::openExistingFile(const string& filename) {
openFile(filename); openFile(filename);
} }

View File

@ -36,13 +36,13 @@ public:
ByteArrayDiskWriter(); ByteArrayDiskWriter();
virtual ~ByteArrayDiskWriter(); virtual ~ByteArrayDiskWriter();
virtual void initAndOpenFile(string filename); virtual void initAndOpenFile(const string& filename);
virtual void openFile(const string& filename); virtual void openFile(const string& filename);
virtual void closeFile(); virtual void closeFile();
virtual void openExistingFile(string filename); virtual void openExistingFile(const string& filename);
// position is ignored // position is ignored
virtual void writeData(const char* data, int len, long long int position = 0); virtual void writeData(const char* data, int len, long long int position = 0);
@ -56,7 +56,6 @@ public:
int getByteArrayLength() const { int getByteArrayLength() const {
return bufLength; return bufLength;
} }
void reset();
}; };
#endif // _D_BYTE_ARRAY_DISK_WRITER_H_ #endif // _D_BYTE_ARRAY_DISK_WRITER_H_

View File

@ -27,7 +27,7 @@
class ConnectionException:public DlAbortEx { class ConnectionException:public DlAbortEx {
public: public:
ConnectionException():DlAbortEx() {} ConnectionException():DlAbortEx() {}
ConnectionException(string msg):DlAbortEx() {} ConnectionException(const string& msg):DlAbortEx() {}
}; };
#endif // _D_CONNECTION_EXCEPTION_H_ #endif // _D_CONNECTION_EXCEPTION_H_

View File

@ -29,7 +29,7 @@ DefaultDiskWriter::DefaultDiskWriter(long long int totalLength):AbstractDiskWrit
DefaultDiskWriter::~DefaultDiskWriter() {} DefaultDiskWriter::~DefaultDiskWriter() {}
void DefaultDiskWriter::initAndOpenFile(string filename) { void DefaultDiskWriter::initAndOpenFile(const string& filename) {
createFile(filename); createFile(filename);
if(totalLength > 0) { if(totalLength > 0) {
ftruncate(fd, totalLength); ftruncate(fd, totalLength);

View File

@ -32,7 +32,7 @@ public:
DefaultDiskWriter(long long int totalLength); DefaultDiskWriter(long long int totalLength);
~DefaultDiskWriter(); ~DefaultDiskWriter();
void initAndOpenFile(string filename); void initAndOpenFile(const string& filename);
}; };
#endif // _D_DEFAULT_DISK_WRITER_H_ #endif // _D_DEFAULT_DISK_WRITER_H_

View File

@ -34,7 +34,7 @@ void Dictionary::clearTable() {
} }
} }
const MetaEntry* Dictionary::get(string name) const { const MetaEntry* Dictionary::get(const string& name) const {
MetaTable::const_iterator itr = table.find(name); MetaTable::const_iterator itr = table.find(name);
if(itr == table.end()) { if(itr == table.end()) {
return NULL; return NULL;
@ -43,7 +43,7 @@ const MetaEntry* Dictionary::get(string name) const {
} }
} }
void Dictionary::put(string name, MetaEntry* entry) { void Dictionary::put(const string& name, MetaEntry* entry) {
table[name] = entry; table[name] = entry;
order.push_back(name); order.push_back(name);
} }

View File

@ -41,8 +41,8 @@ public:
Dictionary(); Dictionary();
~Dictionary(); ~Dictionary();
const MetaEntry* get(string name) const; const MetaEntry* get(const string& name) const;
void put(string name, MetaEntry* entry); void put(const string& name, MetaEntry* entry);
void accept(MetaEntryVisitor* v) const; void accept(MetaEntryVisitor* v) const;
const Order& getOrder() const; const Order& getOrder() const;

View File

@ -26,7 +26,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
Directory::Directory(string name):name(name) {} Directory::Directory(const string& name):name(name) {}
Directory::~Directory() { Directory::~Directory() {
for(Files::iterator itr = files.begin(); itr != files.end(); itr++) { for(Files::iterator itr = files.begin(); itr != files.end(); itr++) {
@ -34,7 +34,7 @@ Directory::~Directory() {
} }
} }
void Directory::createDir(string parentDir, bool recursive) const { void Directory::createDir(const string& parentDir, bool recursive) const {
string path = parentDir+"/"+name; string path = parentDir+"/"+name;
File f(path); File f(path);
if(f.exists()) { if(f.exists()) {

View File

@ -34,10 +34,10 @@ private:
string name; string name;
Files files; Files files;
public: public:
Directory(string name); Directory(const string& name);
~Directory(); ~Directory();
void createDir(string parentDir, bool recursive) const; void createDir(const string& parentDir, bool recursive) const;
void addFile(Directory* directory); void addFile(Directory* directory);
}; };

View File

@ -39,7 +39,7 @@ public:
* If the file exists, then it is truncated to 0 length. * If the file exists, then it is truncated to 0 length.
* @param filename the file name to be opened. * @param filename the file name to be opened.
*/ */
virtual void initAndOpenFile(string filename) = 0; virtual void initAndOpenFile(const string& filename) = 0;
virtual void openFile(const string& filename) = 0; virtual void openFile(const string& filename) = 0;
@ -54,7 +54,7 @@ public:
* *
* @param filename the file name to be opened. * @param filename the file name to be opened.
*/ */
virtual void openExistingFile(string filename) = 0; virtual void openExistingFile(const string& filename) = 0;
/* /*
* Writes len bytes from data to this binary stream at offset position. * Writes len bytes from data to this binary stream at offset position.

View File

@ -42,7 +42,7 @@ public:
DownloadCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s); DownloadCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s);
virtual ~DownloadCommand(); virtual ~DownloadCommand();
virtual TransferEncoding* getTransferEncoding(string transferEncoding) = 0; virtual TransferEncoding* getTransferEncoding(const string& transferEncoding) = 0;
string transferEncoding; string transferEncoding;

View File

@ -33,7 +33,7 @@ class Exception {
private: private:
string msg; string msg;
protected: protected:
void setMsg(string msgsrc, va_list ap) { void setMsg(const string& msgsrc, va_list ap) {
char buf[256]; char buf[256];
vsnprintf(buf, sizeof(buf), msgsrc.c_str(), ap); vsnprintf(buf, sizeof(buf), msgsrc.c_str(), ap);
msg = buf; msg = buf;

View File

@ -24,7 +24,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
File::File(string name):name(name) {} File::File(const string& name):name(name) {}
File::~File() {} File::~File() {}

View File

@ -35,7 +35,7 @@ private:
string name; string name;
int fillStat(struct stat& fstat); int fillStat(struct stat& fstat);
public: public:
File(string name); File(const string& name);
~File(); ~File();
/** /**

View File

@ -31,7 +31,7 @@ public:
long long int offset; long long int offset;
bool extracted; bool extracted;
bool requested; bool requested;
FileEntry(string path, long long int length, long long int offset): FileEntry(const string& path, long long int length, long long int offset):
path(path), length(length), offset(offset), path(path), length(length), offset(offset),
extracted(false), requested(true) {} extracted(false), requested(true) {}
~FileEntry() {} ~FileEntry() {}

View File

@ -33,6 +33,6 @@ FtpDownloadCommand::~FtpDownloadCommand() {
} }
} }
TransferEncoding* FtpDownloadCommand::getTransferEncoding(string name) { TransferEncoding* FtpDownloadCommand::getTransferEncoding(const string& name) {
return NULL; return NULL;
} }

View File

@ -31,7 +31,7 @@ public:
FtpDownloadCommand(int cuid, Request* req, DownloadEngine* e, const Socket* dataSocket, const Socket* ctrlSocket); FtpDownloadCommand(int cuid, Request* req, DownloadEngine* e, const Socket* dataSocket, const Socket* ctrlSocket);
~FtpDownloadCommand(); ~FtpDownloadCommand();
TransferEncoding* getTransferEncoding(string name); TransferEncoding* getTransferEncoding(const string& name);
}; };
#endif // _D_FTP_DOWNLOAD_COMMAND_H_ #endif // _D_FTP_DOWNLOAD_COMMAND_H_

View File

@ -46,6 +46,6 @@ HttpDownloadCommand::~HttpDownloadCommand() {
} }
} }
TransferEncoding* HttpDownloadCommand::getTransferEncoding(string name) { TransferEncoding* HttpDownloadCommand::getTransferEncoding(const string& name) {
return transferEncodings[name]; return transferEncodings[name];
} }

View File

@ -40,7 +40,7 @@ public:
HttpDownloadCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s); HttpDownloadCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s);
~HttpDownloadCommand(); ~HttpDownloadCommand();
TransferEncoding* getTransferEncoding(string transferEncoding); TransferEncoding* getTransferEncoding(const string& transferEncoding);
}; };
#endif // _D_HTTP_DOWNLOAD_COMMAND_H_ #endif // _D_HTTP_DOWNLOAD_COMMAND_H_

View File

@ -84,7 +84,7 @@ void HttpResponseCommand::checkResponse(int status, const Segment& segment) {
} }
} }
bool HttpResponseCommand::handleRedirect(string url, const HttpHeader& headers) { bool HttpResponseCommand::handleRedirect(const string& url, const HttpHeader& headers) {
req->redirectUrl(url); req->redirectUrl(url);
logger->info(MSG_REDIRECT, cuid, url.c_str()); logger->info(MSG_REDIRECT, cuid, url.c_str());
e->noWait = true; e->noWait = true;
@ -126,7 +126,7 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) {
} }
} }
bool HttpResponseCommand::handleOtherEncoding(string transferEncoding, const HttpHeader& headers) { bool HttpResponseCommand::handleOtherEncoding(const string& transferEncoding, const HttpHeader& headers) {
// we ignore content-length when transfer-encoding is set // we ignore content-length when transfer-encoding is set
e->segmentMan->downloadStarted = true; e->segmentMan->downloadStarted = true;
e->segmentMan->isSplittable = false; e->segmentMan->isSplittable = false;
@ -139,7 +139,7 @@ bool HttpResponseCommand::handleOtherEncoding(string transferEncoding, const Htt
return true; return true;
} }
void HttpResponseCommand::createHttpDownloadCommand(string transferEncoding) { void HttpResponseCommand::createHttpDownloadCommand(const string& transferEncoding) {
HttpDownloadCommand* command = new HttpDownloadCommand(cuid, req, e, socket); HttpDownloadCommand* command = new HttpDownloadCommand(cuid, req, e, socket);
TransferEncoding* enc = NULL; TransferEncoding* enc = NULL;

View File

@ -28,10 +28,10 @@
class HttpResponseCommand : public AbstractCommand { class HttpResponseCommand : public AbstractCommand {
private: private:
void checkResponse(int status, const Segment& segment); void checkResponse(int status, const Segment& segment);
bool handleRedirect(string url, const HttpHeader& headers); bool handleRedirect(const string& url, const HttpHeader& headers);
bool handleDefaultEncoding(const HttpHeader& headers); bool handleDefaultEncoding(const HttpHeader& headers);
bool handleOtherEncoding(string transferEncoding, const HttpHeader& headers); bool handleOtherEncoding(const string& transferEncoding, const HttpHeader& headers);
void createHttpDownloadCommand(string transferEncoding = ""); void createHttpDownloadCommand(const string& transferEncoding = "");
void retrieveCookie(const HttpHeader& headers); void retrieveCookie(const HttpHeader& headers);
HttpConnection* http; HttpConnection* http;
protected: protected:

View File

@ -26,7 +26,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
MetaEntry* MetaFileUtil::parseMetaFile(string file) { MetaEntry* MetaFileUtil::parseMetaFile(const string& file) {
File f(file); File f(file);
int len = f.size(); int len = f.size();
char* buf = new char[len]; char* buf = new char[len];

View File

@ -43,7 +43,7 @@ private:
static string decodeWordAsString(const char** pp, const char* end); static string decodeWordAsString(const char** pp, const char* end);
public: public:
static MetaEntry* parseMetaFile(string file); static MetaEntry* parseMetaFile(const string& file);
static MetaEntry* bdecoding(const char* buf, int len); static MetaEntry* bdecoding(const char* buf, int len);
}; };

View File

@ -61,7 +61,7 @@ void MultiDiskWriter::openFile(const string& filename) {
} }
// filename is a directory which is specified by the user in the option. // filename is a directory which is specified by the user in the option.
void MultiDiskWriter::initAndOpenFile(string filename) { void MultiDiskWriter::initAndOpenFile(const string& filename) {
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin(); for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
itr != diskWriterEntries.end(); itr++) { itr != diskWriterEntries.end(); itr++) {
(*itr)->diskWriter->initAndOpenFile(filename+"/"+(*itr)->fileEntry.path); (*itr)->diskWriter->initAndOpenFile(filename+"/"+(*itr)->fileEntry.path);
@ -75,7 +75,7 @@ void MultiDiskWriter::closeFile() {
} }
} }
void MultiDiskWriter::openExistingFile(string filename) { void MultiDiskWriter::openExistingFile(const string& filename) {
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin(); for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
itr != diskWriterEntries.end(); itr++) { itr != diskWriterEntries.end(); itr++) {
(*itr)->diskWriter->openExistingFile(filename+"/"+(*itr)->fileEntry.path); (*itr)->diskWriter->openExistingFile(filename+"/"+(*itr)->fileEntry.path);

View File

@ -60,9 +60,9 @@ public:
void setFileEntries(const FileEntries& fileEntries); void setFileEntries(const FileEntries& fileEntries);
virtual void openFile(const string& filename); virtual void openFile(const string& filename);
virtual void initAndOpenFile(string filename); virtual void initAndOpenFile(const string& filename);
virtual void closeFile(); virtual void closeFile();
virtual void openExistingFile(string filename); virtual void openExistingFile(const string& filename);
virtual void writeData(const char* data, int len, long long int position = 0); virtual void writeData(const char* data, int len, long long int position = 0);
virtual int readData(char* data, int len, long long int position); virtual int readData(char* data, int len, long long int position);
virtual string sha1Sum(long long int offset, long long int length); virtual string sha1Sum(long long int offset, long long int length);

View File

@ -33,7 +33,7 @@ PreAllocationDiskWriter::PreAllocationDiskWriter(long long int totalLength)
PreAllocationDiskWriter::~PreAllocationDiskWriter() {} PreAllocationDiskWriter::~PreAllocationDiskWriter() {}
void PreAllocationDiskWriter::initAndOpenFile(string filename) { void PreAllocationDiskWriter::initAndOpenFile(const string& filename) {
createFile(filename); createFile(filename);
int bufSize = 4096; int bufSize = 4096;
char buf[4096]; char buf[4096];

View File

@ -31,7 +31,7 @@ public:
PreAllocationDiskWriter(long long int totalLength); PreAllocationDiskWriter(long long int totalLength);
~PreAllocationDiskWriter(); ~PreAllocationDiskWriter();
void initAndOpenFile(string filename); void initAndOpenFile(const string& filename);
}; };
#endif // _D_PRE_ALLOCATION_DISK_WRITER_H_ #endif // _D_PRE_ALLOCATION_DISK_WRITER_H_

View File

@ -40,7 +40,7 @@ Request::~Request() {
delete cookieBox; delete cookieBox;
} }
bool Request::setUrl(string url) { bool Request::setUrl(const string& url) {
this->url = url; this->url = url;
return parseUrl(url); return parseUrl(url);
} }
@ -50,12 +50,12 @@ bool Request::resetUrl() {
return setUrl(url); return setUrl(url);
} }
bool Request::redirectUrl(string url) { bool Request::redirectUrl(const string& url) {
previousUrl = currentUrl; previousUrl = currentUrl;
return parseUrl(url); return parseUrl(url);
} }
bool Request::parseUrl(string url) { bool Request::parseUrl(const string& url) {
currentUrl = url; currentUrl = url;
host = ""; host = "";
port = 0; port = 0;

View File

@ -57,7 +57,7 @@ private:
map<string, int> defaultPorts; map<string, int> defaultPorts;
int tryCount; int tryCount;
int trackerEvent; int trackerEvent;
bool parseUrl(string url); bool parseUrl(const string& url);
public: public:
Segment seg; Segment seg;
CookieBox* cookieBox; CookieBox* cookieBox;
@ -68,11 +68,11 @@ public:
// Parses URL and sets url, host, port, dir, file fields. // Parses URL and sets url, host, port, dir, file fields.
// Returns true if parsing goes successful, otherwise returns false. // Returns true if parsing goes successful, otherwise returns false.
bool setUrl(string url); bool setUrl(const string& url);
// Parses URL and sets host, port, dir, file fields. // Parses URL and sets host, port, dir, file fields.
// url field are not altered by this method. // url field are not altered by this method.
// Returns true if parsing goes successful, otherwise returns false. // Returns true if parsing goes successful, otherwise returns false.
bool redirectUrl(string url); bool redirectUrl(const string& url);
bool resetUrl(); bool resetUrl();
void resetTryCount() { tryCount = 0; } void resetTryCount() { tryCount = 0; }
void addTryCount() { tryCount++; } void addTryCount() { tryCount++; }
@ -83,7 +83,7 @@ public:
string getCurrentUrl() const { return currentUrl; } string getCurrentUrl() const { return currentUrl; }
string getPreviousUrl() const { return previousUrl; } string getPreviousUrl() const { return previousUrl; }
string getReferer() const { return referer; } string getReferer() const { return referer; }
void setReferer(string url) { referer = previousUrl = url; } void setReferer(const string& url) { referer = previousUrl = url; }
string getProtocol() const { return protocol; } string getProtocol() const { return protocol; }
string getHost() const { return host; } string getHost() const { return host; }
int getPort() const { return port; } int getPort() const { return port; }

View File

@ -150,7 +150,7 @@ void SegmentMan::save() const {
logger->info(MSG_SAVED_SEGMENT_FILE); logger->info(MSG_SAVED_SEGMENT_FILE);
} }
FILE* SegmentMan::openSegFile(string segFilename, string mode) const { FILE* SegmentMan::openSegFile(const string& segFilename, const string& mode) const {
FILE* segFile = fopen(segFilename.c_str(), mode.c_str()); FILE* segFile = fopen(segFilename.c_str(), mode.c_str());
if(segFile == NULL) { if(segFile == NULL) {
throw new DlAbortEx(strerror(errno)); throw new DlAbortEx(strerror(errno));

View File

@ -41,7 +41,7 @@ private:
const Logger* logger; const Logger* logger;
void read(FILE* file); void read(FILE* file);
FILE* openSegFile(string segFilename, string mode) const; FILE* openSegFile(const string& segFilename, const string& mode) const;
public: public:
/** /**
* The total number of bytes to download. * The total number of bytes to download.

View File

@ -69,7 +69,7 @@ Socket* Socket::acceptConnection() const {
return new Socket(core->acceptConnection()); return new Socket(core->acceptConnection());
} }
void Socket::establishConnection(string host, int port) const { void Socket::establishConnection(const string& host, int port) const {
core->establishConnection(host, port); core->establishConnection(host, port);
} }
@ -93,7 +93,7 @@ void Socket::writeData(const char* data, int len, int timeout) const {
core->writeData(data, len, timeout); core->writeData(data, len, timeout);
} }
void Socket::writeData(string str, int timeout) const { void Socket::writeData(const string& str, int timeout) const {
core->writeData(str.c_str(), str.size(), timeout); core->writeData(str.c_str(), str.size(), timeout);
} }

View File

@ -71,7 +71,7 @@ public:
/** /**
* @see SocketCore::establishConnection() * @see SocketCore::establishConnection()
*/ */
void establishConnection(string host, int port) const; void establishConnection(const string& host, int port) const;
/** /**
* @see SocketCore::setBlockingMode() * @see SocketCore::setBlockingMode()
@ -101,7 +101,7 @@ public:
* A covenient function that can take string class parameter and * A covenient function that can take string class parameter and
* internally calls SocketCore::writeData(). * internally calls SocketCore::writeData().
*/ */
void writeData(string str, int timeout = 5) const; void writeData(const string& str, int timeout = 5) const;
/** /**
* @see SocketCore::readData() * @see SocketCore::readData()

View File

@ -130,7 +130,7 @@ void SocketCore::getPeerInfo(pair<string, int>& peerinfo) const {
peerinfo.second = ntohs(peerin.sin_port); peerinfo.second = ntohs(peerin.sin_port);
} }
void SocketCore::establishConnection(string host, int port) { void SocketCore::establishConnection(const string& host, int port) {
closeConnection(); closeConnection();
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == -1) { if(sockfd == -1) {

View File

@ -102,7 +102,7 @@ public:
* @param host hostname or ip address to connect to * @param host hostname or ip address to connect to
* @param port service port number to connect to * @param port service port number to connect to
*/ */
void establishConnection(string host, int port); void establishConnection(const string& host, int port);
/** /**
* Makes this socket blocking mode. * Makes this socket blocking mode.

View File

@ -350,7 +350,7 @@ void TorrentMan::readFileEntry(FileEntries& fileEntries, Directory** pTopDir, co
} }
} }
void TorrentMan::setup(string metaInfoFile, const Strings& targetFilePaths) { void TorrentMan::setup(const string& metaInfoFile, const Strings& targetFilePaths) {
peerId = "-A2****-"; peerId = "-A2****-";
for(int i = 0; i < 12; i++) { for(int i = 0; i < 12; i++) {
peerId += Util::itos((int)(((double)10)*random()/(RAND_MAX+1.0))); peerId += Util::itos((int)(((double)10)*random()/(RAND_MAX+1.0)));
@ -466,7 +466,7 @@ bool TorrentMan::segmentFileExists() const {
} }
} }
FILE* TorrentMan::openSegFile(string segFilename, string mode) const { FILE* TorrentMan::openSegFile(const string& segFilename, const string& mode) const {
FILE* segFile = fopen(segFilename.c_str(), mode.c_str()); FILE* segFile = fopen(segFilename.c_str(), mode.c_str());
if(segFile == NULL) { if(segFile == NULL) {
throw new DlAbortEx(strerror(errno)); throw new DlAbortEx(strerror(errno));

View File

@ -76,7 +76,7 @@ private:
bool setupComplete; bool setupComplete;
const Logger* logger; const Logger* logger;
FILE* openSegFile(string segFilename, string mode) const; FILE* openSegFile(const string& segFilename, const string& mode) const;
void read(FILE* file); void read(FILE* file);
Piece findUsedPiece(int index) const; Piece findUsedPiece(int index) const;
@ -141,7 +141,7 @@ public:
return infoHash; return infoHash;
} }
void setup(string metaInfoFile, const Strings& targetFilePaths); void setup(const string& metaInfoFile, const Strings& targetFilePaths);
string getPieceHash(int index) const; string getPieceHash(int index) const;
@ -201,7 +201,7 @@ public:
} }
string getStoreDir() const { return storeDir; } string getStoreDir() const { return storeDir; }
void setStoreDir(string dir) { storeDir = dir; } void setStoreDir(const string& dir) { storeDir = dir; }
string getSegmentFilePath() const; string getSegmentFilePath() const;