mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 21:37:13 +02:00
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:
@ -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;
|
||||
|
Reference in New Issue
Block a user