소스 검색

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) {
+    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);
 }
 
 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;
     if (write_queue_empty(&io->write_queue)) {
 try_write: