diff --git a/README.md b/README.md index 6b33344a30..32627d23dd 100644 --- a/README.md +++ b/README.md @@ -154,13 +154,9 @@ where the `~~ HACK ~~` message is from code in `KERNEL.CGO`. ## TODOs - Build on Windows! - - Networking - File paths - Timer - - CMake? - - Assembly - Windows calling convention for assembly stuff - - pthreads (can probably replace with `std::thread`, I don't remember why I used `pthread`s) - performance stats for `SystemThread` (probably just get rid of these performance stats completely) - `mmap`ing executable memory - line input library (appears windows compatible?) diff --git a/common/cross_sockets/xsocket.cpp b/common/cross_sockets/xsocket.cpp index de15d2ec90..0fa79e6864 100644 --- a/common/cross_sockets/xsocket.cpp +++ b/common/cross_sockets/xsocket.cpp @@ -22,7 +22,7 @@ int open_socket(int af, int type, int protocol) { printf("WSAStartup failed: %d\n", iResult); return 1; } - return socket(af, type, protocol); + return socket(af, type, protocol); #endif } @@ -42,11 +42,11 @@ int set_socket_option(int socket, int level, int optname, const char* optval, in #ifdef __linux return setsockopt(socket, level, optname, optval, optlen); #elif _WIN32 - int ret = setsockopt(socket, level, optname, optval, optlen); + int ret = setsockopt(socket, level, optname, optval, optlen); if (ret < 0) { - int err = WSAGetLastError(); - printf("Failed to setsockopt - Err: %d\n", err); - } + int err = WSAGetLastError(); + printf("Failed to setsockopt - Err: %d\n", err); + } return ret; #endif } diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 3a18ddf0cc..e51dde9e25 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -81,5 +81,5 @@ IF (WIN32) target_link_libraries(gk cross_sockets mman) ELSE() # set stuff for other systems - target_link_libraries(gk cross_sockets) + target_link_libraries(gk cross_sockets pthread) ENDIF() diff --git a/game/runtime.cpp b/game/runtime.cpp index a35fd9f717..f851e11a82 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -84,7 +84,7 @@ void deci2_runner(SystemThreadInterface& iface) { server.run(); } else { // no connection yet. Do a sleep so we don't spam checking the listener. - std::this_thread::sleep_for(std::chrono::microseconds(50000)); + std::this_thread::sleep_for(std::chrono::microseconds(50000)); } } } diff --git a/game/system/Deci2Server.cpp b/game/system/Deci2Server.cpp index 5f2308f575..7579b60f65 100644 --- a/game/system/Deci2Server.cpp +++ b/game/system/Deci2Server.cpp @@ -63,21 +63,20 @@ bool Deci2Server::init() { #endif char opt = 1; - if (set_socket_option(server_socket, SOL_SOCKET, server_socket_opt, &opt, sizeof(opt)) < - 0) { + if (set_socket_option(server_socket, SOL_SOCKET, server_socket_opt, &opt, sizeof(opt)) < 0) { close_server_socket(); return false; } - if (set_socket_option(server_socket, server_socket_tcp_level, TCP_NODELAY, &opt, - sizeof(opt)) < 0) { + if (set_socket_option(server_socket, server_socket_tcp_level, TCP_NODELAY, &opt, sizeof(opt)) < + 0) { close_server_socket(); return false; } // TODO - put in library #ifdef __linux - timeval timeout = {}; + timeval timeout = {}; timeout.tv_sec = 0; timeout.tv_usec = 100000; if (set_socket_option(server_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < @@ -274,7 +273,8 @@ void Deci2Server::run() { void Deci2Server::accept_thread_func() { socklen_t l = sizeof(addr); while (!kill_accept_thread) { - // TODO - might want to do a WSAStartUp call here as well, else it won't be balanced on the close + // TODO - might want to do a WSAStartUp call here as well, else it won't be balanced on the + // close new_sock = accept(server_socket, (sockaddr*)&addr, &l); if (new_sock >= 0) { u32 versions[2] = {versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR}; diff --git a/goalc/listener/Listener.cpp b/goalc/listener/Listener.cpp index 774f0415a0..11f62f0260 100644 --- a/goalc/listener/Listener.cpp +++ b/goalc/listener/Listener.cpp @@ -71,24 +71,22 @@ bool Listener::connect_to_target(const std::string& ip, int port) { return false; } - // TODO - put in library + // TODO - put in library #ifdef __linux - timeval timeout = {}; + timeval timeout = {}; timeout.tv_sec = 0; timeout.tv_usec = 100000; - if (set_socket_option(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < - 0) { + if (set_socket_option(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0) { close_socket(socket_fd); - socket_fd = -1; + socket_fd = -1; return false; } #elif _WIN32 unsigned long timeout = 100; // ms - if (set_socket_option(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < - 0) { - printf("[Listener] setsockopt failed\n"); + if (set_socket_option(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0) { + printf("[Listener] setsockopt failed\n"); close_socket(socket_fd); - socket_fd = -1; + socket_fd = -1; return false; } #endif @@ -206,7 +204,8 @@ void Listener::receive_func() { while (rcvd < hdr->deci2_header.len) { if (!m_connected) return; - int got = read_from_socket(socket_fd, ack_recv_buff + ack_recv_prog, hdr->deci2_header.len - rcvd); + int got = read_from_socket(socket_fd, ack_recv_buff + ack_recv_prog, + hdr->deci2_header.len - rcvd); got = got > 0 ? got : 0; rcvd += got; ack_recv_prog += got; diff --git a/test/test_listener_deci2.cpp b/test/test_listener_deci2.cpp index 99874e3d09..a2ffd96e8c 100644 --- a/test/test_listener_deci2.cpp +++ b/test/test_listener_deci2.cpp @@ -23,12 +23,6 @@ TEST(Listener, DeciInit) { EXPECT_TRUE(s.init()); } -// TEST(Listener, TwoDeciServers) { -// Deci2Server s1, s2; -// EXPECT_TRUE(s1.init()); -// EXPECT_TRUE(s2.init()); -//} - /*! * Try to connect when no Deci2Server is running */ @@ -62,9 +56,8 @@ TEST(Listener, DeciThenListener) { EXPECT_FALSE(s.check_for_listener()); EXPECT_FALSE(s.check_for_listener()); EXPECT_TRUE(l.connect_to_target()); - // kind of a hack. + // TODO - some sort of backoff and retry would be better while (!s.check_for_listener()) { - // printf("...\n"); } EXPECT_TRUE(s.check_for_listener()); @@ -93,34 +86,8 @@ TEST(Listener, ListenerThenDeci) { EXPECT_TRUE(s.init()); EXPECT_FALSE(s.check_for_listener()); EXPECT_TRUE(l.connect_to_target()); + // TODO - some sort of backoff and retry would be better while (!s.check_for_listener()) { - // printf("...\n"); } } } - -TEST(Listener, ListenerMultipleDecis) { - Listener l; - EXPECT_FALSE(l.connect_to_target()); - { - Deci2Server s(always_false); - EXPECT_TRUE(s.init()); - EXPECT_FALSE(s.check_for_listener()); - EXPECT_TRUE(l.connect_to_target()); - while (!s.check_for_listener()) { - // printf("...\n"); - } - l.disconnect(); - } - - { - Deci2Server s(always_false); - EXPECT_TRUE(s.init()); - EXPECT_FALSE(s.check_for_listener()); - EXPECT_TRUE(l.connect_to_target()); - while (!s.check_for_listener()) { - // printf("...\n"); - } - l.disconnect(); - } -}