Skip to content

Commit f1d5a27

Browse files
committed
support 0-length UDP packet for #604 #541
1 parent 4697294 commit f1d5a27

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

event/nio.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,14 @@ static void nio_read(hio_t* io) {
323323
// goto read_done;
324324
return;
325325
} else if (err == EMSGSIZE) {
326-
// ignore
327-
return;
326+
nread = len;
328327
} else {
329328
// perror("read");
330329
io->error = err;
331330
goto read_error;
332331
}
333332
}
334-
if (nread == 0) {
333+
if (nread == 0 && (io->io_type & HIO_TYPE_SOCK_STREAM)) {
335334
goto disconnect;
336335
}
337336
if (nread < len) {
@@ -385,7 +384,7 @@ static void nio_write(hio_t* io) {
385384
goto write_error;
386385
}
387386
}
388-
if (nwrite == 0) {
387+
if (nwrite == 0 && (io->io_type & HIO_TYPE_SOCK_STREAM)) {
389388
goto disconnect;
390389
}
391390
pbuf->offset += nwrite;
@@ -516,12 +515,12 @@ int hio_write (hio_t* io, const void* buf, size_t len) {
516515
goto write_error;
517516
}
518517
}
519-
if (nwrite == 0) {
520-
goto disconnect;
521-
}
522518
if (nwrite == len) {
523519
goto write_done;
524520
}
521+
if (nwrite == 0 && (io->io_type & HIO_TYPE_SOCK_STREAM)) {
522+
goto disconnect;
523+
}
525524
enqueue:
526525
hio_add(io, hio_handle_events, HV_WRITE);
527526
}

0 commit comments

Comments
 (0)