1. struct timeval tv;
   2. int ret;
   3. tv.tv_sec = 10;
   4. tv.tv_usec = 0;
   5. if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))<0){
   6. printf("socket option  SO_RCVTIMEO not support\n");
   7. return;
   8. }
   9. if (( ret = recvfrom(s, buf, sizeof buf, 0, NULL,NULL)) < 0)
  10. {
  11.     if(ret == EWOULDBLOCK || ret== EAGAIN )
  12. printf("recvfrom timeout\n");
  13. else
  14. printf("recvfrom err:%d\n",ret);
  15. }

  

相关文章:

  • 2021-12-24
  • 2021-04-22
  • 2021-10-20
  • 2021-08-05
  • 2021-10-02
  • 2021-11-30
  • 2021-08-19
  • 2021-11-17
猜你喜欢
  • 2022-12-23
  • 2021-06-18
  • 2021-06-04
  • 2021-09-24
  • 2022-12-23
  • 2021-05-31
  • 2022-01-03
相关资源
相似解决方案