瀏覽代碼

#define hio_write_queue_is_empty

ithewei 4 年之前
父節點
當前提交
c2c6cd7335
共有 3 個文件被更改,包括 10 次插入9 次删除
  1. 2 3
      event/hevent.c
  2. 7 4
      event/hloop.h
  3. 1 2
      event/nio.c

+ 2 - 3
event/hevent.c

@@ -243,8 +243,8 @@ void* hio_context(hio_t* io) {
     return io->ctx;
 }
 
-size_t hio_read_bufsize(hio_t* io) {
-    return io->readbuf.len;
+hio_readbuf_t* hio_get_readbuf(hio_t* io) {
+    return &io->readbuf;
 }
 
 size_t hio_write_bufsize(hio_t* io) {
@@ -342,7 +342,6 @@ void hio_handle_read(hio_t* io, void* buf, int readbytes) {
                 if (io->readbuf.head == io->readbuf.tail) {
                     io->readbuf.head = io->readbuf.tail = 0;
                 }
-                io->readbuf.head = io->readbuf.tail = 0;
                 io->read_flags &= ~HIO_READ_UNTIL_LENGTH;
                 hio_read_cb(io, (void*)sp, io->read_until_length);
             }

+ 7 - 4
event/hloop.h

@@ -257,10 +257,13 @@ HV_EXPORT void hio_set_context(hio_t* io, void* ctx);
 HV_EXPORT void* hio_context(hio_t* io);
 HV_EXPORT bool hio_is_opened(hio_t* io);
 HV_EXPORT bool hio_is_closed(hio_t* io);
-HV_EXPORT size_t hio_read_bufsize(hio_t* io);
-HV_EXPORT size_t hio_write_bufsize(hio_t* io);
-HV_EXPORT uint64_t hio_last_read_time(hio_t* io); // ms
-HV_EXPORT uint64_t hio_last_write_time(hio_t* io); // ms
+// #include "hbuf.h"
+typedef struct fifo_buf_s hio_readbuf_t;
+HV_EXPORT hio_readbuf_t* hio_get_readbuf(hio_t* io);
+HV_EXPORT size_t   hio_write_bufsize(hio_t* io);
+#define hio_write_queue_is_empty(io) (hio_write_bufsize(io) == 0)
+HV_EXPORT uint64_t hio_last_read_time(hio_t* io);   // ms
+HV_EXPORT uint64_t hio_last_write_time(hio_t* io);  // ms
 
 // set callbacks
 HV_EXPORT void hio_setcb_accept   (hio_t* io, haccept_cb  accept_cb);

+ 1 - 2
event/nio.c

@@ -460,8 +460,7 @@ enqueue:
         if (io->write_bufsize + len - nwrite > MAX_WRITE_BUFSIZE) {
             if (io->write_bufsize > MAX_WRITE_BUFSIZE) {
                 hloge("write bufsize > %u, close it!", (unsigned int)MAX_WRITE_BUFSIZE);
-                hio_close_async(io);
-                return -1;
+                goto write_error;
             }
         }
         offset_buf_t remain;