-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.h
48 lines (41 loc) · 1.32 KB
/
Util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by shahrooz on 10/3/21.
//
#ifndef SHORRENT__UTIL_H_
#define SHORRENT__UTIL_H_
#include <cstdint>
#include <unistd.h>
#include <cstdio>
#include <sys/socket.h>
#include <cstdlib>
#include <netinet/in.h>
#include <string>
#include <vector>
#include <arpa/inet.h>
#include <dirent.h>
#include <sys/types.h>
#define CHUNK_DEFAULT_SIZE (1024 * 1024)
#define SERVER_IP INADDR_ANY
#define SERVER_PORT 8080
#define BACKLOG_SIZE 1024
#define FILES_PATH "files/"
#define CHUNKS_PATH "chunks/"
#define MAX_NUM_OF_THREADS 8
#define PROGRESS_BAR_WIDTH 70
#define DPRINTF(flag, fmt, ...) \
do{ \
if(flag) \
fprintf(stdout, "Time %10li - Thread: %lu : [%s][%s]%d: " fmt, time(nullptr), pthread_self(), __FILE__, __func__, __LINE__, ##__VA_ARGS__); \
fflush(stdout); \
} while(0)
int recvData(int sock, std::string& data);
int sendData(int sock, const std::string& data);
// File operations.
void listDir(const std::string& path, std::vector<std::string>& files);
void listDir2(const std::string& path, std::vector<std::string>& files);
uint32_t fileSize(const std::string& path);
bool fileExist(const std::string& path);
bool isDir(const std::string &path);
int copyDir(const std::string &src, const std::string &dest);
int copyFile(const std::string &src, const std::string &dest);
#endif //SHORRENT__UTIL_H_