ithewei преди 3 години
родител
ревизия
196666f5d8
променени са 2 файла, в които са добавени 8 реда и са изтрити 9 реда
  1. 3 6
      event/kcp/hkcp.c
  2. 5 3
      event/nio.c

+ 3 - 6
event/kcp/hkcp.c

@@ -80,12 +80,9 @@ int hio_write_kcp(hio_t* io, const void* buf, size_t len) {
     kcp_t* kcp = hio_get_kcp(io, conv);
     int nsend = ikcp_send(kcp->ikcp, (const char*)buf, len);
     // printf("ikcp_send len=%d nsend=%d\n", (int)len, nsend);
-    if (nsend < 0) {
-        hio_close(io);
-    } else {
-        ikcp_update(kcp->ikcp, (IUINT32)io->loop->cur_hrtime / 1000);
-    }
-    return nsend;
+    if (nsend < 0) return nsend;
+    ikcp_update(kcp->ikcp, (IUINT32)io->loop->cur_hrtime / 1000);
+    return len;
 }
 
 int hio_read_kcp (hio_t* io, void* buf, int readbytes) {

+ 5 - 3
event/nio.c

@@ -434,13 +434,15 @@ int hio_write (hio_t* io, const void* buf, size_t len) {
         hloge("hio_write called but fd[%d] already closed!", io->fd);
         return -1;
     }
+    int nwrite = 0, err = 0;
+    hrecursive_mutex_lock(&io->write_mutex);
 #if WITH_KCP
     if (io->io_type == HIO_TYPE_KCP) {
-        return hio_write_kcp(io, buf, len);
+        nwrite = hio_write_kcp(io, buf, len);
+        if (nwrite < 0) goto write_error;
+        goto write_done;
     }
 #endif
-    int nwrite = 0, err = 0;
-    hrecursive_mutex_lock(&io->write_mutex);
     if (write_queue_empty(&io->write_queue)) {
 try_write:
         nwrite = __nio_write(io, buf, len);