[A]Support for windows.
[B]Modify README.md.
This commit is contained in:
+16
-8
@@ -3,25 +3,32 @@ cmake_minimum_required(VERSION 3.0)
|
||||
set(SDK_LIBRARY ${PROJECT_NAME}_static)
|
||||
add_library(${SDK_LIBRARY} STATIC "")
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(APR apr-1)
|
||||
if (WIN32)
|
||||
find_path(APR_INCLUDE_DIRS apr.h)
|
||||
find_library(APR_LIBRARIES libapr-1)
|
||||
if (APR_LIBRARIES AND APR_INCLUDE_DIRS)
|
||||
set(APR_FOUND "YES")
|
||||
endif (APR_LIBRARIES AND APR_INCLUDE_DIRS)
|
||||
else (WIN32)
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(APR apr-1)
|
||||
endif (WIN32)
|
||||
|
||||
if (APR_FOUND)
|
||||
target_include_directories(${SDK_LIBRARY}
|
||||
PRIVATE
|
||||
${APR_INCLUDE_DIRS})
|
||||
target_link_libraries(${SDK_LIBRARY}
|
||||
PRIVATE
|
||||
PUBLIC
|
||||
${APR_LIBRARIES})
|
||||
elseif ()
|
||||
message("Can't find Apache Runtime Library, please install.")
|
||||
endif ()
|
||||
|
||||
|
||||
find_package(Boost 1.54 REQUIRED COMPONENTS system)
|
||||
if (Boost_FOUND AND Boost_VERSION LESS 106900)
|
||||
target_link_libraries(${SDK_LIBRARY}
|
||||
PRIVATE
|
||||
${Boost_LIBRARIES})
|
||||
PUBLIC
|
||||
Boost::boost
|
||||
Boost::system)
|
||||
endif ()
|
||||
|
||||
target_include_directories(${SDK_LIBRARY}
|
||||
@@ -84,3 +91,4 @@ install(TARGETS ${SDK_LIBRARY}
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib)
|
||||
|
||||
|
||||
|
||||
@@ -39,8 +39,14 @@ bool IOLoop::Init() {
|
||||
if (mem_pool_ == NULL) {
|
||||
return false;
|
||||
}
|
||||
#ifdef WIN32
|
||||
apr_status_t rv =
|
||||
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_WAKEABLE);
|
||||
#else
|
||||
apr_status_t rv =
|
||||
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_THREADSAFE | APR_POLLSET_WAKEABLE);
|
||||
#endif
|
||||
|
||||
if (rv != APR_SUCCESS) {
|
||||
LOG_ERROR << PrintAPRStatus(rv) << std::endl;
|
||||
return false;
|
||||
|
||||
@@ -23,7 +23,17 @@
|
||||
//
|
||||
|
||||
#include "network_util.h"
|
||||
#ifdef WIN32
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <Winsock2.h>
|
||||
#include <Iphlpapi.h>
|
||||
#include <string>
|
||||
#pragma comment(lib,"Iphlpapi.lib")
|
||||
#pragma comment(lib,"ws2_32.lib")
|
||||
#else
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
namespace livox {
|
||||
namespace util {
|
||||
apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool nonblock) {
|
||||
@@ -55,6 +65,37 @@ apr_socket_t *CreateBindSocket(uint16_t port, apr_pool_t *mem_pool, bool nonbloc
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
||||
bool found = false;
|
||||
ULONG ulOutbufLen = sizeof(IP_ADAPTER_INFO);
|
||||
boost::scoped_array<uint8_t> pAdapterInfo(new uint8_t[ulOutbufLen]);
|
||||
DWORD dlRetVal = GetAdaptersInfo(reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get()), &ulOutbufLen);
|
||||
if (dlRetVal == ERROR_BUFFER_OVERFLOW) {
|
||||
pAdapterInfo.reset(new uint8_t[ulOutbufLen]);
|
||||
dlRetVal = GetAdaptersInfo(reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get()), &ulOutbufLen);
|
||||
}
|
||||
|
||||
IP_ADAPTER_INFO *pAdapter = reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get());
|
||||
if (NO_ERROR == dlRetVal && pAdapter != NULL) {
|
||||
while (pAdapterInfo) {
|
||||
std::string str_ip = pAdapter->IpAddressList.IpAddress.String;
|
||||
std::string str_mask = pAdapter->IpAddressList.IpMask.String;
|
||||
ULONG host_ip = inet_addr(const_cast<char *>(str_ip.c_str()));
|
||||
ULONG host_mask = inet_addr(const_cast<char *>(str_mask.c_str()));
|
||||
|
||||
if ((host_ip & host_mask) ==
|
||||
(client_addr.sin_addr.S_un.S_addr & host_mask)) {
|
||||
local_ip = host_ip;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
#else
|
||||
bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
||||
struct ifaddrs *if_addrs = NULL, *addrs = NULL;
|
||||
if (getifaddrs(&if_addrs) == -1) {
|
||||
@@ -85,6 +126,6 @@ bool FindLocalIP(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace util
|
||||
} // namespace livox
|
||||
} // namespace livox
|
||||
@@ -26,6 +26,10 @@
|
||||
#define LIVOX_NETWORK_UTIL_H_
|
||||
#include <apr_general.h>
|
||||
#include <apr_network_io.h>
|
||||
#ifdef WIN32
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace livox {
|
||||
namespace util {
|
||||
|
||||
@@ -30,7 +30,11 @@
|
||||
#include <vector>
|
||||
#include "apr_network_io.h"
|
||||
#include "apr_pools.h"
|
||||
#ifdef WIN32
|
||||
#include "winsock.h"
|
||||
#else
|
||||
#include "arpa/inet.h"
|
||||
#endif
|
||||
#include "base/logging.h"
|
||||
#include "base/network_util.h"
|
||||
#include "command_handler/command_impl.h"
|
||||
|
||||
@@ -172,6 +172,9 @@ bool DeviceManager::AddListeningDevice(const string &broadcast_code, DeviceMode
|
||||
strncpy(ite->info.broadcast_code, broadcast_code.c_str(), sizeof(ite->info.broadcast_code));
|
||||
ite->info.handle = handle;
|
||||
return true;
|
||||
} else if (strncmp(ite->info.broadcast_code, broadcast_code.c_str(), sizeof(ite->info.broadcast_code)) == 0) {
|
||||
handle = ite->info.handle;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user