Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Luckydog691 committed May 10, 2020
1 parent e07c78f commit 941c408
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/src/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int Client::read_path(const char* path, char* path_info_buf, char** file_info_bu
#ifdef WIN32
intptr_t handle;
_finddata_t findData;
char* dir = new char[1000];
char* dir = new char[2000];
strcpy(dir, path);
dir = strcat(dir, "/*.*");
handle = _findfirst(dir, &findData);
Expand Down Expand Up @@ -316,32 +316,32 @@ int Client::read_path(const char* path, char* path_info_buf, char** file_info_bu

bool Client::send_path_info(char* buffer)
{
delete(buffer);
buffer = new char[3];
buffer[0] = 't'; buffer[1] = '\0';
if(strlen(buffer))
{
int p = strlen(buffer);
char info[6] = "INFO";
send_cmd(info);
int port = -1;
port = get_port();
if(port == -1) return false;

if (strlen(buffer) > MAX_PACKET_DATA_BYTE_LENGTH)
if (p > MAX_PACKET_DATA_BYTE_LENGTH)
{
for (int i = 0; i < strlen(buffer) / MAX_PACKET_DATA_BYTE_LENGTH + 1; i++)
for (int i = 0; i < p / MAX_PACKET_DATA_BYTE_LENGTH + 1; i++)
{
char* paths = new char[MAX_PACKET_DATA_BYTE_LENGTH];
for (int j = 0; j < MAX_PACKET_DATA_BYTE_LENGTH; j++)
{
paths[j] = buffer[i * MAX_PACKET_DATA_BYTE_LENGTH + j];
}
for(int k=0;k< SEND_FREQ;k++)
{
int res = send(cmd_sock, paths, strlen(paths) + UPD_HEADER_LENGTH, 0);
//UNCOMPLETED!!!Need to determine whether the return is "info"
if (res != -1)
{
return true;
}
}
std::cout << "Transmission failed, retransmission limit reached" << std::endl;
return false;
}
Expand All @@ -362,7 +362,6 @@ bool Client::send_path_info(char* buffer)
//recvfrom(cmd_sock, ret, 64, 0, (struct sockaddr*) & serv_addr_cmd, &nSize);
recv_cmd(ret, 64, 5000);
return !strcmp(ret, "INFO");

}
}
else
Expand Down
8 changes: 4 additions & 4 deletions src/src/Client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ bool start_send(Client*& client, const char* file_path, bool dir_flag)
client->set_data_port();
if(dir_flag)
{
char* file_info[1000];
for (int i = 0; i < 1000; i++)
char* file_info[2000];
for (int i = 0; i < 2000; i++)
{
file_info[i] = new char[1000];
memset(file_info[i], 0, 1000);
file_info[i] = new char[2000];
memset(file_info[i], 0, 2000);
}
char* path_info = new char[10000];
memset(path_info, 0, 10000 * sizeof(char));
Expand Down
6 changes: 3 additions & 3 deletions src/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ int Server::set_dir(char* path)

bool Server::parse_path()
{
char buf[1000];
char buf[1050];
char* r_cmd = new char[4];
memset(r_cmd, 0, 4);
memset(buf, 0, 1000);
memset(buf, 0, 1050);

#ifdef __linux__
socklen_t nSize = sizeof(sockaddr);
Expand All @@ -349,7 +349,7 @@ bool Server::parse_path()
int nSize = sizeof(sockaddr);
#endif

recv(client_sock, buf, 1000 * sizeof(char), 0);
recv(client_sock, buf, 1050 * sizeof(char), 0);

/*int pos = 0;
while(pos < strlen(buf))
Expand Down

0 comments on commit 941c408

Please sign in to comment.