recvfrom阻塞设置超时时间

    技术2022-07-12  75

    struct timeval tv; int ret; tv.tv_sec = 10; tv.tv_usec = 0; if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { printf(“socket option SO_RCVTIMEO not support\n”); return; } if ((ret = recvfrom(s, buf, sizeof buf, 0, NULL, NULL)) < 0) { if (ret == EWOULDBLOCK || ret == EAGAIN) printf(“recvfrom timeout\n”); else printf(“recvfrom err:%d\n”, ret); }

    Processed: 0.016, SQL: 9