1
0
ithewei 6 жил өмнө
parent
commit
f9bf2ad2cd

+ 2 - 1
event/hloop.c

@@ -119,6 +119,7 @@ static int hloop_process_events(hloop_t* loop) {
     int nios, ntimers, nidles;
     nios = ntimers = nidles = 0;
 
+    // calc blocktime
     int32_t blocktime = MAX_BLOCK_TIME;
     hloop_update_time(loop);
     if (loop->timers.root) {
@@ -167,7 +168,7 @@ int hloop_init(hloop_t* loop) {
     //io_array_init(&loop->ios, IO_ARRAY_INIT_SIZE);
     // iowatcher: init when iowatcher_add_event
     //iowatcher_init(loop);
-    // time
+    // NOTE: init start_time here, because htimer_add use it.
     time(&loop->start_time);
     loop->start_hrtime = loop->cur_hrtime = gethrtime();
     return 0;

+ 1 - 0
event/hloop.h

@@ -188,6 +188,7 @@ struct hloop_s {
 // loop
 int hloop_init(hloop_t* loop);
 //void hloop_cleanup(hloop_t* loop);
+// NOTE: when no active events, loop will quit.
 int hloop_run(hloop_t* loop);
 int hloop_stop(hloop_t* loop);
 int hloop_pause(hloop_t* loop);

+ 12 - 8
http/server/FileCache.h

@@ -98,16 +98,20 @@ public:
             if (fc == NULL) {
                 struct stat st;
                 fstat(fd, &st);
-                if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode)) {
+                if (S_ISREG(st.st_mode) ||
+                    (S_ISDIR(st.st_mode) &&
+                     filepath[strlen(filepath)-1] == '/')) {
+                    fc = new file_cache_t;
+                    //fc->filepath = filepath;
+                    fc->st = st;
+                    time(&fc->open_time);
+                    fc->stat_time = fc->open_time;
+                    fc->stat_cnt = 1;
+                    cached_files[filepath] = fc;
+                }
+                else {
                     return NULL;
                 }
-                fc = new file_cache_t;
-                //fc->filepath = filepath;
-                fc->st = st;
-                time(&fc->open_time);
-                fc->stat_time = fc->open_time;
-                fc->stat_cnt = 1;
-                cached_files[filepath] = fc;
             }
             if (S_ISREG(fc->st.st_mode)) {
                 // FILE