mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
new exceptions
This commit is contained in:
@ -49,6 +49,7 @@ class sockaddr_in;
|
||||
#define SOCKET_BUFFER_SIZE (100*1024*1024) //100 MB
|
||||
#define DEFAULT_BACKLOG 5
|
||||
|
||||
using sls::SocketError;
|
||||
|
||||
class genericSocket{
|
||||
|
||||
@ -90,7 +91,7 @@ public:
|
||||
struct addrinfo *result;
|
||||
if (ConvertHostnameToInternetAddress(host_ip_or_name, &result)) {
|
||||
sockfd.fd = -1;
|
||||
throw SocketException();
|
||||
throw SocketError("Could convert hostname to address");
|
||||
}
|
||||
|
||||
sockfd.fd = 0;
|
||||
@ -134,7 +135,7 @@ public:
|
||||
// same port
|
||||
if(serverAddress.sin_port == htons(port_number)){
|
||||
sockfd.fd = -10;
|
||||
throw SamePortSocketException();
|
||||
throw SocketError("Cannot create socket on same port");
|
||||
}
|
||||
|
||||
char ip[20];
|
||||
@ -152,7 +153,7 @@ public:
|
||||
if (sockfd.fd < 0) {
|
||||
FILE_LOG(logERROR) << "Can not create socket";
|
||||
sockfd.fd =-1;
|
||||
throw SocketException();
|
||||
throw SocketError("Can not create socket");
|
||||
}
|
||||
|
||||
// Set some fields in the serverAddress structure.
|
||||
@ -175,7 +176,7 @@ public:
|
||||
&val,sizeof(int)) == -1) {
|
||||
FILE_LOG(logERROR) << "setsockopt REUSEADDR failed";
|
||||
sockfd.fd =-1;
|
||||
throw SocketException();
|
||||
throw SocketError("setsockopt REUSEADDR failed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +245,7 @@ public:
|
||||
if(bind(sockfd.fd,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||
FILE_LOG(logERROR) << "Can not bind socket";
|
||||
sockfd.fd =-1;
|
||||
throw SocketException();
|
||||
throw SocketError("Can not bind socket");
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,29 +8,31 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
struct SlsDetectorPackageExceptions : public std::exception {
|
||||
namespace sls{
|
||||
|
||||
struct RuntimeError : public std::runtime_error {
|
||||
public:
|
||||
SlsDetectorPackageExceptions() {}
|
||||
std::string GetMessage() const { return "SLS Detector Package Failed";};
|
||||
RuntimeError(): runtime_error("SLS Detector Package Failed") {}
|
||||
RuntimeError(std::string msg): runtime_error(msg) {}
|
||||
};
|
||||
|
||||
struct SharedMemoryException : public SlsDetectorPackageExceptions {
|
||||
struct SharedMemoryError : public RuntimeError {
|
||||
public:
|
||||
SharedMemoryException() {}
|
||||
std::string GetMessage() const { return "Shared Memory Failed";};
|
||||
SharedMemoryError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
};
|
||||
|
||||
struct SocketException : public SlsDetectorPackageExceptions {
|
||||
struct SocketError : public RuntimeError {
|
||||
public:
|
||||
SocketException() {}
|
||||
std::string GetMessage() const { return "Socket Failed";};
|
||||
SocketError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
};
|
||||
|
||||
struct SamePortSocketException : public SocketException {
|
||||
public:
|
||||
SamePortSocketException() {}
|
||||
std::string GetMessage() const { return "Socket Failed";};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user