Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxiaoquan233 committed Apr 21, 2020
2 parents 325e16e + fa38d31 commit da6f1bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/include/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <io.h>
#include <direct.h>
#include <winsock.h>
#include <windows.h>
#pragma comment (lib, "ws2_32.lib")
#endif

Expand Down
18 changes: 9 additions & 9 deletions src/src/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ int Client::recv_cmd(char* buf, int len, int usec)
struct timeval timeout;
timeout.tv_sec = usec / 1000;
timeout.tv_usec = usec % 1000;
if (setsockopt(cmd_sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
if (setsockopt(cmd_sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) == -1) {
perror("setsockopt failed:");
}

int res = recvfrom(cmd_sock, buf, len, 0, (struct sockaddr*) & serv_addr_cmd, &nSize);
return res;
}

int Client::send_file(const char* input_file_name, int path_offs)
Expand Down Expand Up @@ -111,17 +112,17 @@ bool Client::sock_init(SOCKET* sock, int port, int is_cmd)
bool Client::sock_init(int* sock, int port, int is_cmd)
#endif
{
#ifdef _WIN32
#ifdef _WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
*sock = socket(AF_INET, SOCK_DGRAM, 0);
#endif
#endif

#ifdef __linux__
*sock = socket(AF_INET, SOCK_DGRAM, 0);
#endif
#ifdef __linux__
* sock = socket(AF_INET, SOCK_DGRAM, 0);
#endif

if(is_cmd)
if (is_cmd)
{
memset(&serv_addr_cmd, 0, sizeof(serv_addr_cmd));
serv_addr_cmd.sin_family = AF_INET;
Expand All @@ -145,7 +146,7 @@ bool Client::set_port(SOCKET* sock, int port,int is_cmd)
bool Client::set_port(int* sock, int port, int is_cmd)
#endif
{
if(is_cmd)
if (is_cmd)
{
serv_addr_cmd.sin_port = htons(port);
/*if (bind(*sock, (struct sockaddr*) & serv_addr_cmd, sizeof(sockaddr)) == -1)
Expand All @@ -163,7 +164,6 @@ bool Client::set_port(int* sock, int port, int is_cmd)
}
return true;
}

bool Client::send_packet(int len)
{
int on=1;
Expand Down
3 changes: 1 addition & 2 deletions src/src/Client/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../interface/mainwindow.h"
#include "../../interface/mainwindow.h"
#include <QApplication>
#include "../interface/mainwindow.h"
#include "../../include/Client/Client.h"

bool parse_arg(int argc, char** argv, char** file_path, char** ip_addr, int* port)
Expand Down
36 changes: 18 additions & 18 deletions src/src/Server/Server.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "../../include/Server/Server.h"

Server::Server(int port)
{
cmd_port = port;
Expand Down Expand Up @@ -78,7 +77,7 @@ bool Server::check_port()
//�˿��ѱ�ռ��
//printf("ռ��");
start_port++;
memset(&serv_addr2, 0, sizeof(serv_addr2));
memset(&serv_addr_data, 0, sizeof(serv_addr_data));
serv_addr_data.sin_family = AF_INET;
serv_addr_data.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr_data.sin_port = htons(start_port);
Expand Down Expand Up @@ -515,7 +514,7 @@ bool Server::check_file(char* file_name, int file_len, int pkt_num)
loaded_pack_num[temp] = true;
}
int need_send = total_packet_num - total_loaded_pack_num;
int need_send_num[need_send];
int *need_send_num = new int[need_send];
for (int i = 0, j = 0; i < total_packet_num; i++)
{
if (loaded_pack_num[i] == false)
Expand All @@ -532,6 +531,7 @@ bool Server::check_file(char* file_name, int file_len, int pkt_num)
if(sendto(cmd_sock, offset, strlen(offset), 0,(struct sockaddr*) & serv_addr_cmd, sizeof(serv_addr_cmd))<0)
perror("offset");
fclose(logfile);
delete(need_send_num);
return true;
}
}
Expand All @@ -547,26 +547,26 @@ void mergeFile(char* fileaddress, int package)
int filelen = strlen(fileaddress);

char* buffaddress;
if ((buffaddress = (char*)malloc(sizeof(char) * (filelen + 5))) == NULL)
puts("memory not available"), pthread_exit(NULL);
if ((buffaddress = (char*)malloc(sizeof(char) * (filelen + 5))) == NULL)
{
puts("memory not available"); return;
}

FILE* dst, * src;

//for debug
puts(fileaddress);

if ((dst = fopen(fileaddress, "wb")) == NULL)
puts("cannot create file"), pthread_exit(NULL);
for (int i = 1; i <= package; i++)
if ((dst = fopen(fileaddress, "wb")) == NULL)
{
puts("cannot create file"); return;
}
for (int i = 1; i <= package; i++)
{
sprintf(buffaddress, "%s.%03d", fileaddress, i);
if ((src = fopen(buffaddress, "rb")) == NULL)
{
puts("file not exists"); return;
}
char sub;

//for debug
puts(buffaddress);

if ((src = fopen(buffaddress, "rb")) == NULL)
puts("file not exists"), pthread_exit(NULL);
char sub;
while (!feof(src))
{
sub = fgetc(src);
Expand All @@ -576,7 +576,7 @@ void mergeFile(char* fileaddress, int package)
remove(buffaddress);
}
fclose(dst);
pthread_exit(NULL);
return;
}

int Server::get_ack(char* data)
Expand Down

0 comments on commit da6f1bd

Please sign in to comment.