'Why I need times in closing files in flow
I'm new to c++ and I have question.
I have code like:
void FlowState::closeFile() {
if (outfile) {
//from here
struct timeval times[2];
times[0] = myflow.tstart;
times[1] = myflow.tstart;
outfile->flush();
outfile->close();
//to here
}
}
I have question about selected part. Why I need this? How is it working?
This may be helpful:
class FlowState {
public:
string flowid;
class Streamdemux &demux;
Flow myflow;
// ...
FlowState(class Streamdemux &demux_, const Flow &flow_,
u_int32_t isn_, bool tcp);
virtual ~FlowState();
// ...
};
And:
class Flow: public flowAddr {
public:
int32_t vlan;
struct timeval tstart;
struct timeval tlast;
uint64_t packet_count;
uint64_t connection_count;
string fileNameTemplate;
Flow() :
vlan(), tstart(), tlast(), packet_count(), connection_count() {
fileNameTemplate = "%S:%s-%D:%d"; //brakuje ID połączenia
}
Flow(const flowAddr &flowAddr_, uint16_t vlan_,
const struct timeval &t1, const struct timeval &t2,
uint64_t connection_count_) :
flowAddr(flowAddr_), vlan(vlan_), tstart(t1), tlast(t2), packet_count(
0), connection_count(connection_count_) {
fileNameTemplate = "%S:%s-%D:%d";
}
virtual ~Flow() {
}
};
Solution 1:[1]
Think about it like this: You have a program that runs a long time, opening files from time to time. However, file handles, like everything else on a computer, is a limited resource. So if the program doesn't close the files it will sooner or later run out of available file handles.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Some programmer dude |