소스 검색

fix #142: return NULL if hio_connect fail directly

ithewei 3 년 전
부모
커밋
cc23f3b0d6
2개의 변경된 파일7개의 추가작업 그리고 8개의 파일을 삭제
  1. 6 6
      event/hloop.c
  2. 1 2
      event/nio.c

+ 6 - 6
event/hloop.c

@@ -806,7 +806,7 @@ hio_t* haccept(hloop_t* loop, int listenfd, haccept_cb accept_cb) {
     if (accept_cb) {
         io->accept_cb = accept_cb;
     }
-    hio_accept(io);
+    if (hio_accept(io) != 0) return NULL;
     return io;
 }
 
@@ -816,7 +816,7 @@ hio_t* hconnect (hloop_t* loop, int connfd, hconnect_cb connect_cb) {
     if (connect_cb) {
         io->connect_cb = connect_cb;
     }
-    hio_connect(io);
+    if (hio_connect(io) != 0) return NULL;
     return io;
 }
 
@@ -929,7 +929,7 @@ hio_t* hloop_create_tcp_server (hloop_t* loop, const char* host, int port, hacce
     hio_t* io = hio_create_socket(loop, host, port, HIO_TYPE_TCP, HIO_SERVER_SIDE);
     if (io == NULL) return NULL;
     hio_setcb_accept(io, accept_cb);
-    hio_accept(io);
+    if (hio_accept(io) != 0) return NULL;
     return io;
 }
 
@@ -937,7 +937,7 @@ hio_t* hloop_create_tcp_client (hloop_t* loop, const char* host, int port, hconn
     hio_t* io = hio_create_socket(loop, host, port, HIO_TYPE_TCP, HIO_CLIENT_SIDE);
     if (io == NULL) return NULL;
     hio_setcb_connect(io, connect_cb);
-    hio_connect(io);
+    if (hio_connect(io) != 0) return NULL;
     return io;
 }
 
@@ -945,7 +945,7 @@ hio_t* hloop_create_ssl_server (hloop_t* loop, const char* host, int port, hacce
     hio_t* io = hio_create_socket(loop, host, port, HIO_TYPE_SSL, HIO_SERVER_SIDE);
     if (io == NULL) return NULL;
     hio_setcb_accept(io, accept_cb);
-    hio_accept(io);
+    if (hio_accept(io) != 0) return NULL;
     return io;
 }
 
@@ -953,7 +953,7 @@ hio_t* hloop_create_ssl_client (hloop_t* loop, const char* host, int port, hconn
     hio_t* io = hio_create_socket(loop, host, port, HIO_TYPE_SSL, HIO_CLIENT_SIDE);
     if (io == NULL) return NULL;
     hio_setcb_connect(io, connect_cb);
-    hio_connect(io);
+    if (hio_connect(io) != 0) return NULL;
     return io;
 }
 

+ 1 - 2
event/nio.c

@@ -388,8 +388,7 @@ static void hio_handle_events(hio_t* io) {
 
 int hio_accept(hio_t* io) {
     io->accept = 1;
-    hio_add(io, hio_handle_events, HV_READ);
-    return 0;
+    return hio_add(io, hio_handle_events, HV_READ);
 }
 
 int hio_connect(hio_t* io) {