Open ixqbar opened 9 years ago
static void yar_server_on_accept(int fd, short ev, void *arg) /* {{{ */ {
int client_fd;
struct sockaddr_in client_addr;
socklen_t client_len = sizeof(struct sockaddr_in);
yar_request_context *ctx;
client_fd = accept(fd, (struct sockaddr *)&client_addr, &client_len);
if (client_fd == -1) {
return;
}
ctx = calloc(1, sizeof(yar_request_context) + sizeof(yar_request) + sizeof(yar_response));
//这里应该是yar_set_non_blocking(client_fd)
if (!yar_set_non_blocking(fd)) {
alog(YAR_WARNING, "Setting non-block mode failed '%s'", strerror(errno));
free(ctx);
close(client_fd);
return;
}
...
static int yar_check_previous_run(char *pfile) /* {{{ */ {
FILE *fp;
if (access(pfile, F_OK) == 0) {
alog(YAR_ERROR, "There is already a yar_sever run, pid '%s'", pfile);
return 0;
}
//检查完就写入当前进程pid感觉不太适合,后面的fork也导致了父进程的退出,导致该pid毫无意义
fp = fopen(pfile, "w+");
if (!fp) {
alog(YAR_ERROR, "Failed to write pid file '%s'", strerror(errno));
return 0;
}
fprintf(fp, "%d", getpid());
fclose(fp);
return 1;
} /* }}} */
你要不然提交个PR过来? 直接修改好的.
yar_pack_push_string(packager, "data", 5); 应该为 yar_pack_push_string(packager, "data", 4);