mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-31 01:24:19 +02:00
Windows build fix.
This commit is contained in:
parent
d8edd98e41
commit
412a44e697
@ -45,8 +45,11 @@ Application::Application(const Dictionary::Ptr& serializedUpdate)
|
|||||||
SetErrorMode(SEM_FAILCRITICALERRORS);
|
SetErrorMode(SEM_FAILCRITICALERRORS);
|
||||||
|
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
|
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
|
||||||
BOOST_THROW_EXCEPTION(Win32Exception("WSAStartup failed", WSAGetLastError()));
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< errinfo_api_function("WSAStartup")
|
||||||
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -245,7 +248,9 @@ String Application::GetExePath(const String& argv0)
|
|||||||
char FullExePath[MAXPATHLEN];
|
char FullExePath[MAXPATHLEN];
|
||||||
|
|
||||||
if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath)))
|
if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath)))
|
||||||
BOOST_THROW_EXCEPTION(Win32Exception("GetModuleFileName() failed", GetLastError()));
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< errinfo_api_function("GetModuleFileName")
|
||||||
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
|
||||||
return FullExePath;
|
return FullExePath;
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
@ -43,6 +43,8 @@ typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;
|
|||||||
class I2_BASE_API posix_error : virtual public std::exception, virtual public boost::exception { };
|
class I2_BASE_API posix_error : virtual public std::exception, virtual public boost::exception { };
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
class I2_BASE_API win32_error : virtual public std::exception, virtual public boost::exception { };
|
||||||
|
|
||||||
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
||||||
|
|
||||||
inline std::string to_string(const errinfo_win32_error& e)
|
inline std::string to_string(const errinfo_win32_error& e)
|
||||||
@ -70,7 +72,7 @@ inline std::string to_string(const errinfo_win32_error& e)
|
|||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
class openssl_error : virtual public std::exception, virtual public boost::exception { };
|
class I2_BASE_API openssl_error : virtual public std::exception, virtual public boost::exception { };
|
||||||
|
|
||||||
typedef boost::error_info<struct errinfo_openssl_error_, int> errinfo_openssl_error;
|
typedef boost::error_info<struct errinfo_openssl_error_, int> errinfo_openssl_error;
|
||||||
|
|
||||||
|
@ -144,14 +144,15 @@ void Socket::HandleException(void)
|
|||||||
{
|
{
|
||||||
ObjectLock olock(this);
|
ObjectLock olock(this);
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("select")
|
<< errinfo_api_function("select")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(GetError()));
|
||||||
<< errinfo_errno(GetError())
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
<< errinfo_win32_error(GetError())
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
|
<< errinfo_api_function("select")
|
||||||
|
<< errinfo_win32_error(GetError()));
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,14 +167,15 @@ String Socket::GetAddressFromSockaddr(sockaddr *address, socklen_t len)
|
|||||||
|
|
||||||
if (getnameinfo(address, len, host, sizeof(host), service,
|
if (getnameinfo(address, len, host, sizeof(host), service,
|
||||||
sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV) < 0) {
|
sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV) < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("getnameinfo")
|
<< errinfo_api_function("getnameinfo")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("getnameinfo")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
stringstream s;
|
stringstream s;
|
||||||
@ -194,14 +196,15 @@ String Socket::GetClientAddress(void)
|
|||||||
socklen_t len = sizeof(sin);
|
socklen_t len = sizeof(sin);
|
||||||
|
|
||||||
if (getsockname(GetFD(), (sockaddr *)&sin, &len) < 0) {
|
if (getsockname(GetFD(), (sockaddr *)&sin, &len) < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("getsockname")
|
<< errinfo_api_function("getsockname")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("getsockname")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetAddressFromSockaddr((sockaddr *)&sin, len);
|
return GetAddressFromSockaddr((sockaddr *)&sin, len);
|
||||||
@ -220,14 +223,15 @@ String Socket::GetPeerAddress(void)
|
|||||||
socklen_t len = sizeof(sin);
|
socklen_t len = sizeof(sin);
|
||||||
|
|
||||||
if (getpeername(GetFD(), (sockaddr *)&sin, &len) < 0) {
|
if (getpeername(GetFD(), (sockaddr *)&sin, &len) < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("getpeername")
|
<< errinfo_api_function("getpeername")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("getpeername")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetAddressFromSockaddr((sockaddr *)&sin, len);
|
return GetAddressFromSockaddr((sockaddr *)&sin, len);
|
||||||
@ -271,14 +275,15 @@ void Socket::ReadThreadProc(void)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("select")
|
<< errinfo_api_function("select")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("select")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fd, &readfds))
|
if (FD_ISSET(fd, &readfds))
|
||||||
@ -337,14 +342,15 @@ void Socket::WriteThreadProc(void)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("select")
|
<< errinfo_api_function("select")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("select")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fd, &writefds))
|
if (FD_ISSET(fd, &writefds))
|
||||||
@ -466,14 +472,15 @@ void Socket::Write(const void *buffer, size_t size)
|
|||||||
void Socket::Listen(void)
|
void Socket::Listen(void)
|
||||||
{
|
{
|
||||||
if (listen(GetFD(), SOMAXCONN) < 0) {
|
if (listen(GetFD(), SOMAXCONN) < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("listen")
|
<< errinfo_api_function("listen")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("listen")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -523,14 +530,15 @@ void Socket::HandleWritableClient(void)
|
|||||||
rc = send(GetFD(), data, count, 0);
|
rc = send(GetFD(), data, count, 0);
|
||||||
|
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("send")
|
<< errinfo_api_function("send")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("send")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
m_SendQueue->Read(NULL, rc);
|
m_SendQueue->Read(NULL, rc);
|
||||||
@ -559,14 +567,15 @@ void Socket::HandleReadableClient(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("recv")
|
<< errinfo_api_function("recv")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
#else /* _WIN32 */
|
||||||
#else /* _WIN32 */
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
<< errinfo_api_function("recv")
|
||||||
#endif /* _WIN32 */
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
);
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
new_data = true;
|
new_data = true;
|
||||||
@ -602,14 +611,15 @@ void Socket::HandleReadableServer(void)
|
|||||||
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
|
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("accept")
|
<< errinfo_api_function("accept")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
|
<< errinfo_api_function("accept")
|
||||||
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Ptr client = boost::make_shared<Socket>();
|
Socket::Ptr client = boost::make_shared<Socket>();
|
||||||
|
@ -53,14 +53,15 @@ void TcpSocket::Bind(String node, String service, int family)
|
|||||||
|
|
||||||
if (getaddrinfo(node.IsEmpty() ? NULL : node.CStr(),
|
if (getaddrinfo(node.IsEmpty() ? NULL : node.CStr(),
|
||||||
service.CStr(), &hints, &result) < 0) {
|
service.CStr(), &hints, &result) < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("getaddrinfo")
|
<< errinfo_api_function("getaddrinfo")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
|
<< errinfo_api_function("getaddrinfo")
|
||||||
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = INVALID_SOCKET;
|
int fd = INVALID_SOCKET;
|
||||||
@ -123,14 +124,15 @@ void TcpSocket::Connect(const String& node, const String& service)
|
|||||||
int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result);
|
int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result);
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
BOOST_THROW_EXCEPTION(socket_error()
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
<< errinfo_api_function("getaddrinfo")
|
<< errinfo_api_function("getaddrinfo")
|
||||||
#ifndef _WIN32
|
<< errinfo_errno(errno));
|
||||||
<< errinfo_errno(errno)
|
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
<< errinfo_win32_error(WSAGetLastError())
|
BOOST_THROW_EXCEPTION(socket_error()
|
||||||
|
<< errinfo_api_function("getaddrinfo")
|
||||||
|
<< errinfo_win32_error(WSAGetLastError()));
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = INVALID_SOCKET;
|
int fd = INVALID_SOCKET;
|
||||||
|
@ -278,8 +278,10 @@ String Utility::DirName(const String& path)
|
|||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
if (!PathRemoveFileSpec(dir)) {
|
if (!PathRemoveFileSpec(dir)) {
|
||||||
free(dir);
|
free(dir);
|
||||||
BOOST_THROW_EXCEPTION(Win32Exception("PathRemoveFileSpec() failed",
|
|
||||||
GetLastError()));
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< errinfo_api_function("PathRemoveFileSpec")
|
||||||
|
<< errinfo_win32_error(GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dir;
|
result = dir;
|
||||||
@ -420,8 +422,12 @@ Utility::LoadIcingaLibrary(const String& library, bool module)
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HMODULE hModule = LoadLibrary(path.CStr());
|
HMODULE hModule = LoadLibrary(path.CStr());
|
||||||
|
|
||||||
if (hModule == NULL)
|
if (hModule == NULL) {
|
||||||
BOOST_THROW_EXCEPTION(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError()));
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< errinfo_api_function("LoadLibrary")
|
||||||
|
<< errinfo_win32_error(GetLastError())
|
||||||
|
<< errinfo_file_name(path));
|
||||||
|
}
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
lt_dlhandle hModule = lt_dlopen(path.CStr());
|
lt_dlhandle hModule = lt_dlopen(path.CStr());
|
||||||
|
|
||||||
@ -463,15 +469,21 @@ bool Utility::Glob(const String& pathSpec, const function<void (const String&)>&
|
|||||||
if (errorCode == ERROR_FILE_NOT_FOUND)
|
if (errorCode == ERROR_FILE_NOT_FOUND)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(Win32Exception("FindFirstFile() failed", errorCode));
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< errinfo_api_function("FindFirstFile")
|
||||||
|
<< errinfo_win32_error(errorCode)
|
||||||
|
<< errinfo_file_name(pathSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
callback(DirName(pathSpec) + "/" + wfd.cFileName);
|
callback(DirName(pathSpec) + "/" + wfd.cFileName);
|
||||||
} while (FindNextFile(handle, &wfd));
|
} while (FindNextFile(handle, &wfd));
|
||||||
|
|
||||||
if (!FindClose(handle))
|
if (!FindClose(handle)) {
|
||||||
BOOST_THROW_EXCEPTION(Win32Exception("FindClose() failed", GetLastError()));
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< errinfo_api_function("FindClose")
|
||||||
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user