ithewei 4 년 전
부모
커밋
67be7ec4b2
2개의 변경된 파일7개의 추가작업 그리고 13개의 파일을 삭제
  1. 4 10
      cpputil/hmain.cpp
  2. 3 3
      http/server/HttpServer.cpp

+ 4 - 10
cpputil/hmain.cpp

@@ -306,13 +306,7 @@ int create_pidfile() {
     }
 
     g_main_ctx.pid = hv_getpid();
-    char pid[16] = {0};
-    int len = snprintf(pid, sizeof(pid), "%d\n", g_main_ctx.pid);
-    int nwrite = fwrite(pid, 1, len, fp);
-    if (nwrite != len) {
-        fprintf(stderr, "fwrite failed!\n");
-        exit(-1);
-    }
+    fprintf(fp, "%d\n", (int)g_main_ctx.pid);
     fclose(fp);
     hlogi("create_pidfile('%s') pid=%d", g_main_ctx.pidfile, g_main_ctx.pid);
     atexit(delete_pidfile);
@@ -330,10 +324,10 @@ pid_t getpid_from_pidfile() {
         // hloge("fopen('%s') error: %d", g_main_ctx.pidfile, errno);
         return -1;
     }
-    char pid[64];
-    int readbytes = fread(pid, 1, sizeof(pid), fp);
+    int pid = -1;
+    fscanf(fp, "%d", &pid);
     fclose(fp);
-    return readbytes <= 0 ? -1 : atoi(pid);
+    return pid;
 }
 
 #ifdef OS_UNIX

+ 3 - 3
http/server/HttpServer.cpp

@@ -362,6 +362,9 @@ int http_server_run(http_server_t* server, int wait) {
 }
 
 int http_server_stop(http_server_t* server) {
+    HttpServerPrivdata* privdata = (HttpServerPrivdata*)server->privdata;
+    if (privdata == NULL) return 0;
+
 #ifdef OS_UNIX
     if (server->worker_processes) {
         signal_handle("stop");
@@ -369,9 +372,6 @@ int http_server_stop(http_server_t* server) {
     }
 #endif
 
-    HttpServerPrivdata* privdata = (HttpServerPrivdata*)server->privdata;
-    if (privdata == NULL) return 0;
-
     // wait for all threads started and all loops running
     while (1) {
         hv_delay(1);