说明:在调用该函数前要先调用WSAStartup初始化Winsock
void uSleep(uint32_t usec) { struct timeval timeout; fd_set fds; FD_ZERO(&fds); int32_t fd = socket(AF_INET, SOCK_DGRAM, 0); FD_SET(fd, &fds); timeout.tv_sec = usec / 1000000; timeout.tv_usec = usec % 1000000; int ret = select(0, NULL, NULL, &fds, &timeout); if (0 > ret) { perror("select"); } closesocket(fd); }
时间: 2024-10-13 20:55:02