2023-08-18 07:33:13 +02:00
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
global::Client::Client( std::shared_ptr<global::ThreadPool> ThreadPool, LPTSTR PipeName )
|
2023-08-18 07:33:13 +02:00
|
|
|
{
|
2023-08-22 19:32:25 +02:00
|
|
|
this->thread_pool = ThreadPool;
|
|
|
|
this->pipe = std::make_shared<global::Pipe>( PipeName );
|
|
|
|
}
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
/*
|
|
|
|
* Request an item from the server
|
|
|
|
*/
|
2023-08-24 15:12:49 +02:00
|
|
|
void global::Client::ServerReceive()
|
2023-08-22 19:32:25 +02:00
|
|
|
{
|
2023-08-24 15:12:49 +02:00
|
|
|
|
2023-08-18 07:33:13 +02:00
|
|
|
}
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
/*
|
|
|
|
* Send an item to the server
|
|
|
|
*/
|
|
|
|
void global::Client::ServerSend(PVOID Buffer, SIZE_T Size, INT RequestId)
|
2023-08-18 07:33:13 +02:00
|
|
|
{
|
2023-08-22 19:32:25 +02:00
|
|
|
mutex.lock();
|
2023-08-18 07:33:13 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
global::headers::PIPE_PACKET_HEADER header;
|
|
|
|
header.message_type = SERVER_SEND_PACKET_ID;
|
|
|
|
memcpy( this->send_buffer, &header, sizeof( global::headers::PIPE_PACKET_HEADER ) );
|
2023-08-18 07:33:13 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
LONG total_size_of_headers = sizeof( global::headers::PIPE_PACKET_HEADER ) + sizeof( global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER );
|
2023-08-18 09:18:00 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
if ( Size > ( SEND_BUFFER_SIZE - total_size_of_headers ) )
|
|
|
|
{
|
|
|
|
INT total_packets = std::ceil( Size / ( SEND_BUFFER_SIZE - total_size_of_headers ) );
|
2023-08-23 14:40:44 +02:00
|
|
|
LONG remaining_bytes = Size + total_packets * total_size_of_headers;
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-23 14:40:44 +02:00
|
|
|
for ( INT count = 0; count < total_packets + 1; count++ )
|
2023-08-22 19:32:25 +02:00
|
|
|
{
|
|
|
|
global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER header_extension;
|
|
|
|
header_extension.request_id = RequestId;
|
2023-08-23 17:16:13 +02:00
|
|
|
header_extension.total_incoming_packet_count = total_packets + 1;
|
|
|
|
header_extension.total_incoming_packet_size = Size + total_packets * total_size_of_headers;
|
2023-08-22 19:32:25 +02:00
|
|
|
header_extension.current_packet_number = count;
|
2023-08-23 14:40:44 +02:00
|
|
|
header_extension.packet_size = count == total_packets ? remaining_bytes : SEND_BUFFER_SIZE;
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-23 14:14:20 +02:00
|
|
|
LOG_INFO( "current packet number: %lx, packet size: %lx", header_extension.current_packet_number, header_extension.packet_size );
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
memcpy( PVOID( ( UINT64 )this->send_buffer + sizeof( global::headers::PIPE_PACKET_HEADER ) ),
|
|
|
|
&header_extension, sizeof(global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER));
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
memcpy(
|
|
|
|
PVOID( ( UINT64 )this->send_buffer + total_size_of_headers ), Buffer,
|
|
|
|
( UINT64 )header_extension.packet_size - total_size_of_headers
|
|
|
|
);
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
this->pipe->WriteToPipe( this->send_buffer, header_extension.packet_size );
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-23 14:40:44 +02:00
|
|
|
LOG_INFO( "remainiong bytes: %lx", remaining_bytes );
|
2023-08-22 19:32:25 +02:00
|
|
|
remaining_bytes = remaining_bytes - header_extension.packet_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2023-08-18 16:34:15 +02:00
|
|
|
{
|
2023-08-22 19:32:25 +02:00
|
|
|
global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER header_extension;
|
|
|
|
header_extension.request_id = RequestId;
|
|
|
|
header_extension.total_incoming_packet_count = 1;
|
2023-08-23 17:16:13 +02:00
|
|
|
header_extension.total_incoming_packet_size = Size + total_size_of_headers;
|
2023-08-22 19:32:25 +02:00
|
|
|
header_extension.current_packet_number = 1;
|
2023-08-23 17:16:13 +02:00
|
|
|
header_extension.packet_size = Size + total_size_of_headers;
|
2023-08-22 19:32:25 +02:00
|
|
|
|
|
|
|
memcpy( PVOID( ( UINT64 )this->send_buffer + sizeof( global::headers::PIPE_PACKET_HEADER ) ),
|
|
|
|
&header_extension, sizeof( global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER ) );
|
|
|
|
|
|
|
|
this->pipe->WriteToPipe( this->send_buffer, header_extension.packet_size );
|
2023-08-18 16:34:15 +02:00
|
|
|
}
|
2023-08-22 19:32:25 +02:00
|
|
|
|
|
|
|
RtlZeroMemory( this->send_buffer, SEND_BUFFER_SIZE );
|
|
|
|
mutex.unlock();
|
2023-08-18 16:34:15 +02:00
|
|
|
}
|