浏览代码

hio_read hio_write safe check

ithewei 5 年之前
父节点
当前提交
dd0a1b64b4
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      event/nio.c

+ 8 - 0
event/nio.c

@@ -490,10 +490,18 @@ int hio_connect(hio_t* io) {
 }
 }
 
 
 int hio_read (hio_t* io) {
 int hio_read (hio_t* io) {
+    if (io->closed) {
+        hloge("hio_read called but fd[%d] already closed!", io->fd);
+        return -1;
+    }
     return hio_add(io, hio_handle_events, HV_READ);
     return hio_add(io, hio_handle_events, HV_READ);
 }
 }
 
 
 int hio_write (hio_t* io, const void* buf, size_t len) {
 int hio_write (hio_t* io, const void* buf, size_t len) {
+    if (io->closed) {
+        hloge("hio_write called but fd[%d] already closed!", io->fd);
+        return -1;
+    }
     int nwrite = 0;
     int nwrite = 0;
     if (write_queue_empty(&io->write_queue)) {
     if (write_queue_empty(&io->write_queue)) {
 try_write:
 try_write: