diff --git a/CMakeLists.txt b/CMakeLists.txt index bc281891031370d26fb48cb89398b35e746f2823..eca831d0646f2e6414916a0b7e4c4930cfc68ce5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ find_package( glog REQUIRED ) find_package( OpenCV REQUIRED ) find_package( Threads REQUIRED ) find_package( URIParser REQUIRED ) -find_package( MsgPack ) +find_package( MsgPack REQUIRED ) find_package( LibSGM ) check_language(CUDA) @@ -35,6 +35,14 @@ if (NOT MsgPack_FOUND) message(ERROR "Msgpack is required") endif() else() + if(WIN32) + # Find include + find_path(MSGPACK_INCLUDE_DIRS + NAMES msgpack.hpp + PATHS "C:/Program Files/msgpack" "C:/Program Files (x86)/msgpack" + PATH_SUFFIXES include + ) + endif() include_directories(${MSGPACK_INCLUDE_DIRS}) endif() diff --git a/net/cpp/include/ftl/net/listener.hpp b/net/cpp/include/ftl/net/listener.hpp index 4d86df5c210ccbdf73b255bf31c885d2863f535a..09c1f68f0bea4a047010938ea72387f52c6749ba 100644 --- a/net/cpp/include/ftl/net/listener.hpp +++ b/net/cpp/include/ftl/net/listener.hpp @@ -7,7 +7,7 @@ #ifdef WIN32 //#include <windows.h> -#include <winsock.h> +#include <winsock2.h> #endif #include <ftl/net/handlers.hpp> diff --git a/net/cpp/include/ftl/net/socket.hpp b/net/cpp/include/ftl/net/socket.hpp index f87f4c782d07813458ed08de9bda9afe9784b060..a1c062a3722aaf718bf4f5fd47e7d889a01d20c8 100644 --- a/net/cpp/include/ftl/net/socket.hpp +++ b/net/cpp/include/ftl/net/socket.hpp @@ -1,6 +1,7 @@ #ifndef _FTL_NET_SOCKET_HPP_ #define _FTL_NET_SOCKET_HPP_ +#define GLOG_NO_ABBREVIATED_SEVERITIES #include <glog/logging.h> #include <ftl/net.hpp> #include <ftl/net/protocol.hpp> @@ -12,7 +13,8 @@ #ifdef WIN32 //#include <windows.h> -#include <winsock.h> +//#include <winsock.h> +#include <winsock2.h> #endif #include <iostream> diff --git a/net/cpp/src/dispatcher.cpp b/net/cpp/src/dispatcher.cpp index 32239bd2b52dd31d1238aaea43091f5fa1d8bcf2..0d95a2a5528599dfbc3bc98e3a1aac6b6dbea0ba 100644 --- a/net/cpp/src/dispatcher.cpp +++ b/net/cpp/src/dispatcher.cpp @@ -1,3 +1,4 @@ +#define GLOG_NO_ABBREVIATED_SEVERITIES #include <glog/logging.h> #include <ftl/net/dispatcher.hpp> #include <ftl/net/socket.hpp> diff --git a/net/cpp/src/listener.cpp b/net/cpp/src/listener.cpp index 0338db14abc3f089cf948eacfa440e58d6dc4ea1..dcfe31bf0ca3d4687be5b112041aedbff1fc066b 100644 --- a/net/cpp/src/listener.cpp +++ b/net/cpp/src/listener.cpp @@ -1,3 +1,4 @@ +#define GLOG_NO_ABBREVIATED_SEVERITIES #include <glog/logging.h> #include <ftl/uri.hpp> @@ -27,6 +28,7 @@ typedef int socklen_t; using namespace ftl; using ftl::net::Listener; using std::shared_ptr; +using ftl::net::Socket; int tcpListen(URI &uri) { int ssock; @@ -45,7 +47,7 @@ int tcpListen(URI &uri) { } 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) LOG(ERROR) << "setsockopt(SO_REUSEADDR) failed"; //Specify listen port and address diff --git a/net/cpp/src/net.cpp b/net/cpp/src/net.cpp index 478f336ee21ea127ee0ad9fb10c786f8dca9e636..3ea57c1c483bc4db84012ebd79cfc6d5c82182d6 100644 --- a/net/cpp/src/net.cpp +++ b/net/cpp/src/net.cpp @@ -2,6 +2,10 @@ #include <ftl/net/listener.hpp> #include <ftl/net/socket.hpp> +#ifdef WIN32 +#include <Ws2tcpip.h> +#endif + #include <vector> #include <iostream> #include <chrono> @@ -135,6 +139,7 @@ bool _run(bool blocking, bool nodelay) { if (FD_ISSET(l->_socket(), &sfdread)) { int rsize = sizeof(sockaddr_storage); sockaddr_storage addr; + //int freeclient = freeSocket(); //if (freeclient >= 0) { diff --git a/net/cpp/src/protocol.cpp b/net/cpp/src/protocol.cpp index 125477376eb68e02defe7c747e829d0b56c27c7c..27f1146d6977035603ecf309bf1a2a2584fc8f24 100644 --- a/net/cpp/src/protocol.cpp +++ b/net/cpp/src/protocol.cpp @@ -1,3 +1,4 @@ +#define GLOG_NO_ABBREVIATED_SEVERITIES #include <glog/logging.h> #include <ftl/net/socket.hpp> #include <ftl/net/protocol.hpp> diff --git a/net/cpp/src/socket.cpp b/net/cpp/src/socket.cpp index 1d1cadbf3dc55ce22f0f28d8c33fe920db26bdc4..a992cf0554cf2dbb5481f7cdc773b292d25d3c4a 100644 --- a/net/cpp/src/socket.cpp +++ b/net/cpp/src/socket.cpp @@ -1,3 +1,4 @@ +#define GLOG_NO_ABBREVIATED_SEVERITIES #include <glog/logging.h> #include <ftl/uri.hpp> @@ -16,9 +17,8 @@ #ifdef WIN32 #include <windows.h> -#include <winsock.h> -typedef int socklen_t; -#define MSG_WAITALL 0 +#include <winsock2.h> +#include <Ws2tcpip.h> #endif #include <iostream> @@ -27,6 +27,7 @@ typedef int socklen_t; using namespace ftl; using ftl::net::Socket; +using ftl::net::Protocol; using namespace std; /*static std::string hexStr(const std::string &s) @@ -233,8 +234,12 @@ void Socket::setProtocol(Protocol *p) { void Socket::error() { int err; +#ifdef WIN32 + int optlen = sizeof(err); +#else uint32_t optlen = sizeof(err); - getsockopt(sock_, SOL_SOCKET, SO_ERROR, &err, &optlen); +#endif + getsockopt(sock_, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen); LOG(ERROR) << "Socket: " << uri_ << " - error " << err; } @@ -390,7 +395,15 @@ void Socket::_connected() { } int Socket::_send() { +#ifdef WIN32 + // TODO(nick) Use WSASend instead + int c = 0; + for (auto v : send_vec_) { + c += ::send(sock_, (char*)v.iov_base, v.iov_len, 0); + } +#else int c = ::writev(sock_, send_vec_.data(), send_vec_.size()); +#endif send_vec_.clear(); return c; }