mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-16 08:20:29 +08:00
update README
This commit is contained in:
18
server.c
18
server.c
@@ -138,10 +138,10 @@ static int send_all(THREADTIMER *timer) {
|
||||
char* buf = (char*)malloc(file_size);
|
||||
if(buf) {
|
||||
if(fread(buf, file_size, 1, fp) == 1) {
|
||||
printf("Get dict file size: %zu\n", file_size);
|
||||
//printf("Get dict file size: %zu\n", file_size);
|
||||
char* encbuf = raw_encrypt(buf, &file_size, timer->index, cfg->pwd);
|
||||
sprintf(timer->dat, "%zu$", file_size);
|
||||
printf("Get encrypted file size: %s\n", timer->dat);
|
||||
//printf("Get encrypted file size: %s\n", timer->dat);
|
||||
//FILE* fp = fopen("raw_after_enc", "wb+");
|
||||
//fwrite(encbuf, file_size, 1, fp);
|
||||
//fclose(fp);
|
||||
@@ -198,7 +198,7 @@ static int s2_set(THREADTIMER *timer) {
|
||||
static int s3_set_data(THREADTIMER *timer) {
|
||||
//timer->status = 0;
|
||||
uint32_t datasize = (timer->numbytes > (DICTDATSZ-1))?(DICTDATSZ-1):timer->numbytes;
|
||||
printf("Set data size: %u\n", datasize);
|
||||
//printf("Set data size: %u\n", datasize);
|
||||
memcpy(d.data, timer->dat, datasize);
|
||||
puts("Data copy to dict succ");
|
||||
if(!set_pb(get_dict_fp(timer->index), items_len, sizeof(DICT), &d)) {
|
||||
@@ -234,7 +234,7 @@ static int s4_del(THREADTIMER *timer) {
|
||||
}
|
||||
} else {
|
||||
uint32_t cap = end - next;
|
||||
printf("this: %u, next: %u, end: %u, cap: %u\n", this, next, end, cap);
|
||||
//printf("this: %u, next: %u, end: %u, cap: %u\n", this, next, end, cap);
|
||||
char* data = malloc(cap);
|
||||
if(data) {
|
||||
fseek(fp, next, SEEK_SET);
|
||||
@@ -342,19 +342,19 @@ static void handle_accept(void *p) {
|
||||
) {
|
||||
touch_timer(p);
|
||||
offset += numbytes;
|
||||
printf("[handle] Get %zd bytes, total: %zd.\n", numbytes, offset);
|
||||
//printf("[handle] Get %zd bytes, total: %zd.\n", numbytes, offset);
|
||||
if(offset < CMDPACKET_HEAD_LEN) break;
|
||||
if(offset < CMDPACKET_HEAD_LEN+cp->datalen) {
|
||||
numbytes = recv(accept_fd, buff+offset, CMDPACKET_HEAD_LEN+cp->datalen-offset, MSG_WAITALL);
|
||||
if(numbytes <= 0) break;
|
||||
else {
|
||||
offset += numbytes;
|
||||
printf("[handle] Get %zd bytes, total: %zd.\n", numbytes, offset);
|
||||
//printf("[handle] Get %zd bytes, total: %zd.\n", numbytes, offset);
|
||||
}
|
||||
}
|
||||
numbytes = CMDPACKET_HEAD_LEN+cp->datalen; // 暂存 packet len
|
||||
if(offset < numbytes) break;
|
||||
printf("[handle] Decrypt %zd bytes data...\n", cp->datalen);
|
||||
//printf("[handle] Decrypt %zd bytes data...\n", cp->datalen);
|
||||
if(cp->cmd < 5 && cmdpacket_decrypt(cp, index, cfg->pwd)) {
|
||||
cp->data[cp->datalen] = 0;
|
||||
timer_pointer_of(p)->dat = (char*)cp->data;
|
||||
@@ -406,7 +406,7 @@ static void handle_accept(void *p) {
|
||||
memmove(buff, buff+numbytes, offset);
|
||||
numbytes = 0;
|
||||
} else offset = 0;
|
||||
printf("Offset after analyzing packet: %zd\n", offset);
|
||||
//printf("Offset after analyzing packet: %zd\n", offset);
|
||||
}
|
||||
CONV_END: puts("Conversation end\n");
|
||||
} else puts("Error allocating buffer");
|
||||
@@ -458,7 +458,7 @@ static void accept_client() {
|
||||
timer->touch = time(NULL);
|
||||
timer->ptr = NULL;
|
||||
reset_seq(p);
|
||||
puts("Reset seq succeed");
|
||||
//puts("Reset seq succeed");
|
||||
if (pthread_create(accept_threads + p, &attr, (void *)&handle_accept, timer)) puts("Error creating thread");
|
||||
else puts("Creating thread succeeded");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user