summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/TorrentMan.cc6
-rw-r--r--src/TrackerInitCommand.cc3
-rw-r--r--src/TrackerWatcherCommand.cc1
-rw-r--r--src/main.cc40
4 files changed, 28 insertions, 22 deletions
diff --git a/src/TorrentMan.cc b/src/TorrentMan.cc
index f076feb6..9c8f06a0 100644
--- a/src/TorrentMan.cc
+++ b/src/TorrentMan.cc
@@ -427,9 +427,11 @@ FileEntries TorrentMan::readFileEntryFromMetaInfoFile(const string& metaInfoFile
Dictionary* topDic = (Dictionary*)MetaFileUtil::parseMetaFile(metaInfoFile);
const Dictionary* infoDic = (const Dictionary*)topDic->get("info");
FileEntries fileEntries;
- Directory* topDir;
+ Directory* topDir = NULL;
readFileEntry(fileEntries, &topDir, infoDic, metaInfoFile);
- delete topDir;
+ if(topDir != NULL) {
+ delete topDir;
+ }
return fileEntries;
}
diff --git a/src/TrackerInitCommand.cc b/src/TrackerInitCommand.cc
index 4f254c06..565077ce 100644
--- a/src/TrackerInitCommand.cc
+++ b/src/TrackerInitCommand.cc
@@ -61,7 +61,8 @@ bool TrackerInitCommand::execute() {
"downloaded="+Util::llitos(e->torrentMan->getSessionDownloadLength())+"&"+
"left="+(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength() <= 0
? "0" : Util::llitos(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength()))+"&"+
- "compact=1";
+ "compact=1"+"&"+
+ "key="+e->torrentMan->peerId;
if(!event.empty()) {
url += string("&")+"event="+event;
}
diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc
index 41b8b6ef..c14e71ee 100644
--- a/src/TrackerWatcherCommand.cc
+++ b/src/TrackerWatcherCommand.cc
@@ -30,6 +30,7 @@ TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
TrackerWatcherCommand::~TrackerWatcherCommand() {}
bool TrackerWatcherCommand::execute() {
+ req->resetTryCount();
Command* command = new TrackerInitCommand(e->torrentMan->getNewCuid(),
req,
e);
diff --git a/src/main.cc b/src/main.cc
index 03d2e58f..69fab73a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -71,6 +71,14 @@ void printDownloadAbortMessage() {
printf(_("\nThe download was not complete because of errors. Check the log.\n"));
}
+void setSignalHander(int signal, void (*handler)(int)) {
+ struct sigaction sigact;
+ sigact.sa_handler = handler;
+ sigact.sa_flags = 0;
+ sigemptyset(&sigact.sa_mask);
+ sigaction(signal, &sigact, NULL);
+}
+
void clearRequest(Request* req) {
delete(req);
}
@@ -79,16 +87,19 @@ DownloadEngine* e;
TorrentDownloadEngine* te;
void handler(int signal) {
- cout << _("\nSIGINT signal received.") << endl;
+ printf(_("\nstopping application...\n"));
+ fflush(stdout);
e->segmentMan->save();
if(e->diskWriter != NULL) {
e->diskWriter->closeFile();
}
+ printf("done\n");
exit(0);
}
void torrentHandler(int signal) {
- cout << _("\nSIGINT signal received.") << endl;
+ printf(_("\nstopping application...\n"));
+ fflush(stdout);
if(te->torrentMan->diskAdaptor != NULL) {
te->torrentMan->diskAdaptor->closeFile();
}
@@ -99,7 +110,7 @@ void torrentHandler(int signal) {
} else {
te->torrentMan->save();
}
-
+ printf("done\n");
exit(0);
}
@@ -533,21 +544,14 @@ int main(int argc, char* argv[]) {
SegmentSplitter* splitter = new SplitSlowestSegmentSplitter();
splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE));
- struct sigaction sigactIgn;
- sigactIgn.sa_handler = SIG_IGN;
- sigactIgn.sa_flags = 0;
- sigemptyset(&sigactIgn.sa_mask);
- sigaction(SIGPIPE, &sigactIgn, NULL);
+ setSignalHander(SIGPIPE, SIG_IGN);
bool readyToTorrentMode = false;
string downloadedTorrentFile;
if(torrentFile.empty()) {
- struct sigaction sigact;
- sigact.sa_handler = handler;
- sigact.sa_flags = 0;
- sigemptyset(&sigact.sa_mask);
- sigaction(SIGINT, &sigact, NULL);
-
+ setSignalHander(SIGINT, handler);
+ setSignalHander(SIGTERM, handler);
+
splitter->logger = logger;
e = new ConsoleDownloadEngine();
e->logger = logger;
@@ -590,11 +594,9 @@ int main(int argc, char* argv[]) {
if(!torrentFile.empty() || followTorrent && readyToTorrentMode) {
try {
//op->put(PREF_MAX_TRIES, "0");
- struct sigaction sigact;
- sigact.sa_handler = torrentHandler;
- sigact.sa_flags = 0;
- sigemptyset(&sigact.sa_mask);
- sigaction(SIGINT, &sigact, NULL);
+ setSignalHander(SIGINT, torrentHandler);
+ setSignalHander(SIGTERM, torrentHandler);
+
Request* req = new Request();
req->isTorrent = true;
req->setTrackerEvent(Request::STARTED);