简体   繁体   中英

stop recvfrom() after certain time

我想等待一个恒定的时间(例如3秒),以便recvfrom()接收一些数据,并且如果程序什么都没收到(在这3秒钟之内),我想退出程序怎么办?

Call setsockopt() with the SO_RCVTIMEO option to set a read timeout on the socket. If the timeout fires, recvfrom() will return -1 with errno == EAGAIN/EWOULDBLOCK .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM