tangxin-blog

说明:在调用该函数前要先调用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);
}

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-09-24
  • 2022-12-23
  • 2022-02-12
  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2021-12-03
  • 2021-12-03
  • 2021-05-02
相关资源
相似解决方案