Get network server working in Windows
This commit is contained in:
parent
0619a16be2
commit
25f7a87a79
4 changed files with 31 additions and 13 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ SOURCES += \
|
|||
cli.cpp \
|
||||
OpenRGB.cpp \
|
||||
NetworkClient.cpp \
|
||||
NetworkProtocol.cpp \
|
||||
NetworkServer.cpp \
|
||||
ProfileManager.cpp \
|
||||
qt/OpenRGBDeviceInfoPage.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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue