0
votes

I have a serial port ttyUSB0, and open it with NONBLOCK.

fd = open(args_info.dev_arg, O_RDWR | O_NONBLOCK);

use read will immediate return, everything is ok. But when use libev

ev_io_init(&serial->recv_ctx->io, serial_recv_cb, fd, EV_READ);

serial_recv_cb will block until 100bytes. if data length less than 100bytes, serial_recv_cb will never be called.

[root@jane client]# ./tcptrans --dev /dev/ttyUSB0 -d 7 --nic wlp2s0
serial.c +163 serial_recv_cb(): DEBUG: fd: 5, size: 100
serial.c +163 serial_recv_cb(): DEBUG: fd: 5, size: 100

I think serial_recv_cb will be called immediate. Why libev will block ?

1
And your question is....? - Mathieu
Why libev do not call serial_recv_cb immediate? - jianxi sun
It shouldn't do any callbacks until you call ev_run. - stark
What termios settings do you set for the serial port? - Ian Abbott

1 Answers

0
votes

termios have VMIN and VTIME.My VMIN set 100 and VTIME is 0. so will wait until 100bytes.