Exceptions: zmq socket class descriptors made into its own class for auto destruction upon construction exception, similarly for other try blocks. slsDetector and multislsdetector left to do

This commit is contained in:
2018-08-09 18:12:56 +02:00
parent 1102153d2b
commit a0512a01d5
7 changed files with 140 additions and 138 deletions

View File

@ -50,31 +50,6 @@ using namespace std;
#define DEFAULT_BACKLOG 5
/**
* Class to close socket descriptors automatically
* upon encountering exceptions in the constructor
*/
class mySocketDescriptors {
public:
mySocketDescriptors():fd(-1), newfd(-1){};
~mySocketDescriptors() {
// close TCP server new socket descriptor from accept
if (newfd >= 0) {
close(newfd);
}
// close socket descriptor
if (fd >= 0) {
close(fd);
}
}
/** socket descriptor */
int fd;
/** new socket descriptor in TCP server from accept */
int newfd;
};
class genericSocket{
public:
@ -814,6 +789,33 @@ public:
char thisClientIP[INET_ADDRSTRLEN];
int differentClients;
private:
/**
* Class to close socket descriptors automatically
* upon encountering exceptions in the genericSocket constructor
*/
class mySocketDescriptors {
public:
/** Constructor */
mySocketDescriptors():fd(-1), newfd(-1){};
/** Destructor */
~mySocketDescriptors() {
// close TCP server new socket descriptor from accept
if (newfd >= 0) {
close(newfd);
}
// close socket descriptor
if (fd >= 0) {
close(fd);
}
}
/** socket descriptor */
int fd;
/** new socket descriptor in TCP server from accept */
int newfd;
};
protected:
int portno;
communicationProtocol protocol;