From 25f7a87a79fb25e927c92771bdfca0f845037688 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Mon, 27 Apr 2020 10:21:24 -0500 Subject: [PATCH] Get network server working in Windows --- NetworkServer.cpp | 25 +++++++++++-------- OpenRGB.pro | 1 - .../RGBController_CorsairPeripheral.cpp | 16 ++++++++++++ net_port/net_port.cpp | 2 +- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/NetworkServer.cpp b/NetworkServer.cpp index 4ed8bceb..670f0d24 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -74,7 +74,10 @@ void NetworkServer::ConnectionThread() SOCKET * client_sock = port.tcp_server_listen(); //Start a listener thread for the new client socket #ifdef WIN32 - _beginthread(listen_thread, 0, this); + listen_thread_param_type new_thread_param; + new_thread_param.sock_ptr = client_sock; + new_thread_param.this_ptr = this; + _beginthread(listen_thread, 0, &new_thread_param); #else pthread_t thread; @@ -97,7 +100,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock) char * data = NULL; //Read first byte of magic - bytes_read = read(*client_sock, &header.pkt_magic[0], 1); + bytes_read = recv(*client_sock, &header.pkt_magic[0], 1, 0); if(bytes_read == 0) { @@ -111,7 +114,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock) } //Read second byte of magic - bytes_read = read(*client_sock, &header.pkt_magic[1], 1); + bytes_read = recv(*client_sock, &header.pkt_magic[1], 1, 0); if(bytes_read == 0) { @@ -125,7 +128,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock) } //Read third byte of magic - bytes_read = read(*client_sock, &header.pkt_magic[2], 1); + bytes_read = recv(*client_sock, &header.pkt_magic[2], 1, 0); if(bytes_read == 0) { @@ -139,7 +142,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock) } //Read fourth byte of magic - bytes_read = read(*client_sock, &header.pkt_magic[3], 1); + bytes_read = recv(*client_sock, &header.pkt_magic[3], 1, 0); if(bytes_read == 0) { @@ -156,7 +159,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock) bytes_read = 0; do { - bytes_read += read(*client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read); + bytes_read += recv(*client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read, 0); if(bytes_read == 0) { @@ -175,7 +178,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock) do { - bytes_read += read(*client_sock, &data[bytes_read], header.pkt_size - bytes_read); + bytes_read += recv(*client_sock, &data[bytes_read], header.pkt_size - bytes_read, 0); } while (bytes_read < header.pkt_size); } @@ -290,8 +293,8 @@ void NetworkServer::SendReply_ControllerCount(SOCKET * client_sock) reply_data = controllers.size(); - write(*client_sock, &reply_hdr, sizeof(NetPacketHeader)); - write(*client_sock, &reply_data, sizeof(unsigned int)); + send(*client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0); + send(*client_sock, (const char *)&reply_data, sizeof(unsigned int), 0); } void NetworkServer::SendReply_ControllerData(SOCKET * client_sock, unsigned int dev_idx) @@ -313,7 +316,7 @@ void NetworkServer::SendReply_ControllerData(SOCKET * client_sock, unsigned int reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA; reply_hdr.pkt_size = reply_size; - write(*client_sock, &reply_hdr, sizeof(NetPacketHeader)); - write(*client_sock, reply_data, reply_size); + send(*client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0); + send(*client_sock, (const char *)reply_data, reply_size, 0); } } diff --git a/OpenRGB.pro b/OpenRGB.pro index 21367f54..98d312ee 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -69,7 +69,6 @@ SOURCES += \ cli.cpp \ OpenRGB.cpp \ NetworkClient.cpp \ - NetworkProtocol.cpp \ NetworkServer.cpp \ ProfileManager.cpp \ qt/OpenRGBDeviceInfoPage.cpp \ diff --git a/RGBController/RGBController_CorsairPeripheral.cpp b/RGBController/RGBController_CorsairPeripheral.cpp index 526ef0f8..ee7acbb8 100644 --- a/RGBController/RGBController_CorsairPeripheral.cpp +++ b/RGBController/RGBController_CorsairPeripheral.cpp @@ -21,6 +21,12 @@ static const unsigned int zone_sizes[] = 7 }; +static const zone_type zone_types[] = +{ + ZONE_TYPE_MATRIX, + ZONE_TYPE_SINGLE +}; + static const char* led_names[] = { "Key: Escape", //0 @@ -192,6 +198,7 @@ void RGBController_CorsairPeripheral::SetupZones() { case DEVICE_TYPE_KEYBOARD: new_zone.name = zone_names[zone_idx]; + new_zone.type = zone_types[zone_idx]; new_zone.leds_min = zone_sizes[zone_idx]; new_zone.leds_max = zone_sizes[zone_idx]; new_zone.leds_count = zone_sizes[zone_idx]; @@ -199,8 +206,17 @@ void RGBController_CorsairPeripheral::SetupZones() break; case DEVICE_TYPE_MOUSE: + new_zone.name = "Mousemat Zone"; + new_zone.type = ZONE_TYPE_SINGLE; + new_zone.leds_min = 15; + new_zone.leds_max = 15; + new_zone.leds_count = 15; + new_zone.matrix_map = NULL; + break; + case DEVICE_TYPE_MOUSEMAT: new_zone.name = "Mousemat Zone"; + new_zone.type = ZONE_TYPE_LINEAR; new_zone.leds_min = 15; new_zone.leds_max = 15; new_zone.leds_count = 15; diff --git a/net_port/net_port.cpp b/net_port/net_port.cpp index 450e553e..126bbd81 100644 --- a/net_port/net_port.cpp +++ b/net_port/net_port.cpp @@ -273,7 +273,7 @@ void net_port::tcp_close() int net_port::tcp_listen(char * recv_data, int length) { - return(read(sock, recv_data, length)); + return(recv(sock, recv_data, length, 0)); } int net_port::tcp_client_write(char * buffer, int length)