1
0
hewei.it 4 жил өмнө
parent
commit
39904fca8f
2 өөрчлөгдсөн 14 нэмэгдсэн , 11 устгасан
  1. 2 6
      event/hevent.c
  2. 12 5
      event/nio.c

+ 2 - 6
event/hevent.c

@@ -297,15 +297,11 @@ void hio_read_cb(hio_t* io, void* buf, int len) {
         // printd("read_cb======\n");
     }
 
+    // for readbuf autosize
     if (hio_is_alloced_readbuf(io) && io->readbuf.len > READ_BUFSIZE_HIGH_WATER) {
-        // readbuf autosize
         size_t small_size = io->readbuf.len / 2;
         if (len < small_size) {
-            if (++io->small_readbytes_cnt == 3) {
-                io->small_readbytes_cnt = 0;
-                io->readbuf.base = (char*)safe_realloc(io->readbuf.base, small_size, io->readbuf.len);
-                io->readbuf.len = small_size;
-            }
+            ++io->small_readbytes_cnt;
         }
     }
 }

+ 12 - 5
event/nio.c

@@ -50,14 +50,21 @@ static void __read_cb(hio_t* io, void* buf, int readbytes) {
 
     if (io->unpack_setting) {
         hio_unpack(io, buf, readbytes);
-        return;
-    }
+    } else {
+        if (io->read_once) {
+            hio_read_stop(io);
+        }
 
-    if (io->read_once) {
-        hio_read_stop(io);
+        hio_read_cb(io, buf, readbytes);
     }
 
-    hio_read_cb(io, buf, readbytes);
+    // readbuf autosize
+    if (io->small_readbytes_cnt >= 3) {
+        io->small_readbytes_cnt = 0;
+        size_t small_size = io->readbuf.len / 2;
+        io->readbuf.base = (char*)safe_realloc(io->readbuf.base, small_size, io->readbuf.len);
+        io->readbuf.len = small_size;
+    }
 }
 
 static void __write_cb(hio_t* io, const void* buf, int writebytes) {