Skip to content

Commit

Permalink
Close streams properly on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
SuppenGeist committed May 22, 2016
1 parent 1c4d825 commit b68d661
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ak_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,26 @@ void AKLogger::log(String line) {
void AKLogger::shutdown() {
if(!isActive)
return;

isActive = false;

closeAndDeleteOutputStreams();
closeAndDeleteInputStreams();
}

void AKLogger::closeAndDeleteOutputStreams() {
for(SimpleList<OutputStream*>::iterator it = ostreams.begin(); it != ostreams.end(); it++) {
(*it)->flush();
(*it)->close();
delete &(*it);
it = ostreams.erase(it);
}
}

void AKLogger::closeAndDeleteInputStreams() {
for(SimpleList<InputStream*>::iterator it = istreams.begin(); it != istreams.end(); it++) {
(*it)->close();
delete &(*it);
it = istreams.erase(it);
}
}
2 changes: 2 additions & 0 deletions src/ak_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ class AKLogger {

String readInputStreams();
void logLineFormat();
void closeAndDeleteOutputStreams();
void closeAndDeleteInputStreams();
};

0 comments on commit b68d661

Please sign in to comment.