-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisk_task.h
More file actions
114 lines (108 loc) · 2.24 KB
/
disk_task.h
File metadata and controls
114 lines (108 loc) · 2.24 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef _DISK_TASK_H_
#define _DISK_TASK_H_
namespace ftp_server
{
class disk_task
{
private:
int ctrl_fd;
int action;
char cur_path[PATHSIZE]; // 用户当前目录
long rest_size; // 续传位置(-1文件尾,0不变,正整数,偏移位置)
char* file_buffer;
int buf_len;
public:
disk_task(int new_ctrl_fd, int new_action)
{
ctrl_fd = new_ctrl_fd;
action = new_action;
rest_size = 0;
file_buffer = NULL;
buf_len = 0;
};
disk_task(int new_ctrl_fd, int new_action, char* new_path)
{
ctrl_fd = new_ctrl_fd;
action = new_action;
strncpy(cur_path, new_path, PATHSIZE);
rest_size = 0;
file_buffer = NULL;
buf_len = 0;
};
disk_task(int new_ctrl_fd, int new_action, char* new_path, long offset)
{
ctrl_fd = new_ctrl_fd;
action = new_action;
strncpy(cur_path, new_path, PATHSIZE);
rest_size = offset;
file_buffer = NULL;
buf_len = 0;
};
~disk_task()
{
if(file_buffer != NULL)
{
delete[] file_buffer;
file_buffer = NULL;
}
};
int get_ctrl_fd()
{
return ctrl_fd;
};
int get_action()
{
return action;
};
void set_action(int new_action)
{
action = new_action;
};
char* get_cur_path()
{
return cur_path;
};
void set_cur_path(char* new_path)
{
strncpy(cur_path, new_path, PATHSIZE);
};
int cmp_path(char *buf)
{
return strncasecmp(cur_path, buf, PATHSIZE);
};
int get_rest_size()
{
return rest_size;
};
void set_rest_size(int new_rest_size)
{
rest_size = new_rest_size;
};
char* get_file_buffer()
{
return file_buffer;
};
int get_buf_len()
{
return buf_len;
};
void set_new_file_buffer(char* new_file_buffer, int new_buf_len)
{
if(file_buffer != NULL)
{
exit(1);
}
file_buffer = new char[FILEBUFSIZE];
memset(file_buffer, 0, FILEBUFSIZE);
memcpy(file_buffer, new_file_buffer, new_buf_len);
buf_len = new_buf_len;
};
/* void set_file_buffer(char* new_file_buffer, int new_buf_len)
{
memset(file_buffer, 0, FILEBUFSIZE);
memcpy(file_buffer, new_file_buffer, new_buf_len);
buf_len = new_buf_len;
};
*/ };
}
#endif /* _DISK_TASK_H_ */