mirror of
https://github.com/fumiama/simple-dict.git
synced 2026-06-12 22:40:50 +08:00
fix: 错误交互
This commit is contained in:
@@ -31,7 +31,7 @@ Start server on localhost using the commands below.
|
|||||||
```bash
|
```bash
|
||||||
chmod +x simple-dict-server simple-dict-client
|
chmod +x simple-dict-server simple-dict-client
|
||||||
Usage:
|
Usage:
|
||||||
./simple-dict-server [-d] listen_port dict_file [config_file | -]
|
./simple-dict-server [-d] listen_port dict_file [ config_file | - ]
|
||||||
-d: As daemon
|
-d: As daemon
|
||||||
- : Read config from env SDS_PWD & SDS_SPS
|
- : Read config from env SDS_PWD & SDS_SPS
|
||||||
```
|
```
|
||||||
@@ -41,7 +41,7 @@ Open another shell to connect to it.
|
|||||||
```bash
|
```bash
|
||||||
./simple-dict-client 127.0.0.1 7777
|
./simple-dict-client 127.0.0.1 7777
|
||||||
```
|
```
|
||||||
Now you have connected to the server. The default access passwords is in `client.c` and you can modify the password in source code as you like. Please note that the server will only wait `4` seconds for a response after the last communication. The box below shows how to control the server to accompilsh basic add/del/find/edit operations.
|
Now you have connected to the server. The default access passwords is in `client.c` and you can modify the password in source code as you like. Please note that the server will only wait `4` seconds for a response after the last communication. You can go to `server.h` to edit this limit. The box below shows how to control the server to accompilsh basic add/del/find/edit operations.
|
||||||
|
|
||||||
| cmd | data | description | reply |
|
| cmd | data | description | reply |
|
||||||
| ---- | ---- | ---- | ----- |
|
| ---- | ---- | ---- | ----- |
|
||||||
|
|||||||
4
server.c
4
server.c
@@ -330,6 +330,7 @@ ERR_INSERT_ITEM:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int s3_set_data(thread_timer_t *timer) {
|
static int s3_set_data(thread_timer_t *timer) {
|
||||||
|
if(!setdicts[timer->index].data[0]) return send_data(timer->accept_fd, timer->index, ACKERRO, "erro", 4);
|
||||||
FILE *fp = open_ex_dict();
|
FILE *fp = open_ex_dict();
|
||||||
if(fp == NULL) return send_data(timer->accept_fd, timer->index, ACKERRO, "erro", 4);
|
if(fp == NULL) return send_data(timer->accept_fd, timer->index, ACKERRO, "erro", 4);
|
||||||
|
|
||||||
@@ -378,6 +379,8 @@ static int s3_set_data(thread_timer_t *timer) {
|
|||||||
r = send_data(timer->accept_fd, timer->index, ACKSUCC, "succ", 4);
|
r = send_data(timer->accept_fd, timer->index, ACKSUCC, "succ", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setdicts[timer->index].data[0] = 0;
|
||||||
|
|
||||||
pthread_cleanup_pop(1);
|
pthread_cleanup_pop(1);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -523,6 +526,7 @@ static void cleanup_thread(thread_timer_t* timer) {
|
|||||||
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
||||||
puts("Start cleaning");
|
puts("Start cleaning");
|
||||||
timer->thread = 0;
|
timer->thread = 0;
|
||||||
|
setdicts[timer->index].data[0] = 0;
|
||||||
if(timer->accept_fd) {
|
if(timer->accept_fd) {
|
||||||
close(timer->accept_fd);
|
close(timer->accept_fd);
|
||||||
timer->accept_fd = 0;
|
timer->accept_fd = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user