已有数据同步功能完成

This commit is contained in:
1iaan
2026-01-29 10:47:24 +00:00
parent fe257cafec
commit 2bdb48d63d
27 changed files with 1134 additions and 139 deletions

View File

@@ -104,7 +104,7 @@ int event_register(int fd, int event) {
memset(conn_list[fd].wbuffer, 0, BUFFER_LENGTH*2);
conn_list[fd].wlength = 0;
conn_list[fd].is_from_master = 0;
conn_list[fd].is_stop = 0;
set_event(fd, event, 1);
}
@@ -147,24 +147,24 @@ int recv_cb(int fd) {
// printf("avail: %d\n", avail);
if (avail <= 0) {
// 缓冲满了还没解析出来:协议异常或包过大
close(fd);
epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
close(fd);
return 0;
}
int count = recv(fd, c->rbuffer + c->rlength, avail, 0);
if (count == 0) { // disconnect
//printf("client disconnect: %d\n", fd);
close(fd);
epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL); // unfinished
close(fd);
return 0;
} else if (count < 0) { //
printf("count: %d, errno: %d, %s\n", count, errno, strerror(errno));
close(fd);
epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
close(fd);
return 0;
}
@@ -191,8 +191,8 @@ int recv_cb(int fd) {
#elif ENABLE_KVSTORE
int consumed = kvs_request(c);
if(consumed < 0){
close(fd);
epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
close(fd);
return 0;
}
@@ -274,8 +274,8 @@ int send_cb(int fd) {
pthread_mutex_unlock(&c->g_sync_lock);
printf("send fd=%d errno=%d %s\n", fd, e, strerror(e));
close(fd);
epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
close(fd);
return 0;
}
@@ -372,7 +372,7 @@ int reactor_start(unsigned short port, msg_handler handler) {
conn_list[sockfd].fd = sockfd;
conn_list[sockfd].r_action.recv_callback = accept_cb;
conn_list[sockfd].is_from_master = 0;
conn_list[sockfd].is_stop = 0;
set_event(sockfd, EPOLLIN, 1);
}