diff --git a/cmake/FindURIParser.cmake b/cmake/FindURIParser.cmake index 70d3366ebbfaa6b337bb25baaf94ffe2ae7f460a..e1db241682815e732125dda7b93888fc8c4cd4ae 100644 --- a/cmake/FindURIParser.cmake +++ b/cmake/FindURIParser.cmake @@ -31,6 +31,6 @@ mark_as_advanced(URIPARSER_FOUND) if(URIPARSER_FOUND) include_directories(${URIPARSER_INCLUDE_DIRS}) set(URIPARSER_FOUND TRUE CACHE BOOL "" FORCE) - set(URIPARSER_LIBRARIES ${URIPARSER_LIBRARY}) + set(URIPARSER_LIBRARIES "${URIPARSER_LIBRARY}") message(STATUS "Found URIParser") endif() diff --git a/net/cpp/src/net.cpp b/net/cpp/src/net.cpp index 3ea57c1c483bc4db84012ebd79cfc6d5c82182d6..9aae938f816f9072e50089245ce47d1657d4e9b8 100644 --- a/net/cpp/src/net.cpp +++ b/net/cpp/src/net.cpp @@ -10,6 +10,10 @@ #include <iostream> #include <chrono> +#ifdef WIN32 +#pragma comment(lib, "Ws2_32.lib") +#endif + using namespace std; using namespace std::chrono; using ftl::net::Listener; diff --git a/net/cpp/test/CMakeLists.txt b/net/cpp/test/CMakeLists.txt index ee774f88d274c9d2a8da7177926ec2595468b4ac..03a789594c94ce7aa399a8411d48d982bee6cc10 100644 --- a/net/cpp/test/CMakeLists.txt +++ b/net/cpp/test/CMakeLists.txt @@ -3,21 +3,21 @@ add_executable(protocol_unit ./protocol_unit.cpp ) target_include_directories(protocol_unit PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(protocol_unit glog) +target_link_libraries(protocol_unit ${GLOG_LIBRARIES}) add_executable(socket_unit ./tests.cpp ./socket_unit.cpp ) target_include_directories(socket_unit PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(socket_unit uriparser glog) +target_link_libraries(socket_unit ${URIPARSER_LIBRARIES} ${GLOG_LIBRARIES}) add_executable(uri_unit ./tests.cpp ./uri_unit.cpp ) target_include_directories(uri_unit PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(uri_unit uriparser) +target_link_libraries(uri_unit ${URIPARSER_LIBRARIES}) add_executable(p2p_base_unit ./tests.cpp @@ -30,7 +30,7 @@ add_executable(p2p_base_unit ../src/listener.cpp ) target_include_directories(p2p_base_unit PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(p2p_base_unit uriparser gflags glog uuid) +target_link_libraries(p2p_base_unit ${URIPARSER_LIBRARIES} gflags ${GLOG_LIBRARIES} uuid) add_executable(net_integration ./tests.cpp @@ -42,7 +42,7 @@ add_executable(net_integration ../src/net.cpp ) target_include_directories(net_integration PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(net_integration uriparser glog) +target_link_libraries(net_integration ${URIPARSER_LIBRARIES} ${GLOG_LIBRARIES}) add_test(URIUnitTest uri_unit) add_test(ProtocolUnitTest protocol_unit) diff --git a/net/cpp/test/net_integration.cpp b/net/cpp/test/net_integration.cpp index 86a478d8dab981f5f99b19f0d8a91212be787eac..ea915da0b82a7351d66e74f3d3b9d990f534380d 100644 --- a/net/cpp/test/net_integration.cpp +++ b/net/cpp/test/net_integration.cpp @@ -25,9 +25,8 @@ using std::shared_ptr; #ifdef WIN32 #include <windows.h> -#include <winsock.h> -typedef int socklen_t; -#define MSG_WAITALL 0 +#include <winsock2.h> +#include <Ws2tcpip.h> #endif static int ssock = INVALID_SOCKET; @@ -66,7 +65,7 @@ void init_server() { } int enable = 1; - if (setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) + if (setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR, (char*)&enable, sizeof(int)) < 0) std::cerr << "setsockopt(SO_REUSEADDR) failed" << std::endl; //Specify listen port and address diff --git a/net/cpp/test/socket_unit.cpp b/net/cpp/test/socket_unit.cpp index 881da27a96a6d61464450262a5d8c5e4b669a1a2..fc76725e723e81d6ba43c23f7937493f19bda40b 100644 --- a/net/cpp/test/socket_unit.cpp +++ b/net/cpp/test/socket_unit.cpp @@ -8,6 +8,10 @@ using ftl::net::Socket; +#ifdef WIN32 +#pragma comment(lib, "Ws2_32.lib") +#endif + // --- Mock -------------------------------------------------------------------- class MockSocket : public Socket { @@ -43,7 +47,8 @@ static std::map<int, std::string> fakedata; void fake_send(int sd, uint32_t service, const std::string &data) { //std::cout << "HEX SEND: " << hexStr(data) << std::endl; - char buf[8+data.size()]; + char buf[8+1024]; + assert(data.size() < 1024); ftl::net::Header *h = (ftl::net::Header*)&buf; h->size = data.size()+4; h->service = service; @@ -53,7 +58,11 @@ void fake_send(int sd, uint32_t service, const std::string &data) { //std::cout << "HEX SEND2: " << hexStr(fakedata[sd]) << std::endl; } +#ifdef WIN32 +extern int recv(SOCKET sd, char *buf, int n, int f) { +#else extern ssize_t recv(int sd, void *buf, size_t n, int f) { +#endif if (fakedata.count(sd) == 0) { std::cout << "Unrecognised socket" << std::endl; return 0; @@ -66,6 +75,14 @@ extern ssize_t recv(int sd, void *buf, size_t n, int f) { return l; } +#ifdef WIN32 +extern int send(SOCKET sd, const char *v, int cnt, int flags) { + int len = cnt; + // TODO(nick) merge multiple sends + fakedata[sd] = std::string(v, len); + return len; +} +#else extern ssize_t writev(int sd, const struct iovec *v, int cnt) { size_t len = 0; //v[0].iov_len+v[1].iov_len; char buf[1000]; @@ -80,6 +97,7 @@ extern ssize_t writev(int sd, const struct iovec *v, int cnt) { fakedata[sd] = std::string(&buf[0], len); return len; } +#endif uint32_t get_service(int sd) { auto h = (ftl::net::Header*)fakedata[sd].data();