-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
56 lines (46 loc) · 1.42 KB
/
main.c
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
#include "./include/header.h"
#include "./include/hashTable.h"
#include "./include/hashUvData.h"
#include "./include/hashData.h"
#include "./include/hashDb.h"
HashNode rnode;
uv_fs_t req1;
uv_file myfile;
void read_callback(uv_fs_t *req);
void write_callback(uv_fs_t *req){
int result = req->result;
printf("%d\n",result);
uv_fs_req_cleanup(req);
asyncFindOneHashNode(req,&rnode,myfile,read_callback);
}
void read_callback(uv_fs_t *req){
if (req->result < 0) {
fprintf(stderr, "Read error: %s\n", uv_strerror(req->result));
}
printf("%s\n",rnode.value);
}
void open_callback(uv_fs_t *req){
printf("test\n");
char *key = (char *)malloc(MAX_KEY_BYTE*BYTE_SIZE);
char *value = (char *)malloc(MAX_VALUE_BYTE*BYTE_SIZE);
strcpy(key,"name");
strcpy(value,"munongmunong");
myfile = req->result;
uv_fs_req_cleanup(req);
asyncSaveOneKeyValue(req,key,value,myfile,write_callback);
}
int main(int argc, char **argv) {
rnode.key = (char *)malloc(MAX_KEY_BYTE*BYTE_SIZE);
rnode.value = (char *)malloc(MAX_VALUE_BYTE*BYTE_SIZE);
rnode.key = "haha";
uv_fs_t req;
asyncOpenHashFile(&req,"./data/data.db",open_callback);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
char *test = (char *)malloc(MAX_VALUE_BYTE*BYTE_SIZE);
char *key = (char *)malloc(MAX_KEY_BYTE*BYTE_SIZE);
key = "name";
HashData *data = openHashFile("./data/data.db");
findOneKeyValue(data,key,test);
printf("%s\n",test);
return 0;
}